newbie question: Can D do this?
kai at unixlords.com
Mon Dec 19 10:50:33 PST 2011
On 12/19/2011 09:17 AM, clk wrote:
> I'm new to this mailing list. I'm trying to learn D to eventually use it
> in production code.
> I'm a little bit intimidated by the fact that the topics in the d-learn
> list look rather advanced to a newbie like me.
> I have 3 fairly simple questions:
> assigment (multiple assigment in python):
> [a, b] = [b, a];
I would love multiple assignment like this, but it's tricky. But your
usage isn't really multiple assignment as much as it is a swap. What I'd
love is something like this:
[a, b, c] = [get_a(), get_b(), get_c()];
[a, b, c] = [to!(int)(argv), some_other_value, argv);
> 2) D doesn't seem to support the list comprehension syntax available in
> [f(x) for x in list if condition]
No, D's syntax is very C-ish. I don't expect syntax like this to ever
show up (though what you are doing is possible with things like
> 3) D's slice operator apparently doesn't allow the use of a stride other
> than unity as is allowed with fortran and matlab. Is there a way to
> implement this feature so that
> [1, 2, 3, 4, 5][0..$:2] would refer to [1, 3, 5], etc..., where 2 is the
> non unit stride. Or is the find function from std.algorithm the only
> option to achieve the same behavior.
Ya, std.range, like Ali said.
> I find the 3 features above extremely convenient in every day coding.
More information about the Digitalmars-d-learn