To begin in D coming from Python

Mike vertex at gmx.at
Mon Jul 21 06:02:17 PDT 2008


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.

> 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.

> 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

?

> Is there also any construct similar to dictionaries?

Dictionaries are called "Associative arrays" in D.

int[char[]] dict;
dict["hello"] = 5;

> Are there D libraries to access PostgreSQL database or do I have to use
> C's?

Don't know, but have a look at dsource.org, there are lots of  
bindings/libraries up.

-Mike

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list