Re: associative arrays
Am 09.01.2012 22:08, schrieb Manfred Nowak: dennis luehring wrote: why is there an exception/error neeeded if missing? Exceptions or errors are not _needed_. Their existence stems from the modell under which the user of the operation _has_ to think about the operation, especially whether it is a:only the outcome of the operation or b:the amount of work to get to this outcome and maybe c:at runtime has to be known, whether the object exists. Jesse Phillips wrote: I have a lot of if(exists) remove() in my code As one can see, Jesse does not know, whether the object exists and has to ask, before he in fact removes the object, i.e. doubled access to the file, which may cause a slowdown. so your FileDelete would not return an FileDoesNotExists-Error? it isn't always clear what is "ok" to happen - there are million types of remove-like-semantic, an Jesse's scenario is one type of usage, which other type of remove allows silently non-remove-removes? STL? Python, etc. (how do others handle such cases) would it not help to better understand big code if the remove would be renamed to remove_existing or to add something like this?
Re: How do you overload new and delete for a class?
Hi Alex, Thanks for the answer. As for the allocation, you mention malloc: is that malloc from the C runtime library? You also imply alternatives to this allocator; what would these be? As for deletion, does on then invoke delete on the malloc'ed data pointer? Pointing me to some example would be greatly appreciated. Thanks. - Adrian.
Re: Learning With D
On Monday, 9 January 2012 at 13:41:08 UTC, hope wrote: http://www.digitalmars.com/d/archives/digitalmars/D/announce/Learning_With_D_20566.html any new news about it? it is a very nice tutorial Hi, it is still on my plate, but hasn't seen a lot of progress. One major point is that I don't expect to complete it. Instead I expect at some point it will just be declared complete. This is really my first attempted at writing this kind of book, and one for public consumption, and putting this first draft out wasn't very easy. To help with this I'm trying to develop a preprocessor that will not only test my examples but add the compile/run command and the output to the document. This is of course a challenge as some programs take input and some are intended to fail. I'm hoping to get a little further when std.process is updated. Also, the netbook I was using to write content on the bus hasn't been in very good shape. hmmm, I think I will make csv output my goal for this week so I don't feel so split. Thanks for the unintentional encouragement.
Re: std.csv
On Monday, 9 January 2012 at 15:05:53 UTC, Joshua Reusch wrote: Hello, I checked out the phobos git repo and found a std.csv module. Is it ready to use or should I stay to my own (but incomplete and whithout any "good" error messages) csv reading function ? Thank you Yep, no known reason it can't be used in production (shouldn't be changing before the next release). Documentation can be found for now at: http://nascent.freeshell.org/programming/D/doc/phobos/std_csv2.html
Re: Exceptions in safe D
On Tuesday, January 10, 2012 03:55:35 Jesse Phillips wrote: > Maybe I missed something, but the last I knew Safe D is not > completely implemented. I think checking that you don't call > system functions is the only piece implemented, and Phobos isn't > annotated with it. Yeah. I'm not sure how well @safe is implemented in general, but IIRC, it's not fully implemented yet - though it certainly works well enough to use in many cases. However, one of the biggest problems is essentially the same problem that we have with const, and that is that not enough stuff in druntime and Phobos uses it where it should. Case in point: Exception isn't marked with @safe, pure, or nothrow, and it probably could (and probably _should_) be marked with all three. Attribute inferrence for templates has helped a lot with the problem, but there's still plenty of non-templated stuff which needs to be fixed up to work properly with @safe, pure, and nothrow. - Jonathan M Davis
Re: Exceptions in safe D
Maybe I missed something, but the last I knew Safe D is not completely implemented. I think checking that you don't call system functions is the only piece implemented, and Phobos isn't annotated with it.
Re: Problem with interfacing C code to D
Scratch that, in X11 apparently the Display structure is an incomplete type (so sizeof won't work). This means you most probably *have* to use pass it around as an opaque pointer. It's kind of odd because you can still access some of its fields (so it's not totally opaque), but you can't do copies. So just use pointers and you'll be safe. Hell I've never really done any C programming except what's in K&R, but this seems like a logical conclusion to me..
Re: Problem with interfacing C code to D
On 01/10/12 01:02, bioinfornatics wrote: > Dear i do not understand why the first example works and the second > segfault. Thanks > > EXAMPLE 1 --- Display* display = XOpenDisplay(getenv("DISPLAY")); > char** fonts = XListFonts( display, pattern.dup.ptr, 10, &counter > EXAMPLE 2 --- > Display display = *XOpenDisplay(getenv("DISPLAY")); > char** fonts = XListFonts( &display, pattern.dup.ptr, 10, &counter Do you expect the xlib functions to work with copies of private structures? artur
Re: Problem with interfacing C code to D
Jesus christ, sorry about that my keyboard script went crazy and posted that. What I was going to say is it's likely a mismatch of the struct sizes. In the second example you are dereferencing the pointer on the D size, which does a field-by-field copy of the pointed-to struct. But D will only read the exact amount of bytes that is defined by the structure. So if you end up reading e.g 176 bytes, but the C structure is actually more than that, then the C-side (X11) will end up reading into D memory past the 176th byte, and will segfault. If you can, try seeing if you can get the size of the Display structure in C code (e.g. use printf("%d", sizeof(Display))), and then compare that to D with writeln(Display.sizeof). They must have the same size.
Re: Problem with interfacing C code to D
It's likely a module Gmail - Problem with interfacing C code to D - Mozilla Firefo; import std.algorithm; import std.array; import std.stdio; void main() { } On 1/10/12, bioinfornatics wrote: > Le mardi 10 janvier 2012 à 01:26 +0100, Trass3r a écrit : >> What's the definition of Display? > > This one: > _ > struct _XDisplay{ > XExtData* ext_data; /* hook for > extension to hang data */ > _XPrivate* private1; > int fd; /* Network socket. > */ > int private2; > int proto_major_version;/* major version of > server's X protocol */ > int proto_minor_version;/* minor version of > servers X protocol */ > char* vendor; /* vendor of the > server hardware */ > XID private3; > XID private4; > XID private5; > int private6; > XID function(_XDisplay*)resource_alloc; /* allocator > function */ > int char_order; /* screen char > order, LSBFirst, MSBFirst */ > int bitmap_unit;/* padding and data > requirements */ > int bitmap_pad; /* padding > requirements on bitmaps */ > int bitmap_bit_order; /* LeastSignificant > or MostSignificant */ > int nformats; /* number of pixmap > formats in list */ > ScreenFormat* pixmap_format;/* pixmap format > list */ > int private8; > int release;/* release of the > server */ > _XPrivate* private9, private10; > int qlen; /* Length of input > event queue */ > c_ulong last_request_read; /* seq number of > last event read */ > c_ulong request; /* sequence number > of last request. */ > XPointer private11; > XPointer private12; > XPointer private13; > XPointer private14; > uint max_request_size; /* maximum number 32 > bit words in request*/ > _XrmHashBucketRec* db; > int function( _XDisplay* )private15; > char* display_name; /* "host:display" > string used on this connect*/ > int default_screen; /* default screen > for operations */ > int nscreens; /* number of screens > on this server*/ > Screen* screens;/* pointer to list > of screens */ > c_ulong motion_buffer; /* size of motion > buffer */ > c_ulong private16; > int min_keycode;/* minimum defined > keycode */ > int max_keycode;/* maximum defined > keycode */ > XPointer private17; > XPointer private18; > int private19; > char* xdefaults;/* contents of > defaults from server */ > /* there is more to this structure, but it is private to Xlib */ > } > alias _XDisplay Display; > >
Re: Problem with interfacing C code to D
Le mardi 10 janvier 2012 à 01:26 +0100, Trass3r a écrit : > What's the definition of Display? This one: _ struct _XDisplay{ XExtData* ext_data; /* hook for extension to hang data */ _XPrivate* private1; int fd; /* Network socket. */ int private2; int proto_major_version;/* major version of server's X protocol */ int proto_minor_version;/* minor version of servers X protocol */ char* vendor; /* vendor of the server hardware */ XID private3; XID private4; XID private5; int private6; XID function(_XDisplay*)resource_alloc; /* allocator function */ int char_order; /* screen char order, LSBFirst, MSBFirst */ int bitmap_unit;/* padding and data requirements */ int bitmap_pad; /* padding requirements on bitmaps */ int bitmap_bit_order; /* LeastSignificant or MostSignificant */ int nformats; /* number of pixmap formats in list */ ScreenFormat* pixmap_format;/* pixmap format list */ int private8; int release;/* release of the server */ _XPrivate* private9, private10; int qlen; /* Length of input event queue */ c_ulong last_request_read; /* seq number of last event read */ c_ulong request; /* sequence number of last request. */ XPointer private11; XPointer private12; XPointer private13; XPointer private14; uint max_request_size; /* maximum number 32 bit words in request*/ _XrmHashBucketRec* db; int function( _XDisplay* )private15; char* display_name; /* "host:display" string used on this connect*/ int default_screen; /* default screen for operations */ int nscreens; /* number of screens on this server*/ Screen* screens;/* pointer to list of screens */ c_ulong motion_buffer; /* size of motion buffer */ c_ulong private16; int min_keycode;/* minimum defined keycode */ int max_keycode;/* maximum defined keycode */ XPointer private17; XPointer private18; int private19; char* xdefaults;/* contents of defaults from server */ /* there is more to this structure, but it is private to Xlib */ } alias _XDisplay Display;
Re: Problem with interfacing C code to D
What's the definition of Display?
Problem with interfacing C code to D
Dear i do not understand why the first example works and the second segfault. Thanks EXAMPLE 1 --- // ldc2 -L=/usr/lib64/libXlib.so -L-lX11 -g -w xtest.d import std.string; import std.stdio; import std.conv; import std.c.stdlib : getenv; import std.exception : Exception; import X11.Xlib; void main( string[] args ){ Display* display = XOpenDisplay(getenv("DISPLAY")); if( display is null ) new Exception( "Could not communicate with X server" ); int counter; string pattern = "*\0"; char** fonts = XListFonts( display, pattern.dup.ptr, 10, &counter ); for(int c = 0; c < counter; c++) writeln( to!string( fonts[c] ) ); } EXAMPLE 2 --- // ldc2 -L=/usr/lib64/libXlib.so -L-lX11 -g -w xtest.d import std.string; import std.stdio; import std.conv; import std.c.stdlib : getenv; import std.exception : Exception; import X11.Xlib; void main( string[] args ){ Display display = *XOpenDisplay(getenv("DISPLAY")); if( display is null ) new Exception( "Could not communicate with X server" ); int counter; string pattern = "*\0"; char** fonts = XListFonts( &display, pattern.dup.ptr, 10, &counter ); for(int c = 0; c < counter; c++) writeln( to!string( fonts[c] ) ); }
Re: Exceptions in safe D
On Mon, 09 Jan 2012 22:33:28 +0100, Juan Campanas wrote: On Monday, 9 January 2012 at 21:14:05 UTC, Robert Clipsham wrote: Are exceptions in safe D possible? I started trying to make my code @safe (there's no reason why it can't be as far as I'm aware), but I hit the following issue: @safe class MyException : Exception { this() { super(""); } } void main() { throw new MyException(""); } $ rdmd test.d test.d(7): Error: safe function 'this' cannot call system function 'this' test.d(13): Error: constructor test.MyException.this () is not callable using argument types (string) test.d(13): Error: expected 0 arguments, not 1 for non-variadic function type @safe MyException() Is this just unimplemented, is there a workaround, or will this never work? Thanks, Why are you calling the MyException constructor with a string parameter? Yeah, that explains the error on line 13. Anyways. I think that Exception is not marked as @safe. Indeed. This seems like a bug. Please file it in bugzilla. http://d.puremagic.com/issues/enter_bug.cgi
Waiting around
Hello, I need to connect to a network location and read a file but I also need some way of waiting around until the connection is established. Currently I use the following snippet to do this: while (!std.file.exists("/Volumes/mountedDir/myfile.txt") && timeout < 30) { core.thread.Thread.sleep(10_000_000); // core.thread.Thread conflicts with std.regex.Thread, hence the full path reference timeout++; } with the recent changes to std.regex it stopped compiling due to the "Thread" conflict. Is there a more obvious way to do what I'm doing that avoids importing core.thread? Thanks, Josh
Re: Exceptions in safe D
On Monday, 9 January 2012 at 21:14:05 UTC, Robert Clipsham wrote: Are exceptions in safe D possible? I started trying to make my code @safe (there's no reason why it can't be as far as I'm aware), but I hit the following issue: @safe class MyException : Exception { this() { super(""); } } void main() { throw new MyException(""); } $ rdmd test.d test.d(7): Error: safe function 'this' cannot call system function 'this' test.d(13): Error: constructor test.MyException.this () is not callable using argument types (string) test.d(13): Error: expected 0 arguments, not 1 for non-variadic function type @safe MyException() Is this just unimplemented, is there a workaround, or will this never work? Thanks, Why are you calling the MyException constructor with a string parameter? Anyways. I think that Exception is not marked as @safe.
Exceptions in safe D
Are exceptions in safe D possible? I started trying to make my code @safe (there's no reason why it can't be as far as I'm aware), but I hit the following issue: @safe class MyException : Exception { this() { super(""); } } void main() { throw new MyException(""); } $ rdmd test.d test.d(7): Error: safe function 'this' cannot call system function 'this' test.d(13): Error: constructor test.MyException.this () is not callable using argument types (string) test.d(13): Error: expected 0 arguments, not 1 for non-variadic function type @safe MyException() Is this just unimplemented, is there a workaround, or will this never work? Thanks, -- Robert http://octarineparrot.com/
Re: associative arrays
dennis luehring wrote: > why is there an exception/error neeeded if missing? Exceptions or errors are not _needed_. Their existence stems from the modell under which the user of the operation _has_ to think about the operation, especially whether it is a:only the outcome of the operation or b:the amount of work to get to this outcome and maybe c:at runtime has to be known, whether the object exists. Jesse Phillips wrote: > I have a lot of if(exists) remove() in my code As one can see, Jesse does not know, whether the object exists and has to ask, before he in fact removes the object, i.e. doubled access to the file, which may cause a slowdown. As Jesse states the designer of the API has made up false assumptions about his knowledge, described in c:, _and_ his interests, described in b:. Jesse is interested only in the outcome of the operation, as described in a:, Therefore the likely answer to your question stated at the beginning is: the designer of the API made a mistake. -manfred
Re: How do you overload new and delete for a class?
On 09-01-2012 20:41, Adrian Mercieca wrote: Hi, Can someone please provide an example regarding overloading new and delete for a class? Thanks a lot. This is deprecated. What you should be doing is using std.conv.emplace() with whatever allocator (say, malloc()) you wish to use. - Alex
Re: associative arrays
On 1/9/12, Steven Schveighoffer wrote: > Could this be you? Ah, yes. I didn't even notice you've replied to that, sorry. Yes, I'm ok with it.
Re: associative arrays
On Mon, 09 Jan 2012 14:57:36 -0500, Andrej Mitrovic wrote: Ok, allow me to temporarily hijack again and ask: Would you mind adding opIn_r (or rather the newer opBinaryRight with "in") that forwards to contains() for the HashSet and similar hash-based classes that define contains()? It would make porting code that uses builtin hashes to your own implementation easier. Could this be you? http://www.dsource.org/projects/dcollections/ticket/18 If so, this means you are OK with the last suggestion I made? -Steve
Re: associative arrays
Ok, allow me to temporarily hijack again and ask: Would you mind adding opIn_r (or rather the newer opBinaryRight with "in") that forwards to contains() for the HashSet and similar hash-based classes that define contains()? It would make porting code that uses builtin hashes to your own implementation easier.
Re: Learning With D
On 01/09/2012 05:41 AM, hope wrote: http://www.digitalmars.com/d/archives/digitalmars/D/announce/Learning_With_D_20566.html any new news about it? it is a very nice tutorial I hope it has actually grown but we haven't heard the news yet! :) On a related note, I am continuing to translate my book from Turkish. Although I mostly translate from the beginning of the book, I occasionally translate from the later chapters: http://ddili.org/ders/d.en/index.html I am currently working on the Templates chapter. Ali
How do you overload new and delete for a class?
Hi, Can someone please provide an example regarding overloading new and delete for a class? Thanks a lot.
Re: associative arrays
On Mon, 09 Jan 2012 13:35:26 -0500, Andrej Mitrovic wrote: On 1/9/12, Steven Schveighoffer wrote: BTW, dcollections' HashMap, HashSet, and HashMultiset do guarantee that adding elements does not invalidated cursors (dcollections' safe version of pointers) as long as you use the default Hash implementation. However, I just noticed this is not stated anywhere in the docs (will fix). Funny, I was looking at the docs a few days ago and it said "Adding an element can invalidate cursors depending on the implementation.", so I just assumed it did invalidate the cursors. Yeah, I could have sworn I stated somewhere that the current implementation doesn't invalidate cursors, but apparently it's not stated. I think the docs need a lot of TLC before the first release. Some day when I have time... To clarify what I plan to do, the add doc will say something like "adding an element can invalidate cursors depending on the implementation, however the default implementation guarantees not to invalidate them." I don't want to specifically disallow implementations which do invalidate (dcollections' implementations are pluggable so anyone can replace the internals). I do think those are dcollections v1 docs though. Anyway glad to hear from you about this. The D2 docs are somewhat leftover from D1 version. However, I do remember when implementing the hash code that it purposely does not invalidate cursors on a rehash. Ranges can be invalidated, however. Given the implementation, it's actually faster *not* to invalidate them when rehashing because I just relink all the link-list nodes instead of reallocating them. -Steve
Re: associative arrays
On 1/9/12, Steven Schveighoffer wrote: > BTW, dcollections' HashMap, HashSet, and HashMultiset do guarantee that > adding elements does not invalidated cursors (dcollections' safe version > of pointers) as long as you use the default Hash implementation. However, > I just noticed this is not stated anywhere in the docs (will fix). Funny, I was looking at the docs a few days ago and it said "Adding an element can invalidate cursors depending on the implementation.", so I just assumed it did invalidate the cursors. I do think those are dcollections v1 docs though. Anyway glad to hear from you about this.
Re: std.csv
Am 09.01.2012 16:19, schrieb simendsjo: On 09.01.2012 16:05, Joshua Reusch wrote: Hello, I checked out the phobos git repo and found a std.csv module. Is it ready to use or should I stay to my own (but incomplete and whithout any "good" error messages) csv reading function ? Thank you It should be ready for production work, but if it's only in git you might want to wait for 2.058. Great ! I tried it and it works fine ! And makes my CSV - reading code 3 times shorter ... Every (new) module in phobos has gone through a review proccess similar to boost: http://www.boost.org/community/reviews.html Here's a list of upcoming modules scheduled for review/inclusion in phobos: http://prowiki.org/wiki4d/wiki.cgi?ReviewQueue
Re: How to get runtime args from shared static this module ctor?
Sweeet, thanks Joshua! On 1/9/12, Joshua Reusch wrote: > Am 09.01.2012 18:00, schrieb Andrej Mitrovic: >> I need to get the name of the executable but without using a string[] >> from main. I'm wrapping a 3rd party library that requires me to >> initialize it by calling an extern function to pass the executable >> name. >> >> However I don't want to force the user to pass args from main when >> constructing a class, so I was wondering if there's a cross-platform >> way of getting the arguments which I could use in a shared static this >> module constructor inside of my wrapper library? >> >> Druntime probably has the arguments stored somewhere upon app entry >> (before calling my main function). Is there a way to extract them? >> Otherwise I'll have to use OS-specific APIs, but I'd rather avoid >> those. Worst-case-scenario I'll just have to make passing args[] from >> main a requirement of the library. It's not a big issue, but slightly >> annoying. > > They are stored in Runtime.args (you must import core.runtime). > > Joshua >
Re: associative arrays
On Monday, January 09, 2012 09:25:14 Steven Schveighoffer wrote: > Actually, not invalid for the current implementation. I don't know if > it's stated whether an AA specifically requires that elements do not > re-associate on a rehash. Well, like I said, it depends on the current implementation. There are hash table implementations where rehashing would invalidate the pointer returned by in, and I don't believe that the spec specificies that D's AA guarantees that rehashing doesn't do that. So in the future, it _could_ be changed to an implementation which invalidates the pointers on rehash. As such, it doesn't really matter what the current implementation does. Relying on the current behavior is unsafe if it's not guaranteed by the spec. Now, if we want to change the spec to make such guarantees, that's fine, but I don't believe it makes them right now. Good to know what the current implementation is doing though. - Jonathan m Davis
Re: How to get runtime args from shared static this module ctor?
Am 09.01.2012 18:00, schrieb Andrej Mitrovic: I need to get the name of the executable but without using a string[] from main. I'm wrapping a 3rd party library that requires me to initialize it by calling an extern function to pass the executable name. However I don't want to force the user to pass args from main when constructing a class, so I was wondering if there's a cross-platform way of getting the arguments which I could use in a shared static this module constructor inside of my wrapper library? Druntime probably has the arguments stored somewhere upon app entry (before calling my main function). Is there a way to extract them? Otherwise I'll have to use OS-specific APIs, but I'd rather avoid those. Worst-case-scenario I'll just have to make passing args[] from main a requirement of the library. It's not a big issue, but slightly annoying. They are stored in Runtime.args (you must import core.runtime). Joshua
How to get runtime args from shared static this module ctor?
I need to get the name of the executable but without using a string[] from main. I'm wrapping a 3rd party library that requires me to initialize it by calling an extern function to pass the executable name. However I don't want to force the user to pass args from main when constructing a class, so I was wondering if there's a cross-platform way of getting the arguments which I could use in a shared static this module constructor inside of my wrapper library? Druntime probably has the arguments stored somewhere upon app entry (before calling my main function). Is there a way to extract them? Otherwise I'll have to use OS-specific APIs, but I'd rather avoid those. Worst-case-scenario I'll just have to make passing args[] from main a requirement of the library. It's not a big issue, but slightly annoying.
Re: std.csv
On 09.01.2012 16:05, Joshua Reusch wrote: Hello, I checked out the phobos git repo and found a std.csv module. Is it ready to use or should I stay to my own (but incomplete and whithout any "good" error messages) csv reading function ? Thank you It should be ready for production work, but if it's only in git you might want to wait for 2.058. Every (new) module in phobos has gone through a review proccess similar to boost: http://www.boost.org/community/reviews.html Here's a list of upcoming modules scheduled for review/inclusion in phobos: http://prowiki.org/wiki4d/wiki.cgi?ReviewQueue
Re: Ref local variables?
On Mon, 09 Jan 2012 09:27:06 -0500, bearophile wrote: Steven Schveighoffer: With new => syntax (in git head), this would probably be: @property ref tile => map[y*w+x]; That's not currently supported: http://d.puremagic.com/issues/show_bug.cgi?id=7176 The given function is not a method, but it is an inner-class function. But you are right, it's a named function not a lambda. I'm not too concerned about whether this version works or not, the other version is reasonably short. I wonder if this would work, but it wouldn't be inlined like my original example: auto tile = @property ref () => map[y*w+x]; -Steve
std.csv
Hello, I checked out the phobos git repo and found a std.csv module. Is it ready to use or should I stay to my own (but incomplete and whithout any "good" error messages) csv reading function ? Thank you
Re: Ref local variables?
Steven Schveighoffer: > With new => syntax (in git head), this would probably be: > > @property ref tile => map[y*w+x]; That's not currently supported: http://d.puremagic.com/issues/show_bug.cgi?id=7176 Bye, bearophile
Re: associative arrays
On Sun, 08 Jan 2012 08:40:27 -0500, Jonathan M Davis wrote: On Sunday, January 08, 2012 14:24:32 simendsjo wrote: Thanks for your clarifications. Does this mean even this is undefined? aa["a"] = new C(); auto c = "a" in aa; aa["b"] = new C(); // Using c here is undefined as an element was added to aa Yes. Depending on the current implementation of AAs and the state of aa when "b" is added to it, c could still point to exactly what it did before, or aa could have been rehashed, which could move any or all of its elements around, in which case who knows what c points to. Actually, not invalid for the current implementation. I don't know if it's stated whether an AA specifically requires that elements do not re-associate on a rehash. There are certain hash implementations (such as ones that involve a single array), which would invalidate pointers on a rehash. So there is the potential (if it's not a stated requirement to the contrary in the spec) that some future AA implementation would invalidated references. However, I'd say it's unlikely this would happen. BTW, dcollections' HashMap, HashSet, and HashMultiset do guarantee that adding elements does not invalidated cursors (dcollections' safe version of pointers) as long as you use the default Hash implementation. However, I just noticed this is not stated anywhere in the docs (will fix). -Steve
Re: Ref local variables?
On Sun, 08 Jan 2012 12:54:13 -0500, Ben Davis wrote: Hi, Is there a reason 'ref' is disallowed for local variables? I want to write something like: MapTile[] map; // It's a struct ref MapTile tile=map[y*w+x]; tile.id=something; tile.isWall=true; My actual case is more complicated, so inlining the expression everywhere would be messy. I can't use 'with' because I sometimes pass 'tile' to a function (which also takes it as a ref). I don't want to make it a class since the array is quite big and that would be a lot of extra overhead. For now I'm using pointers, but this is forcing me to insert & or * operators sometimes, and it also reduces the temptation to use 'ref' in the places where it IS allowed, since it's inconsistent. I hope it's not a stupid question - it's my first one - but I couldn't find an answer anywhere. I like most of what I've seen of D so far, and I'm very glad to be able to leave C and C++ (mostly) behind! My first inclination is to use pointers. D doesn't have -> operator, so pointers are seamless for your small example: auto tile = &map[y*w+x]; tile.id = something; tile.isWall = true; When you need to pass it to a ref function, or if you do any operators on it, you would need to use *. Another horribly inefficient option (if you don't use -inline) is this: @property ref tile() { return map[y*w+x]; } With new => syntax (in git head), this would probably be: @property ref tile => map[y*w+x]; -Steve
Learning With D
http://www.digitalmars.com/d/archives/digitalmars/D/announce/Learning_With_D_20566.html any new news about it? it is a very nice tutorial
Re: An issue with lazy delegates
On 05/01/2012 05:26, Andrej Mitrovic wrote: The first call doesn't do anything because the delegate is wrapped inside of another delegate. I want this template to be versatile enough to be used by both lazy expressions and delegate literals, but I don't know how. If you have a delegate you want to use as a lazy expression, you can make the lazy argument a call to it onFailThrow!Exception({ to!int(x); }()); Of course, Peter's solution enables you to omit the () and just pass the delegate in, but it does mean that you can't lazily evaluate an expression to a delegate, unless you wrap it in a delegate literal. Stewart.
Re: associative arrays
assert(key in aa); aa.remove(key); So, as far as I can tell, the current situation is more efficient, and it doesn't cost you any expressiveness. You can still have an exception thrown when remove fails if you use enforce before the call if you want an exception thrown when the element isn't there. but then it should be called optional_remove - because it "mabye" removes its like file_delete, DeleteFile (and all the others) on non existing files - why is there an exception/error neeeded if missing? the "maybe"-situation is not that often used in good code - because you can't find your errors if many routines would work like remove
Re: associative arrays
Looks like this is fixed for 2.058. https://github.com/D-Programming-Language/dmd/commit/3e23b0f5834acb32eaee20d88c30ead7e03bb2f4 On 08/01/2012 3:43 AM, Jonathan M Davis wrote: On Sunday, January 08, 2012 03:24:22 Kapps wrote: Ah, found the bug / pull request. https://github.com/D-Programming-Language/dmd/pull/597 http://d.puremagic.com/issues/show_bug.cgi?id=4523 Ah, TDPL says that it returns bool. Well, then it definitely needs to be changed, and it's good to see that that there's a pull request for it. So, it should be fixed in the next release. In fact, the number of TDPL-related bugs fixed for the next release should be quite high, which is great. - Jonathan M Davis