D as a prototyping language (for C/C++ projects)

Jacob Carlborg doob at me.com
Wed Feb 27 12:33:52 PST 2013


On 2013-02-27 21:12, H. S. Teoh wrote:

> Oh I get it now. So basically it's a wrapper around functions to make
> UFCS chaining possible?

Yes, something like that.

> What would a templated version add to this functionality?

Allow structs to be passed as well. Although they need to be passed by 
ref. But then you would be able to do this:

auto s = Struct();
s.tap!((ref e) { e = Struct(); });

Which should be avoidable if possible.

> I guess I'm skeptical about the value of using tap in this context,
> since you could just call the function on the object, then set its
> values, then return it. So this is just syntactic sugar.
>
> But I guess I can see some use cases where you're chaining a bunch of
> stuff inside nested function calls, then tap might become convenient:
>
> 	return map!myFunc(zip(r1, [
> 		new X().tap!myFunc2(),
> 		new X().tap!myFunc2()
> 	]));
>
> Which can be unpacked into linear code, but you would would need a bunch
> of temporary variables to hold the intermediate results.

This is about the little things that makes it convenient to write code. 
I'm not saying that you cannot do anything without these things. But the 
question was, what can we do to make D more usable as a scripting language.

> I disagree with this point. Writing !isBlank is just as easy as writing
> isPresent (in fact, a few characters less). I don't see how this helps
> with writing scripts faster.

No, I was more thinking of "The best APIs are minimal ones". If you only 
have the minimal building blocks you would need to create wrappers and 
similar to create convenient functions.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list