To begin in D coming from Python

Luis P. Mendes luislupeXXXX at gmailXXXX.com
Mon Jul 21 08:47:53 PDT 2008


Hi Mike,


Mon, 21 Jul 2008 15:02:17 +0200, Mike wrote:

> On Mon, 21 Jul 2008 13:51:23 +0200, Luis P. Mendes
> <luislupeXXXX at gmailxxxx.com> wrote:
> 
>> To begin with, is version 2 just a developer version or should I start
>> by using it?
> 
> D2 is a moving target, so stick with D1 for the moment.
> 
>> In Python, lists can have variables, functions, text and others as
>> elements.  As far as I can recall from reading a C book, arrays in C
>> don't have this possibility.  What about it in D?
> 
> You can put all kinds of stuff into arrays, including delegates and
> classes. D's arrays are a completely different thing than C's arrays,
> just have a look at the documentation.
Ok.

> 
>> And regarding list comprehensions like li = [elem*2 for elem in li]? 
>> is there something close in D?
> 
> Depends on how you define close. There is foreach and with some template
> trickery you can get similar syntax:
> 
> // Please note that this works only if you define the template "each"
> yourself!
> [1, 2, 3, 4, 5].each((int value) { Stdout("Value: {0}", value).newline;
> });
> 
> But I would recommend you concentrate on the basic stuff first.
By something close I meant some kind of (high-level) construct that D 
would have to offer.  As in this example, as in other I wrote I didn't 
want to mimic Python. 


> 
>> For example, how could I do something like: valores = []
>> for c in lista_campos: valores.append(getattr(self,c)), so that I can
>> have all the
> 
> ?
Sorry for the paste error. 

I wanted to know if I can load values for attributes in a concise manner.

For example, right now I'm working on a project that reads and writes 
circa 40 values for each instance of an object and in Python I'm able to 
load the values on a for loop as mentioned above.

Thank you for your time and comments.

Luis



More information about the Digitalmars-d mailing list