Re: Signed word lengths and indexes

2010-06-18 Thread Adam Ruppe
On 6/18/10, bearophile wrote: > As I have said, you have to use operator overloading of the struct and some > near-ugly code that uses the offsetof. I don't like this a lot. D need be no uglier than C. Here's my implementation: /* @very_unsafe */ struct TailArray(T) { T opIndex(size_t i

Re: Signed word lengths and indexes

2010-06-18 Thread Adam Ruppe
On 6/18/10, bearophile wrote: >> static void destroy(MyString* s) { >> free(s); >> } > > Why destroy instead of ~this() ? It allocates and deallocates the memory rather than initialize and uninitialize the object. I don't think a destructor can free the mem of its own objec

Re: Signed word lengths and indexes

2010-06-18 Thread Adam Ruppe
On 6/18/10, bearophile wrote: > By the way, this program shows your code is not a replacement of the > operator overloading of the variable length struct itself I was talking > about, because D structs can't have length zero (plus 3 bytes of padding, > here): Huh, weird. Doesn't make too much of

Re: Errors in TDPL

2010-06-21 Thread Adam Ruppe
On 6/21/10, bearophile wrote: > How do you write this? > foreach_reverse (i; 0 .. 10) foreach(i; retro(iota(0, 10))) { } ?

Re: Is there ANY chance we can fix the bitwise operator precedence rules?

2010-06-21 Thread Adam Ruppe
What's the point of a switch without implicit fallthrough? If you take that away, it offers nothing that if/elseif doesn't. (Aside from not retyping the switch(stuff here), which you can bring into a function anyway, so whoop-de-doo. And I guess some performance boosts in rearranging the cases, but

Re: Is there ANY chance we can fix the bitwise operator precedence rules?

2010-06-21 Thread Adam Ruppe
On 6/21/10, Andrei Alexandrescu wrote: > Then why are people using switch and next to nobody uses fall through > (provably including Walter, who thinks is using fall through "all the > time")? Do you have some stats from the phobos and dmd source? I ran a crude text pattern program, and it said a

Re: Is there ANY chance we can fix the bitwise operator precedence rules?

2010-06-21 Thread Adam Ruppe
On 6/22/10, Don wrote: > Did you consider situations where the last thing before the case is > actually a 'goto' ? Walter does that a lot. Yeah, me too. I counted them the same as break (and continue, return, and throw). Here's my source. I know it has some false negatives and some false positiv

Re: Is there ANY chance we can fix the bitwise operator precedence rules?

2010-06-22 Thread Adam Ruppe
What you guys are saying makes enough sense. switch will always be a series of labels and jumps in my mind, but I can deal with this. One note that I think is the main reason people find fallthrough confusing: they hit tab once too many times. switch(a) { case 10: case 20: // obvious fall

Automatic library download plan

2010-06-25 Thread Adam Ruppe
I was thinking this morning about a way to have a simple way for D library distribution. Let me run it by you guys, and we'll discuss if it is a good plan. The short version is it takes a package -> URL mapping file and downloads on http, based on the .d file being in an expected folder. The plan

Re: Automatic library download plan

2010-06-25 Thread Adam Ruppe
On 6/25/10, Nick Sabalausky wrote: > - This should probably use DMDZ (or is it ZDMD?), or be built on-top of it. I remember reading about it in the newsgroup, but is there a link to a website or something? I don't remember any details. > - It should probably be possible for the mapping file to b

Re: Status of std.xml (D2/Phobos)

2010-06-27 Thread Adam Ruppe
I'm not terribly interested in it because I already wrote my own replacement: http://arsdnet.net/dcode/dom.d Mine is biased toward HTML, doing what I personally find useful, or mimicing what javascript in the browser would do instead of following the standard, but if there's anything in there that

Re: Status of std.xml (D2/Phobos)

2010-06-27 Thread Adam Ruppe
On 6/27/10, Justin Johansson wrote: > btw. I feel it fair to add conjecture that a DOM implementation > is pretty basic stuff and that a complete XML ecosystem it much > larger than just this (i.e. an in-memory DOM). Yes, it is very simple, but so is all the XML I've ever actually encountered. I'

Re: C# 4.0 dynamic vs std.variant

2010-06-29 Thread Adam Ruppe
If you want to play with dmdscript, I have a port to D2 here: http://arsdnet.net/dcode/dmdscript_d2.zip You have to compile it all at once: dmd *.d, instead of incremental, or it won't link for some reason. There's some hacks in that code, since I did the port using a dmd release that had a broke

Re: Network I/O and streaming in D2

2010-06-29 Thread Adam Ruppe
My network thing is very simple: it opens a socket, then wraps it up in a File struct, via FILE*. Then, you can treat it the same way. Simple code, and I've been meaning to commit it to phobos for linux at least, but stuff keeps coming up and I haven't gotten around to it yet. Now, there's some c

Re: Network I/O and streaming in D2

2010-06-30 Thread Adam Ruppe
On 6/30/10, Sean Kelly wrote: > I've been thinking about this and I think this is probably what the majority > of apps want anyway. It isn't scalable, but server apps are a whole 'nother > ball of wax. Blocking calls are convenient for simple apps, since you just call the read and write function

Re: Class field inheritance

2010-06-30 Thread Adam Ruppe
Easy one: xa is null. This one used to bite me all the time too, since I was used to C++ where XA xa; works on its own. But in D, classes are always created by reference (think of them all as pointers), so you have to new them before using them. Just add an xa = new XA; to your constructor and it

Re: Can someone explain why this is not an error?

2010-07-01 Thread Adam Ruppe
On 7/1/10, Adam Ruppe wrote: > (and auto, which is inferred from the missing type). Nitpicking myself, but I shouldn't have said that; auto is just the default storage class, and it is the missing type that means infer it, not the auto keyword. I think you know what I mean though.

Re: Can someone explain why this is not an error?

2010-07-01 Thread Adam Ruppe
I don't think this is really a special case: they are all sharing the same keywords. immutable a = 1, b = "a"; // both a and b are immutable string a = "a", b = "b"; // both a and b are strings immutable int a = 1, b = 2; // both a and b are immutable ints I'd say the bug is that the documentatio

Re: mangle

2010-07-01 Thread Adam Ruppe
http://dpldocs.info/std.demangle

Re: Nullable!T

2010-07-06 Thread Adam Ruppe
On 7/6/10, bearophile wrote: > 1) Nullable!(SomeClass) is forbidden in C#. I figure a Nullable struct would just alias the original type if T t; t = null; already compiles. So a nullable pointer, class, or Nullable is just a no-op. This would cover your cases 1 and 2 with a simple rule. > Option

Re: Nullable!T

2010-07-06 Thread Adam Ruppe
I said: > Blargh, what I'd want is > if(x is null) Then went off and implemented something where that doesn't actually compile, and forgot to mention it. This is the reason I used a T* in the nullable struct; I was hoping to take T* is null and make it work for the struct as a whole, but it didn'

Re: Nullable!T

2010-07-06 Thread Adam Ruppe
On 7/6/10, bearophile wrote: > I don't think that's a good idea, you lose the standard API of Nullable, so > it's worse than useless. Make that standard API free functions, like std.array does. Then, it would work with all nullable items, and not just Nullable ones. Uniformity is good. >(and don

Re: Nullable!T

2010-07-06 Thread Adam Ruppe
On 7/6/10, Nick Sabalausky wrote: > But ducks are bad. Oh, I don't know. You don't want to over do it, but to me a nullable thing is just anything where item = null; compiles; a good fit for a duck. > How about an INullable that's implemented by Nullable and > implicitly implemented by classes?

Re: Nullable!T

2010-07-07 Thread Adam Ruppe
On 7/7/10, Jacob Carlborg wrote: > Uniform function call syntax isn't implemented (issue 3382), if you're > referring to that. Yeah, that would be the ideal way to do it, but just having the free functions there are good enough to accomplish the goal.

Re: Nullable!T

2010-07-07 Thread Adam Ruppe
On 7/7/10, Clemens wrote: > Strange... I could have sworn that when I recently tried D2, arrays > supported range methods (popFront etc), and that those were implemented in > std.array. Am I mistaken, or how does that work? Arrays work for it, and have for quite a while, but nothing else does yet

Re: Nullable!T

2010-07-07 Thread Adam Ruppe
On 7/7/10, Clemens wrote: > That brings up an interesting corner case though: once uniform call syntax > is supported for pointers and references, and you have a null reference x, > an actual method x.foo() would give you a segmentation fault, while a > pseudomethod that is implemented as a free f

Re: Allocating structs with new?

2010-07-10 Thread Adam Ruppe
On 7/10/10, Jonathan M Davis wrote: > I think that I was > thinking that you had to use malloc to put primitive types no the heap > though. D is very similar to C++ here, with the big exception that classes *must* use new, whereas new is just an option for everything else. int* a = new int; // v

Re: Manual memory management in D2

2010-07-13 Thread Adam Ruppe
On 7/13/10, Nick Sabalausky wrote: > I think I'm missing something. Instead of regressing back to malloc & co., > why not just have the custom allocators? For me, what I don't like is they are in the wrong place. If you use a malloc/free custom allocator, that fact is hidden in the class. There's

Linking problem with custom associative arrays

2010-07-18 Thread Adam Ruppe
I'm working on a rapid webdev thing for D, using my existing cgi library, which has been working excellently in production for a few months now. I hit a weird problem linking it though: = dmd -of/var/www/cgi-bin/test test.d program/djs/proxy/cgi.d program/djs/dom.d program/lib/arsd/web.d pr

Re: Linking problem with custom associative arrays

2010-07-18 Thread Adam Ruppe
I should add, this problem does *not* strike if I use the cgi module directly. It only seems to come in if I use the fancy framework around it. I don't know why. Maybe it is due to the different locations of main()? In both cases, it is defined in a mixin template, but in the simple case, it goes i

Re: PNG Lib?

2010-07-24 Thread Adam Ruppe
Try mine but a! My computer died on my last Wednesday, and it hosts my dcode too! It is a few hundred lines of D that takes a pixel array and puts out a simple png file. Does the bare minimum I needed to get the job done, but sounds like that's exactly what you want. My code sounds like i

Re: Why don't other programming languages have ranges?

2010-07-27 Thread Adam Ruppe
Lerdorf's quote strikes me as actually being somewhat close to what Walter is talking about. Web applications don't focus on making a thing that never fails, but instead achieve reliability by having an external watchdog switch to backups - that is, a fresh copy of the program - when something goes

Re: What functions could be added to std.algorithm?

2010-08-01 Thread Adam Ruppe
On 8/1/10, Tomek SowiƄski wrote: > Link, please. ;) http://dpldocs.info If any tried to use it last week, you would have noticed it was down: my motherboard died, and the parts to fix it didn't arrive until Friday. It should be up most the time now. You can put in a search term to the box, or u

Re: Andrei's Google Talk

2010-08-03 Thread Adam Ruppe
On 8/3/10, Walter Bright wrote: > Andrei put together a benchmark that shows that D compiles 4 times faster > than Go. I've found D1 tends to be much faster than D2 as well. The dmd version 1 is so fast that I often think it doesn't even run! D2's (relative) slowness I've tracked down to import

Re: Andrei's Google Talk

2010-08-03 Thread Adam Ruppe
On 8/3/10, Andrei Alexandrescu wrote: > BTW, speed of compilation of very short programs is not very relevant as > long as it's reasonably good. I don't know. Large programs is certainly very important, but I think small ones are too. The reason is a very quick compile on small programs means you

Re: Andrei's Google Talk

2010-08-04 Thread Adam Ruppe
On 8/4/10, bearophile wrote: > I am sorry to say this, but I think porting the current back-end to 64 bit > is a waste of time because it will not be used for professional usages. I > think LLVM will be the main back-end for professional usages of D2 Get back to me when LDC starts to actually /wo

Re: Andrei's Google Talk

2010-08-05 Thread Adam Ruppe
On 8/5/10, mwarning wrote: > I assume that's what you call unusable? I mean unusable in the literal sense: $ ./ldc ./ldc: error while loading shared libraries: libelf.so.0: cannot open shared object file: No such file or directory I hear it also doesn't do D2 at all, which is unacceptable, and

Re: Andrei's Google Talk

2010-08-05 Thread Adam Ruppe
On 8/5/10, mwarning wrote: > Google might help. I know what it is, but I have /zero/ respect for people who shove their dependencies on me. It shouldn't be my problem. One of the reasons I went with Digital Mars early on is that DMC just works when you unzip it. DMD continues that tradition, and

Re: typeid() woes

2010-08-08 Thread Adam Ruppe
On 8/8/10, Andrej Mitrovic wrote: > I wonder if there's a way to get the static type, is there an equivalent > function like typeid() for such a case? Try this: typeid(typeof( X )); typeof() returns the static type of the variable. Then, you can get the typeid of that returned static type

Re: A const idiom + a different 'delete'

2010-08-11 Thread Adam Ruppe
Here's how I'd do it: void main() { const T[] buildArray() { T[] t; // fill in t return t; } const T[] t = buildArray; } So the creation is factored away into that nested function which is used to initialized the reference that you keep around.

Re: The Status of Const

2010-08-12 Thread Adam Ruppe
On the subject of rebindable, what about: const Object o; // not rebindable, the whole thing is set once and const const(Object) o; // the Object is const, but the reference is not. So, everything is rebindable unless the declaration has a const/immutable on the outside. int a; // rebindable (ob

Re: Phobos urllib

2010-08-13 Thread Adam Ruppe
I've been using the curl library with a thin wrapper in D: http://arsdnet.net/dcode/curl.d Example use: dmd test.d curl.d -L-lcurl = import std.stdio; import arsd.curl; void main() { writefln("%s", curl("http://arsdnet.net/dcode/curl.d";)); } = That fetches the code off my si

Re: Destructor semantics

2010-08-13 Thread Adam Ruppe
Perhaps relevant to this discussion is the Old New Thing posts this week. This last one has a good sentence: http://blogs.msdn.com/b/oldnewthing/archive/2010/08/13/10049634.aspx "If I ruled the world, I would decree that the only thing you can do in a finalizer is perform some tests to ensure tha

Re: Phobos urllib

2010-08-13 Thread Adam Ruppe
On 8/13/10, Graham Fawcett wrote: > Just FYI, if you add 'pragma(lib, "curl");' to the top of your > curl.d file, you shouldn't need '-L-lcurl' any more; dmd will > add it automatically during linking. Very cool. For some reason, I thought that didn't work on linux... I must have just been doing

Re: Andrei's Google Talk

2010-08-14 Thread Adam Ruppe
To me, the biggest appeal of ddoc is that it doesn't require markup to give good enough results. It's almost mindless to use.

Re: To avoid some 32=>64 bit user code port bugs

2010-08-16 Thread Adam Ruppe
On 8/16/10, bearophile wrote: > So I think size_t=>uint may require a cast on 32 > bit systems too, so when the code gets compiled with the 64 bit dmd this > error isn't present. I don't think that's a good idea because of what you say later in your post: the cast punches a hole through the syste

Re: Notes on the Phobos style guide

2010-08-16 Thread Adam Ruppe
On 8/16/10, bearophile wrote: > 'auto' in C++0x is a good and useful feature, just as it is useful in D, but > as I have explained it has real risks, so it must be used with moderation, > if you use it everywhere in the code, your code becomes harder to understand > and modify. I see it as the op

Re: Contributing

2010-08-16 Thread Adam Ruppe
I started doing this too, and am planning to commit it for the next release. I haven't finished it though. If you email your modified copy of date.d to me (destructionator (at) gmail.com), I'll integrate your changes with mine and commit it to Phobos for you.

Re: Contributing

2010-08-16 Thread Adam Ruppe
On 8/16/10, Yao G. wrote: > Are you working on Gregorian documentation? Or the code itself? I've just been (slowly) documenting std.date. I used it for a work project, and hit a similar situation to Pedro: the module was good enough for me, but I had to dive into the source before I knew it even

Re: [OT] Crazy language limit-pushing (Was: Re: Why C++ compiles slowly)

2010-08-19 Thread Adam Ruppe
On 8/19/10, Nick Sabalausky wrote: > And Adam Ruppe did cgi in Asm: > > http://www.arsdnet.net/cgi-bin/a.out Did I post that to this list, or did it find its way around the Internet on its own? I saw it randomly pop up on a Google search last year too, on a list I've never even

Re: Why C++ compiles slowly

2010-08-20 Thread Adam Ruppe
Glancing over it really quickly, High Level Assembly is /completely insane/. The whole point of writing assembly language is to see and write exactly what the computer sees and executes. This makes it useful for coding, and also very easy to read (in the small, at least). The HLA examples on Wikip

Re: Why C++ compiles slowly

2010-08-20 Thread Adam Ruppe
On 8/20/10, dsimcha wrote: > How did you do this? Don't you lose some important stuff like label names > in the translation? Yes, though a lot of label names aren't all that helpful in the first place. "done:" or worse yet, "L1:" don't help much. Those names are obvious from context anyway. > I

Re: How does D handle null pointers?

2010-08-20 Thread Adam Ruppe
This is brought up somewhat often on this group. Problem with throwing an exception in a segfault is that it is undefined behavior in POSIX. However, I encountered exactly your problem: a null pointer in a big web app. The way I solved it was to sprinkle assert( var !is null ); before I start u

Version bug?

2010-08-20 Thread Adam Ruppe
I just hit something that might be a compiler bug, or might be a documentation bug. (Of course, it can't be me! :P ) I have two modules: config.d === version (clientA) {} version ( clientB ) { version = withFeatureX; } version (clientC) { version = withFeatureX; } === application.d ===

Re: Version bug?

2010-08-20 Thread Adam Ruppe
r other modules." Striking the word "imported", since it being there implies it only changes modules the defining file imports - a one way thing. This lack of influence would in fact go both ways. On 8/20/10, Adam Ruppe wrote: > I just hit something that might be a compiler bug, or mi

Re: Version bug?

2010-08-20 Thread Adam Ruppe
Sorry for three messages in a row, but I just realized what I'm asking for would break incremental compiles, since the version thing wouldn't be propagated there. So I guess it is by design. I think the documentation should be a bit more explicit about it. That kinda sucks though. I can't have tha

Re: Version bug?

2010-08-20 Thread Adam Ruppe
Last message in a row, I promise. I just determined a work around for this - use a global variable. (the config.d file defines several global variables already, but it is stuff like companyName, domainName, etc.). A global enum actually: version(clientA) enum bool withFeatureX = true; =

Re: Version bug?

2010-08-20 Thread Adam Ruppe
On 8/20/10, Andrej Mitrovic wrote: > There are no global variables in D, afaik. But I haven't studied this > closely yet. The opposite: there are multiple kinds. You have enums in the global scope, which are available to everyone, but don't take any storage (that's what I used here), you have re

Re: Version bug?

2010-08-20 Thread Adam Ruppe
On 8/20/10, Andrej Mitrovic wrote: > I dunno, TDPL says: > *snip* That's true, though I think it is getting into nitpicking the definition of global variable still, the module system resolves conflicts in a way that C globals can't hope to do, which is fantastic. All the benefits with none of

Re: How does D handle null pointers?

2010-08-20 Thread Adam Ruppe
On 8/20/10, Adam B wrote: > If only we could trap a segfault signal and have the OS tell us which > thread caused it and provide some mechanism to resume the thread with > an exception... Windows actually does that.

Improved doc page - small change to html

2010-02-21 Thread Adam Ruppe
The Jump To: section on the phobos 2 docs could be made a lot easier by sorting the anchors listed alphabetically. I looked at the html source and noticed that they are generated by some Javascript. Here's a replacement for the function in there now that does this sorting: function listanchors(

Network in phobos

2010-03-27 Thread Adam Ruppe
Something that I think would be nice is being able to treat a network connection the same way we can work with files and stdin. Is there a plan already in place for phobos? If no, I might have something usable to get started. I peered into std.stdio's source and hacked something up. My plan was s

Re: value range propagation for _bitwise_ OR

2010-04-13 Thread Adam Ruppe
Jerome's highbit function is the same as std.intrinsic.bsr. I wonder which is faster? I ran a test, and for 100 million iterations (1..1000), the intrinsic beat out his function be a mere 300 milliseconds on my box. - highbit ran in an average of 1897 ms and bsr did the same in an average if 1

Re: Spellechecker - is this really fun?

2010-05-08 Thread Adam Ruppe
On 5/8/10, d user wrote: > 3. design new DMD2 features > At this point we should be in stage 3 or 4. You mean like an integrated spell checker?

Re: Should scope(exit) be valid outside of a scope?

2010-05-11 Thread Adam Ruppe
On Tue, May 11, 2010 at 10:18:29PM +0200, Don wrote: > Currently the scope(exit) doesn't get executed at all (it's bugzilla > 1894). But I suspect that any such use of scope guards is a bug. > Can we just make it illegal? I was pondering named unit tests and wanted to use this: { if(g

Re: Should scope(exit) be valid outside of a scope?

2010-05-11 Thread Adam Ruppe
On Tue, May 11, 2010 at 06:56:52PM -0700, S wrote: > static if doesn't create a new scope. You should use that instead and > a debug version. But you can't static if based on a runtime value.

Re: Default argument values

2010-05-20 Thread Adam Ruppe
On 5/20/10, bearophile wrote: > A default argument may be an arbitrary expression. What I do in code where I want this kind of behaviour is something like this: void func(Whatever* options = null) { if(options is null) options = Whatever(default blah blah); } (substitute null for a

Re: Poll: Primary D version

2010-05-20 Thread Adam Ruppe
As a thought, when/if you decide to write your own polling system, I think it should log the website referrer as well as the voter's ip and choice. It'd be interesting to see stats about skewing from a certain site, like if everyone who followed a link on "d-sucks-ass.org" voted "none and never wi

Re: Poll: Primary D version

2010-05-22 Thread Adam Ruppe
On 5/22/10, retard wrote: > On a 4 GB system you lose 600+ MB of memory when using a 32-bit operating > system without PAE support. You can run 32 bit programs on a 64 bit operating system. The point isn't that 64 bits is useless in general, it is just that most *applications* work just fine as 3

Re: Poll: Primary D version

2010-05-22 Thread Adam Ruppe
On 5/22/10, retard wrote: > I can't believe the 64-bit processes are twice as large. They probably aren't. I don't think we're talking about the same thing here. I, and I don't think Nick is either, am not saying that 64-bit is bad. We're just saying not having 64 bit isn't a big deal for most a

Re: Poll: Primary D version

2010-05-22 Thread Adam Ruppe
On 5/22/10, bearophile wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=4165 I don't think that's a bug. It should only worry about converting, not filtering out bad stuff. That's an orthogonal problem that the other function does well, and easily too.

Re: 64-bit support (Was: Poll: Primary D version)

2010-05-24 Thread Adam Ruppe
On 5/24/10, bearophile wrote: > Even faster than an installer, for people that just want to try the language > quickly it can be useful a single-file zero-install download-and-go thing That's exactly what the zip is. Unzip it and go. To uninstall, just delete the folder. On Linux, you could argue

<    1   2   3