DMDScript now on D2

2010-12-16 Thread Dmitry Olshansky
Following that quite emotional discussion of JavaScript on  
digitalmars.D I decided I'll take a risk to announce my work on porting 
DMDScript, that is ECMA-262 script engine.


In the end it turned out to more like a quite successful fork given the 
amount of changes. The goal was not only to just make it compile with D2 
and work (that would be of limited value) but also slowly convert it to 
newer D2 idioms/libraries/etc, I essence simplifying user side code  for 
writing extensions. For instance, I even managed to use immutable 
strings throughout, at the expense of a couple of casts at critical spots.


I'm considering current state of release as stable beta, since I had to 
disable some of original performance tricks in order to debug some 
issues properly. They eventually would be re-enabled of course.
Latest tar with source code + samples can be found here: 
http://dsource.org/projects/dmdscript-2/browser/downloads


Things of possible interest:
-- Builds  fully works with latest dmd , tested on Windows and Linux
-- Greatly increased standard conformance
-- Still runs quite fast
-- Some huge bugs fixed, that were present in DMDScript 1.16 . (for 
instance 'in' _expression_ not implemented)
-- Includes (highly experimental)  module for extending script engine 
with native D functions/types in a couple of LOCs

-- Contains few basic examples to get started

P.S. I'm still reluctant to give it a version number, should it be 
DMDScript2 0.1 ?


--
Dmitry Olshansky



Re: DMDScript now on D2

2010-12-16 Thread Adam Ruppe
Dmitry Olshansky wrote:
 The goal was not only to just make it compile with D2
 and work (that would be of limited value)

I tried this too about a year ago...:
http://arsdnet.net/dcode/dmdscript_d2.zip

...but overall, from a brief glance, your port is *much* better
than mine. I used a lot more casts and idups, and thus introduced
new bugs and hurt the performance. I got it working, but not working
well.

Nice work!

But there still might be a few ideas or bits of code
we can share from the easy expansion stuff.

I called mine pretty.d and test.d in that zip. One of the
things I tried to do was make a ScriptObject class in D, which
you could expand and call with opIndex and opDispatch.

I was only partially successful, but maybe we can better with
a newer compiler.

Here's a copy/paste of part of my test.d showing the idea I was chasing:

===
auto g = se.globalObject; // se is a ScriptEngine

/* You can work with the script environment as an associative
array... */
g[hello] = Hello, world!;
g[lol] = new ScriptObject; // ScriptObject is just a generic object.
You can specialize it in the constructor.
//g[lol][fun] = fun; // Can even assign native top-level functions
this way!  FIXME: broken due to ICE

/* Or, you can do it with opDispatch, though this is limited to just
assigning existing ScriptObjects... */
auto so2 = new ScriptObject;
se.globalObject.lol.hate = so2;

/* You can also add functions to specific ScriptObjects with the
addFunction template */
se.addFunction!(raise, fun)(so2);

===

And all that stuff would of course be available to the script via
the global object.

In pretty.d, you can see some attempt to unify D and dmdscript
exceptions too, but I don't recall how well that went, but I'm
pretty sure it worked at least one way.


One little thing we both did is one line expansion. One thing I'd
add to your code is making the name of the script function default
to being the same name as the D function. It's a minor addition,
but I think it looks nice.


Generally though, your port is excellent, thanks for doing it!


Re: DMDScript now on D2

2010-12-16 Thread Dmitry Olshansky

On 16.12.2010 19:43, Adam Ruppe wrote:

Dmitry Olshansky wrote:

The goal was not only to just make it compile with D2
and work (that would be of limited value)

I tried this too about a year ago...:
http://arsdnet.net/dcode/dmdscript_d2.zip
Yes, that's the only previous effort I've found, and  it was after my 
port almost started working.



...but overall, from a brief glance, your port is *much* better
than mine. I used a lot more casts and idups, and thus introduced
new bugs and hurt the performance. I got it working, but not working
well.

Nice work!
Thanks, yet I plan a lot of refactoring, one I dream of is eventually 
replacing struct Value with Algebraic from Phobos. And yes, that 
exception propagation mechanism, I almost switched to throwing instead 
of returning exceptions from functions.

But there still might be a few ideas or bits of code
we can share from the easy expansion stuff.

I called mine pretty.d and test.d in that zip. One of the
things I tried to do was make a ScriptObject class in D, which
you could expand and call with opIndex and opDispatch.

I was only partially successful, but maybe we can better with
a newer compiler.

Here's a copy/paste of part of my test.d showing the idea I was chasing:

===
 auto g = se.globalObject; // se is a ScriptEngine

 /* You can work with the script environment as an associative
array... */
 g[hello] = Hello, world!;
 g[lol] = new ScriptObject; // ScriptObject is just a generic object.
You can specialize it in the constructor.
 //g[lol][fun] =fun; // Can even assign native top-level functions
this way!  FIXME: broken due to ICE

 /* Or, you can do it with opDispatch, though this is limited to just
assigning existing ScriptObjects... */
 auto so2 = new ScriptObject;
 se.globalObject.lol.hate = so2;

 /* You can also add functions to specific ScriptObjects with the
addFunction template */
 se.addFunction!(raise, fun)(so2);

===

Yes, that's awesome. I guess I should get a closer look at that pretty.d!

And all that stuff would of course be available to the script via
the global object.

In pretty.d, you can see some attempt to unify D and dmdscript
exceptions too, but I don't recall how well that went, but I'm
pretty sure it worked at least one way.


One little thing we both did is one line expansion. One thing I'd
add to your code is making the name of the script function default
to being the same name as the D function. It's a minor addition,
but I think it looks nice.


Yes, it's planned, and indeed improves user experience. I just was stuck 
with the issue of extending of variadic functions/templated functions 
consider, for example, std.stdio.writeln.  That must have distracted me 
from this issue.




Generally though, your port is excellent, thanks for doing it!

--

Dmitry Olshansky



Re: DMDScript now on D2

2010-12-16 Thread Brian Hay

On 17/12/2010 2:14 AM, Dmitry Olshansky wrote:

I decided I'll take a risk to announce my work on porting DMDScript,
that is ECMA-262 script engine.


Nice!

As few seem to read the DMDScript newsgroup, here's my last post as it 
seems relevant to this topic.


===

There's a JavaScript arms race going on (as I'm sure many of you are 
aware). The competing JS engines of the major browsers are leap-frogging 
each other in performance every few months it seems.


http://www.conceivablytech.com/4472/products/chrome-10-posts-huge-performance-jump/

It would be so cool (and a huge showcase for the D Programming Language) 
if DMDScript was in that performance race and beating the big guns.


Possible?


Re: DMDScript now on D2

2010-12-16 Thread Nick Sabalausky
Brian Hay b...@construct3d.com wrote in message 
news:ieecsp$1ej...@digitalmars.com...
 On 17/12/2010 2:14 AM, Dmitry Olshansky wrote:
 I decided I'll take a risk to announce my work on porting DMDScript,
 that is ECMA-262 script engine.

 Nice!

 As few seem to read the DMDScript newsgroup, here's my last post as it 
 seems relevant to this topic.

 ===

 There's a JavaScript arms race going on (as I'm sure many of you are 
 aware). The competing JS engines of the major browsers are leap-frogging 
 each other in performance every few months it seems.

 http://www.conceivablytech.com/4472/products/chrome-10-posts-huge-performance-jump/

 It would be so cool (and a huge showcase for the D Programming Language) 
 if DMDScript was in that performance race and beating the big guns.

 Possible?

First step, of course, would be to run those benchmarks on DMDScript. Though 
everyone probably knows I'm a rather vocal anti-fan of JS, even I'd be very 
interested to see how DMDScript currently stacks up to the rest. I'd laugh 
my ass off if after all this time of not a whole lot of work on DMDScript 
besides the port to D2 (unless I'm mistaken), if it still managed to be on 
par with or beat all those others that have been pounding their chests and 
bashing each other over the head.




Re: DMDScript now on D2

2010-12-16 Thread Brian Hay

On 17/12/2010 12:00 PM, Nick Sabalausky wrote:

Brian Hayb...@construct3d.com  wrote in message
news:ieecsp$1ej...@digitalmars.com...

On 17/12/2010 2:14 AM, Dmitry Olshansky wrote:

I decided I'll take a risk to announce my work on porting DMDScript,
that is ECMA-262 script engine.


Nice!

As few seem to read the DMDScript newsgroup, here's my last post as it
seems relevant to this topic.

===

There's a JavaScript arms race going on (as I'm sure many of you are
aware). The competing JS engines of the major browsers are leap-frogging
each other in performance every few months it seems.

http://www.conceivablytech.com/4472/products/chrome-10-posts-huge-performance-jump/

It would be so cool (and a huge showcase for the D Programming Language)
if DMDScript was in that performance race and beating the big guns.

Possible?


First step, of course, would be to run those benchmarks on DMDScript. Though
everyone probably knows I'm a rather vocal anti-fan of JS, even I'd be very
interested to see how DMDScript currently stacks up to the rest. I'd laugh
my ass off if after all this time of not a whole lot of work on DMDScript
besides the port to D2 (unless I'm mistaken), if it still managed to be on
par with or beat all those others that have been pounding their chests and
bashing each other over the head.


Like it or not, javascript is THE programming language of the 
client-side web (rich web apps, Google maps, docs, Flash ActionScript, 
X3D etc etc), so to be in that arms race would be a huge boon to the D 
Programming Language IMHO.


Agreed, DMDScript is unlikely to be competitive with compiled JS engines 
like V8 and spidermonkey now, but we won't know until it's benchmarked 
and possibly some of the performance enhancements that went into those 
engines can be adapted for dmdscript (although I don't know the first 
thing about interpreter or compiler writing, so I'm just speculating).




Re: DMDScript now on D2

2010-12-16 Thread Adam D. Ruppe
Brian Hay wrote:
 It would be so cool (and a huge showcase for the D Programming Language)
if DMDScript was in that performance race and beating the big guns.

It kicked the living crap out of the competition up to not too long ago! It beat
out Firefox 2 by well about 50x when I checked it, and IE7 by IIRC 20x.

What's really impressive is dmdscript was several years old at
that point - as in it only got a few minor bugfixes in those years,
and the main design was even older. It took the big guys some
five years or more to catch up to lone Walter.


It was about 1/2 the speed of Firefox 3 when I checked it last. That
gap has probably widened quite a bit in the last year. A quick check using the
sieve.ds shows Firefox 3 is currently about 16x faster than dmdscript.

The gap is definitely opening up in the other direction now, but
still, it took them long enough!



Could dmdscript take the lead back? Probably, though I suspect it'd
be quite a lot of work. But I don't really know. dmdscript is a kind of 
compiler,
so maybe not. I'm just not qualified.


Re: DMDScript now on D2

2010-12-16 Thread Nick Sabalausky
Brian Hay b...@construct3d.com wrote in message 
news:ieehug$1q5...@digitalmars.com...
 On 17/12/2010 12:00 PM, Nick Sabalausky wrote:
 Brian Hayb...@construct3d.com  wrote in message
 news:ieecsp$1ej...@digitalmars.com...
 On 17/12/2010 2:14 AM, Dmitry Olshansky wrote:
 I decided I'll take a risk to announce my work on porting DMDScript,
 that is ECMA-262 script engine.

 Nice!

 As few seem to read the DMDScript newsgroup, here's my last post as it
 seems relevant to this topic.

 ===

 There's a JavaScript arms race going on (as I'm sure many of you are
 aware). The competing JS engines of the major browsers are leap-frogging
 each other in performance every few months it seems.

 http://www.conceivablytech.com/4472/products/chrome-10-posts-huge-performance-jump/

 It would be so cool (and a huge showcase for the D Programming Language)
 if DMDScript was in that performance race and beating the big guns.

 Possible?

 First step, of course, would be to run those benchmarks on DMDScript. 
 Though
 everyone probably knows I'm a rather vocal anti-fan of JS, even I'd be 
 very
 interested to see how DMDScript currently stacks up to the rest. I'd 
 laugh
 my ass off if after all this time of not a whole lot of work on DMDScript
 besides the port to D2 (unless I'm mistaken), if it still managed to be 
 on
 par with or beat all those others that have been pounding their chests 
 and
 bashing each other over the head.

 Like it or not, javascript is THE programming language of the client-side 
 web (rich web apps, Google maps, docs, Flash ActionScript, X3D etc etc), 
 so to be in that arms race would be a huge boon to the D Programming 
 Language IMHO.


Agreed. I can at least see the writing on the wall even if I don't like what 
it says ;)

Although in the case of Flash, I've been using Haxe which compiles directly 
to Flash bytecode. I think there may be some intermediate ActionScript 
needed for a few things if you're doing strictly Flash9+, but the 
combination of Haxe and some custom tools/libs I've made have been enough to 
paper over enough of the usual drawbacks of maintaining Flash8/Wii 
compatibility.

 Agreed, DMDScript is unlikely to be competitive with compiled JS engines 
 like V8 and spidermonkey now, but we won't know until it's benchmarked and 
 possibly some of the performance enhancements that went into those engines 
 can be adapted for dmdscript (although I don't know the first thing about 
 interpreter or compiler writing, so I'm just speculating).


Yea. It would also be really interesting to see how much work would really 
be needed to bring it back up to par with the latest competition. Being able 
to get up the that really easily would be a nice bragging right for D. :)





Re: A Benchmark for Phobos Sort Algorithm

2010-12-16 Thread spir
On Wed, 15 Dec 2010 23:07:46 -0800
Jonathan M Davis jmdavisp...@gmx.com wrote:

 It would be nice to get a fairly extensive lists of types to sort with a 
 variety 
 of values and number of values of those types and set up an extensive set of 
 benchmarking tests. Heck, such a set of types and collections of those types 
 could be a useful benchmarking tool for a variety of algorithms. Then we'll 
 have 
 a good base to build from and compare to. If we're going to tweak algorithms 
 for 
 efficiency, we're going to want to some thorough tests so that we're sure 
 that any 
 tweaks are actually overall improvements. It's easy to find cases which do 
 poorly 
 for a particular algorithm. It can even be fairly easy to tweak an algorithm 
 to 
 improve that particular case. But it's not so easy to be sure that that tweak 
 is 

On one hand, having sut a source data set would be nice nice. On the other, 
such general-purpose algorithm simply cannot perform well; so, I would not 
bother much.
If one does need efficiency, then it is necessary to use or write a custom sort 
adapted to the data type (int), the value space ([1,99]), the actual 
distribution (many small values), the degree of pre-ordering of source data 
(bigger values have higher chances to come last),...
The performance ratio between a specific and general algorithm can be huge, as 
you know.

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



Re: emscripten

2010-12-16 Thread Lars T. Kyllingstad
On Thu, 16 Dec 2010 01:31:13 -0600, Andrew Wiley wrote:

 On Wed, Dec 15, 2010 at 3:16 PM, Nick Sabalausky a...@a.a wrote:
 
 Michael Stover michael.r.sto...@gmail.com wrote in message
 news:mailman.1041.1292446362.21107.digitalmar...@puremagic.com...
  With my own computer, there are things I can do to prevent that.
  With
  webapps I'm 100% reliant on someone else: there isn't a damn thing I
  can do.
 
  But what about your group-think lemming mother?
 
 
 Unfortunately, she leaves the security and accessibility of her data at
 the mercy of MS's web monkeys. So tell me how exactly that's supposed
 to be an improvement over just keeping it on her local system? Yes,
 either way there are possible security risks. But there isn't a chance
 in hell a webapp can actually be considered better in that regard.



 This is what you're not seeing. Web applications have zero-install,
 zero-configuration, and while you've pointed out that people whine when
 they change, those same people are already using them and continue to
 use them anyway. Why? Ease of use.
 The sad truth is that most computer users know next to nothing about how
 their computer works, and when given the choice between a fully featured
 email client they have to set up properly and a ready-to-go webmail
 system like Gmail/Hotmail, the choice seems fairly obvious. The same
 average user would probably say their data is safer with Microsoft than
 on their computer, simply because Microsoft has experts working to
 maintain privacy and backup, while the user might not even understand
 how he/she would go about that sort of thing. Now, from the inside that
 we see as developers, the picture isn't as pretty, but still. Computers
 and software are designed and created by the elite for both the elite
 and the non-elite. When the non-elite have a choice between doing it
 themselves and trusting it to the elite, the rise of web applications
 shows that they will generally choose the elite.
 For power users, this choice just isn't the same.

This just means that the elite has failed in ensuring that the obvious 
choice is the right one.

As you say, the average user will chose whatever looks simpler or more 
convenient, regardless of whether it actually *is* the best choice, 
performance- or security-wise.  (Or even with regards to user-
friendliness, once the seemingly insurmountable hurdles of installation 
and configuration have been passed.)  But that doesn't mean that 
developers should take advantage of that to push crappy applications on 
people.

Instead, developers should work to make local applications as easy to use 
as web applications, or to find a better way of serving applications over 
the internet than running them in a glorified document viewer.

-Lars


Re: Binary heap method to update an entry.

2010-12-16 Thread Andrei Alexandrescu

On 12/15/10 10:21 PM, Matthias Walter wrote:

Hi all,

I uploaded [1] a patch for std.container to use BinaryHeap as a priority
queue. For the latter one it is often necessary to change a value (often
called decreaseKey in a MinHeap). For example, Dijkstra's shortest path
algorithm would need such a method. My implementation expects that the
user calls the update method after changing the entry in the
underlying store.

My method works for value-decrease and -increase, but one might want to
split this functionality into two methods for efficiency reasons. But I
thought it'll be better, because one can change the MaxHeap to be a
MaxHeap by changing the template alias parameter, but this wouldn't
change the method names :-)

The patch is against current svn trunk.

[1] http://xammy.xammy.homelinux.net/files/BinaryHeap-PriorityQueue.patch


A better primitive is to define update to take an index and a new value, 
such that user code does not need to deal simultaneously with the 
underlying array and the heap. No?


Andrei


Re: Why Ruby?

2010-12-16 Thread Stephan Soller

On 15.12.2010 17:37, Andrej Mitrovic wrote:

On 12/15/10, Stephan Sollerstephan.sol...@helionweb.de  wrote:


So, _if_ we can figure out a way to do some nice chaining of such calls
we can get:

[1, 2, 3, 4, 5].filter!((e){ return e  3; })
.map!((e){ return e*e; });

Or if you don't like delegates and don't mind obvious compile time black
magic:

[1, 2, 3, 4, 5].filter!(a  3).map!(a * a);



You might use pipe! as an alternative:

import std.algorithm;
import std.functional;
import std.stdio;

void main()
{
 int[] arr = [1, 2, 3, 4, 5];
 auto result = pipe!( filter!(a3), map!(a * a) )(arr);
 writeln(result);
}

But I can't seem to do the same with delegates:

import std.algorithm;
import std.functional;
import std.stdio;

void main()
{
 int[] arr = [1, 2, 3, 4, 5];
 pipe!( filter!( (e){ return e  3; } ),
  map!( (e){ return e*e; } ) )(arr);
}

chain.d(9): Error: expression template filter(Range) is not a valid
template value argument
chain.d(9): Error: expression template map(Range) is not a valid template
value argument


Thanks for testing this out. :)

I noticed compose! and pipe! but these break my thought flow. It's 
hard to describe since I only experienced such a way of writing code in 
Ruby. You can more or less write your thoughts down without much 
translation or the need to go back and forth in the line. As you think 
you can type… I don't need a thought buffer so to speak.


Having to think about if I want to call multiple collection operations 
or just one right at the start breaks this flow. That the data at hand 
is pushed to the end of the line (poor visibility) also don't really 
help. I don't know if this is a matter preference but while deciding on 
such collection operations I usually think about the data first. Only if 
I know how the data is structured I start to apply operations on it.


This code

[1, 2, 3, 4, 5].filter!(a  3).map!(a * a);

matches the that flow of thoughts. With pipe! I have to jump 2 times 
within a buffer of 3 thoughts.


All that may sound very… unprofessional or not like a real programmer. 
However that kind of mental friction adds up and you notice that if 
it's no longer there. I really agree with Matz (the creator of Ruby) 
that the way you formulate your thoughts changes your thought patterns 
in turn. Ruby is carefully crafted to keep the resulting thought 
patterns close to the natural ones. To experienced programmers this 
might be irritating at first since languages like C++, Java and even D 
require some mental acrobatics to formulate what you want. It takes some 
time to just think strait again if you're used to these acrobatics. Ruby 
is a very interesting subject if you're interested in what programmers 
think while programming.


Please note that this stuff is IMHO limited to application programming. 
That is to solve hight level problems where low level work only adds 
friction and is not that important (like with usual Websites). With 
systems level programming this is different. When working with low-level 
APIs and very machine specific problems the thought patterns are 
different than the ones of application programming. The problems are 
often not defined by real world needs and therefore the experience from 
the real world can not help there.


This is the reason why I think D should not spend to much time with 
this. It's not a design goal of D and probably would collide with other 
design goals (e.g. efficient compiler implementation). If someone really 
wants this kind of programming in D it's not that difficult to do, but 
will cost efficiency (e.g. using real functions instead of templates). D 
should not mimic Ruby nor is Ruby as bad as some might think. It's one 
of the few languages that really accept that programmers are humans and 
not machines. D does this too but by far not to the same extend (thats 
why I still like D1 more than D2 actually).


Ruby has its applications and D has its applications. The right tool for 
the right job only works if the different tools have a distinct purpose 
and not try to do everything at the expense of being good at one thing.


Happy programming
Stephan Soller


Re: New syntax for string mixins

2010-12-16 Thread Pelle Månsson

On 12/15/2010 11:00 PM, Nick Sabalausky wrote:

Jonathan M Davisjmdavisp...@gmx.com  wrote in message
news:mailman.1035.1292441722.21107.digitalmar...@puremagic.com...

On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:


That was my idea as well, that

@get_set(int, bar);

could be translated into

mixin(get_set(int, bar)); just like

just like scope statements are translated into try/catch/finally.


Honestly, I don't see much gain in using @ rather than mixin(). It's a
little
less typing, but that's it.


It does seem like a small difference, just replacing mixin with @ and
removing one layer of parens. But I think that extra layer of parens, minor
as it seems, makes a big difference in the readability (and typeability)
of mixin invocations. Those extra parens do get to be a real bother, major
visual noise at least to my eyes.



I agree with this. Actually, just removing the parenthesis would be a 
huge gain for me.



And it precludes stuff like mixin(lhs  ~ op ~ 
rhs) like happens all the time in overloaded operator functions.



I don't see why these shouldn't work:

@int foo;;
return @(lhs  ~ op ~  rhs);

At least with just the @ part of the proposal. Maybe the delegate thing
might make it tricker, I dunno.



This could work, but I don't think anyone is suggesting completely 
replacing the mixin. I think @ could be a function/template thing, and 
have strings in a more explicit mixin;


Then again, inconsistency sucks.


Re: emscripten

2010-12-16 Thread Adam Chandler
Michael Stover Wrote:

  there's no integration with the
 external environment
 
 But it is an advantage at the same time as it's a weakness.  The advantage
 is, I can read and use gmail or google docs anywhere, firewall or not.
 
 I could sit here at home, open an openoffice doc, write in it, save it.
  Then tomorrow go to work, open open office and bitch and scream about why
 the doc I made last night at home isn't in my recent docs list!! ZOMG!!! I
 *LOATHE* Open Office!  I can't do the simplest thing!  But, no, I recognize
 the limitations of the different mediums, and rather than look at what is
 not exactly the same as what I'm used to, I can see what it does that I've
 not been able to do before.  If you'd asked me 1 year ago about javascript,
 I would have laughed and said no way I would want to use that crap.  I've
 learned to think otherwise since.
 
 If you go looking for problems, you're going to find them.  To me, it simply
 indicates inflexibility on your part.  Which is fine, like I said, the world
 doesn't care about your inability to adapt and see new possibilities.
 
 It's just, the strength of the emotional response in this thread has been
 kind of revealing.

Dear Mike, you're one of the most annoying wankers I've seen. Go f** yourself 
or even better, go kill yourself. TYVM let us have a nice day.


Re: emscripten

2010-12-16 Thread Pelle Månsson

On 12/15/2010 03:17 PM, Michael Stover wrote:

And that's the problem - we're talking about applications that happen to
be distributed via the web, not a website.  Everyone's demands that it
work in lynx, FF2, with javascript turned off, etc are ludicrous.


I disagree.


You don't get to make such demands of applications.


Yes I do!


Some applications areWindows only.


Not running them.


Some don't follow platform standards.


They suck!


Some require 1GB to work effectively.


Probably not running them.


These expectations are invalid.


They are not.

The idea that you shouldn't expect things to be good is backwards. 
Web-as-a-platform isn't good. Maybe it can be in the future. It's not now.


Re: emscripten

2010-12-16 Thread Adam Ruppe
Andrew Wiley wrote:
 Web applications have zero-install

But they trade it in for registration, with those awful, awful
CAPTCHAs.

They don't just distinguish between humans and computers (sometimes).
They also distinguish between flawless humans with perfect vision
and expensive monitors and real life humans who can't see the
poorly contrasting colors or can't distinguish letters with a
font size of 8 pixels. Some have letters right on top of each
other what order do they want it? Gah.

It invariably takes me two or three attempts to get those stupid
things. Thankfully, the popular Re-Captcha ones are among the
easiest to read, but that doesn't help when someone still uses
the green on red with purple stripes and tiny font variety. It's
been a while since I saw the Google captcha, but I remember it
as being nearly impossible.


The worst part is they come back post-registration too! Vile.


Re: emscripten

2010-12-16 Thread Michael Stover
And CAPTCHAs prove that javascript and browsers are terrible???

You must have failed logic class.  Probably you never took it, knowing how
poorly you would do.

I should criticize your precious local apps because some require dongles.

On Thu, Dec 16, 2010 at 8:28 AM, Adam Ruppe destructiona...@gmail.comwrote:

 Andrew Wiley wrote:
  Web applications have zero-install

 But they trade it in for registration, with those awful, awful
 CAPTCHAs.

 They don't just distinguish between humans and computers (sometimes).
 They also distinguish between flawless humans with perfect vision
 and expensive monitors and real life humans who can't see the
 poorly contrasting colors or can't distinguish letters with a
 font size of 8 pixels. Some have letters right on top of each
 other what order do they want it? Gah.

 It invariably takes me two or three attempts to get those stupid
 things. Thankfully, the popular Re-Captcha ones are among the
 easiest to read, but that doesn't help when someone still uses
 the green on red with purple stripes and tiny font variety. It's
 been a while since I saw the Google captcha, but I remember it
 as being nearly impossible.


 The worst part is they come back post-registration too! Vile.



Re: emscripten

2010-12-16 Thread Jeff Nowakowski

On 12/15/2010 04:31 PM, Nick Sabalausky wrote:


But if you're going to make, say, a mortgage rate calculator,
excluding Lynx or requiring JS makes absolutely no sense whatsoever.


This is actually a good example of why you might require JavaScript. 
Here, JavaScript is useful to the end user because it doesn't require a 
request and response to the server, so everything is faster and smoother.


Supporting both JavaScript and plain HTML takes extra work for little 
benefit, since the vast majority of users have it enabled.


It's not 1995 anymore.


[OT] Mozilla Thunderbird

2010-12-16 Thread Justin Johansson

Just wondering how others rate Thunderbird as a decent newsreader.

My experience with Thunderbird is that it is not of a standard of 
distinction that one would hope for in 2010 coming 2011.


For one thing, and perhaps this is a newsgroup server problem, but I 
doubt it, my Thunderbird client shows a number of D NG topics as being 
unread though the folder tree item for d.D shows all items as read.


Aside from that issue, my experience with Thunderbird is that it is not 
particularly innovative in drawing my attention to the high-traffic 
topics apart from telling me that one-or-more responses are unread (as 
opposed to popular topics for example).


Overall I think Thunderbird is a bit lame as a newsreader for this day 
and age, and, though it owes me nothing and I paid nothing for it, I do 
wonder what others think of their NG experience using Mozilla Thunderbird.


-- Justin






Re: emscripten

2010-12-16 Thread Adam Ruppe
Lars T. Kyllingstad wrote:
 find a better way of serving applications over
 the internet than running them in a glorified document viewer.

This is something I've been (very) slowly working on for a while,
with my D Windowing System project.

My idea was to take a fairly high level GUI API and put it over
the network. By adding a middleman program, it can handle multiple
user sessions, and most importantly, remember state across dying
processes, without complicating the application. So if you leave
the program on your desktop and connect from your laptop, it is
just as you left it. Like what Remote Desktop does, but for
individual applications.

It doesn't just do gui either, since there's more to an application
than graphics. I included sound, files, and a little more in the
setup too. (A lot of inspiration from Remote Desktop.)

With a high level API, latency can be kept to a minimum by doing
local processing, and integration with the local system is done
simply by *not* micro-managing it - let the widgets do their default
whenever possible so the local operating system handles the details.


An interesting side effect of this is some dws applications actually can run in
the browser. I've written a partial javascript viewer
that, so far, runs my three demo applications (aim, notepad, and
calculator)! While it is not as good of an experience as using
the Windows viewer, it does work.

Though, notepad, calculator, and a buggy aim client aren't
particularly taxing to a GUI's capabilities. I still have a lot
of work to do before being able to make a confident public release.
Last time I spent a good chunk of time on it, I was doing a low
level event api. Very difficult to get that working as well as I
want given network lag, but not impossible.

(And, of course, these programs don't have to be run over a network.
 They work just as well as stand alone local apps, but I'd like the
 network still be as fast as possible.)


Re: Binary heap method to update an entry.

2010-12-16 Thread Matthias Walter
On 12/16/2010 04:17 AM, Andrei Alexandrescu wrote:
 On 12/15/10 10:21 PM, Matthias Walter wrote:
 Hi all,

 I uploaded [1] a patch for std.container to use BinaryHeap as a priority
 queue. For the latter one it is often necessary to change a value (often
 called decreaseKey in a MinHeap). For example, Dijkstra's shortest path
 algorithm would need such a method. My implementation expects that the
 user calls the update method after changing the entry in the
 underlying store.

 My method works for value-decrease and -increase, but one might want to
 split this functionality into two methods for efficiency reasons. But I
 thought it'll be better, because one can change the MaxHeap to be a
 MaxHeap by changing the template alias parameter, but this wouldn't
 change the method names :-)

 The patch is against current svn trunk.

 [1]
 http://xammy.xammy.homelinux.net/files/BinaryHeap-PriorityQueue.patch

 A better primitive is to define update to take an index and a new
 value, such that user code does not need to deal simultaneously with
 the underlying array and the heap. No?
Well, I thought of the case where you have an array of structs and use a
custom less function for ordering. There you might not have a new value,
i.e. a replaced struct, but just a minor change internally. But I see
your idea, in most cases you would just call update after replacing your
array entry... Could we provide both, maybe?

Matthias Walter


Re: emscripten

2010-12-16 Thread Justin Johansson

On 17/12/10 00:35, Jeff Nowakowski wrote:

On 12/15/2010 04:31 PM, Nick Sabalausky wrote:


But if you're going to make, say, a mortgage rate calculator,
excluding Lynx or requiring JS makes absolutely no sense whatsoever.


This is actually a good example of why you might require JavaScript.
Here, JavaScript is useful to the end user because it doesn't require a
request and response to the server, so everything is faster and smoother.

Supporting both JavaScript and plain HTML takes extra work for little
benefit, since the vast majority of users have it enabled.

It's not 1995 anymore.


True its not 1995 anymore but in 2010 JavaScript has not made any 
significant headway in language maturity since its lame-day incarnation 
a decade ago.  The paradox, of course, is that this lame language has 
attained ubiquity (at least in the web client arena) and that there 
seems little else in the way of competition as to a truly web-standard 
offering (aside from plugins that the big end of town want you to 
install, or try to install on your Open Source Browser without your 
permission).




Re: emscripten

2010-12-16 Thread Lars T. Kyllingstad
On Thu, 16 Dec 2010 13:54:24 +, Adam Ruppe wrote:

 Lars T. Kyllingstad wrote:
 find a better way of serving applications over the internet than
 running them in a glorified document viewer.
 
 This is something I've been (very) slowly working on for a while, with
 my D Windowing System project.

I know, and I'm very interested in that project.  I drop by your home 
page every once in a while to keep up to date, and I continually fight 
the urge to nag you about it. ;)

-Lars


Re: Binary heap method to update an entry.

2010-12-16 Thread Andrei Alexandrescu

On 12/16/10 7:55 AM, Matthias Walter wrote:

On 12/16/2010 04:17 AM, Andrei Alexandrescu wrote:

On 12/15/10 10:21 PM, Matthias Walter wrote:

Hi all,

I uploaded [1] a patch for std.container to use BinaryHeap as a priority
queue. For the latter one it is often necessary to change a value (often
called decreaseKey in a MinHeap). For example, Dijkstra's shortest path
algorithm would need such a method. My implementation expects that the
user calls the update method after changing the entry in the
underlying store.

My method works for value-decrease and -increase, but one might want to
split this functionality into two methods for efficiency reasons. But I
thought it'll be better, because one can change the MaxHeap to be a
MaxHeap by changing the template alias parameter, but this wouldn't
change the method names :-)

The patch is against current svn trunk.

[1]
http://xammy.xammy.homelinux.net/files/BinaryHeap-PriorityQueue.patch


A better primitive is to define update to take an index and a new
value, such that user code does not need to deal simultaneously with
the underlying array and the heap. No?

Well, I thought of the case where you have an array of structs and use a
custom less function for ordering. There you might not have a new value,
i.e. a replaced struct, but just a minor change internally. But I see
your idea, in most cases you would just call update after replacing your
array entry... Could we provide both, maybe?


Good point. Here's what I suggest:

/**
  Applies unary function fun to the element at position index, after 
which moves that element to preserve the heap property. (It is assumed 
that fun changes the element.) Returns the new position of the element 
in the heap.


Example:


int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
auto h = heapify(a);
assert(equal(a, [ 16, 14, 10, 9, 8, 7, 4, 3, 2, 1 ]));
h.update!a -= 5(1);
assert(equal(a, [ 16, 10, 9, 9, 8, 7, 4, 3, 2, 1 ]));

*/
size_t update(alias fun)(size_t index);

Let me know of what you think, and thanks for contributing. When using 
unaryFun inside update, don't forget to pass true as the second argument 
to unaryFun to make sure you enact pass by reference.


Obviously, if you have already changed the element, you may always call 
update with an empty lambda.



Andrei


Re: Binary heap method to update an entry.

2010-12-16 Thread Matthias Walter
On 12/16/2010 10:53 AM, Andrei Alexandrescu wrote:
 On 12/16/10 7:55 AM, Matthias Walter wrote:
 On 12/16/2010 04:17 AM, Andrei Alexandrescu wrote:
 On 12/15/10 10:21 PM, Matthias Walter wrote:
 Hi all,

 I uploaded [1] a patch for std.container to use BinaryHeap as a
 priority
 queue. For the latter one it is often necessary to change a value
 (often
 called decreaseKey in a MinHeap). For example, Dijkstra's shortest
 path
 algorithm would need such a method. My implementation expects that the
 user calls the update method after changing the entry in the
 underlying store.

 My method works for value-decrease and -increase, but one might
 want to
 split this functionality into two methods for efficiency reasons.
 But I
 thought it'll be better, because one can change the MaxHeap to be a
 MaxHeap by changing the template alias parameter, but this wouldn't
 change the method names :-)

 The patch is against current svn trunk.

 [1]
 http://xammy.xammy.homelinux.net/files/BinaryHeap-PriorityQueue.patch

 A better primitive is to define update to take an index and a new
 value, such that user code does not need to deal simultaneously with
 the underlying array and the heap. No?
 Well, I thought of the case where you have an array of structs and use a
 custom less function for ordering. There you might not have a new value,
 i.e. a replaced struct, but just a minor change internally. But I see
 your idea, in most cases you would just call update after replacing your
 array entry... Could we provide both, maybe?

 Good point. Here's what I suggest:

 /**
   Applies unary function fun to the element at position index, after
 which moves that element to preserve the heap property. (It is assumed
 that fun changes the element.) Returns the new position of the element
 in the heap.

 Example:

 
 int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
 auto h = heapify(a);
 assert(equal(a, [ 16, 14, 10, 9, 8, 7, 4, 3, 2, 1 ]));
 h.update!a -= 5(1);
 assert(equal(a, [ 16, 10, 9, 9, 8, 7, 4, 3, 2, 1 ]));
 
 */
 size_t update(alias fun)(size_t index);

 Let me know of what you think, and thanks for contributing. When using
 unaryFun inside update, don't forget to pass true as the second
 argument to unaryFun to make sure you enact pass by reference.
Good idea. I like the interface!

Btw, can I then call a routine in the string, too? Like

h.update!a.updatePriority()(1);

Although this does look ugly, so separating the call would probably make
more sense.

Matthias


Re: Why Ruby?

2010-12-16 Thread Andrej Mitrovic
On 12/16/10, Stephan Soller stephan.sol...@helionweb.de wrote:
 snip

The cool thing about D is that with a little bit of string magic you
can make your own DSL's. Here's a rather hardcoded and superficial
example, but for this simple case it works:

http://pastebin.com/Xkghv1ky

Of course you'd need to build your own little DSL string parsing
functions and use regex instead of hardcoding it like that. But all
kinds of syntaxes are possible.


Re: Why Ruby?

2010-12-16 Thread piotrek
On Wed, 15 Dec 2010 17:13:48 -0500, Nick Sabalausky wrote:
 Feel free not to answer that though, I don't think
 either of us are feeling particularly inclined to end up in a heated
 debate about it today.

Yes, peace. I also understand you and agree that there's an issue with
overreactions. However I try to act somehow rationally  ;)

Cheers
Piotrek


Re: Fast string search

2010-12-16 Thread Leonid Volnitsky
bearophile Wrote:
 Look better at the code,

Oh, now I see.  Then this is not correct translation to D.   C++ returns 
correct results.   I've fixed bug, but not the one that you see.  You can 
verify this by running C++ version. 


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread CrypticMetaphor
I'm using Thunderbird, but it's pretty much the only newsreader I've 
ever had so can't really compare it with others. But I use the following 
extensions to improve my experience:


QuoteCollapse:
https://addons.mozilla.org/en-US/thunderbird/addon/347/

Not directly related with newsreading but still useful.
https://addons.mozilla.org/en-US/thunderbird/addon/12581/

I use other extensions as well but they are not newsreading related.


Re: A Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Craig Black
And here is why. Quicksort is quite famous for being O(n^2) worst case 
(for sorted data). Your straightforward, simple  (and less generic, I must 
say) implementation shines for random data, but performs terribly for 
ordered data. Phobos' sort isn't really plain quicksort so it is slower 
for random data (yet still of the same complexity as your code best case), 
but it is pretty fast for ordered data.


Quite right!  Phobos sort does a really good job with ordered data.  The 
simple algorithm doesn't...


-Craig 



Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-15 00:19, Graham St Jack wrote:



I don't know, do you have an example ?


For example taking a classname and a bunch of field types and names, and
turning it into a class definition complete with constructor from field
values, constructor from an input stream, a method to write to an output
stream, and const getters. Or maybe std.typecons.AutoImplement.


Could you post an example of how that mixin would be used and the code
it would generate then I can see if I can translate it to my syntax.
AutoImplement seems to just contain template mixins which is something
else.



I have attached my concurrency framework, which relies heavily on
mixins, plus its unit test to show how it is used. I haven't included
the various dependencies because I assume you just want the example
code. Let me know if you want something buildable, or perhaps something
more cut-down.

What the code-generating template does is to create from something like
this (you can have any number of Messages in a Protocol):


alias Protocol!(Requests, Message!(job, string, name)).code jobCode;
mixin(jobCode);


this code:


class Requests {
struct jobMsg {
string name;
this(string name) {
this.name = name;
}
void read(InStream stream) {
name = stream.get!string;
}
void write(OutStream stream) {
stream(name);
}
}
struct Message {
uint kind;
union {
jobMsg job;
}
this(ref jobMsg msg) {
kind = 0;
job = msg;
}
this(InStream stream) {
kind = stream.get!uint;
switch(kind) {
case 0: job.read(stream); break;
default: assert(0, Cannot read unsupported message kind);
}
}
void write(OutStream stream) {
stream(kind);
switch(kind) {
case 0: job.write(stream); break;
default: assert(0, Cannot write unsupported message kind);
}
}
}
private alias Channel!(Message) _Chan;
private alias shared _Chan Chan;

private Chan channel;
this() { channel = new Chan(); }
ChannelSelectable newSelectable() { return channel.newSelectable(); }
void finalize() { channel.finalize; }

interface IHandler {
void job(string name);
}
void job(string name) {
channel.add(Message(jobMsg(name)));
}
void receive(IHandler handler) {
auto message = channel.remove;
switch (message.kind) {
case 0: handler.job(message.job.name); break;
default: assert(0, Cannot dispatch unsupported message kind);
}
}
}



I use this for inter-thread communications, and I use the discriminated
union to pass messages between processes. The manual mixin after the
alias is a debugging aid - the compiler errors when doing mixins aren't
helpful at all. I case you are wondering why I did all this, it was
partly a learning experience, but mostly an attempt to do something
properly thread-safe (!hasAliasing), using shared, const and immutable
properly.


I've attached a part of how concurrency.d could look like translated to 
my suggested syntax. It probably contains a lot of errors because did a 
quick translation and I had some trouble understanding the mixins.


--
/Jacob Carlborg
void delegate () Paste (string name, string joiner)
{
return
{
static if (more)
enum @name = { _...@name @joiner Next.name; };

else
enum @name = { _...@name; };
}
}

private template MessageStrings(string msgName, T...) {
static assert(T.length  1, Message parameters must be in pairs);
enum more = T.length  2;
static if (more) {
alias MessageStrings!(msgName, T[2..$]) Next;
}
static if (T.length  0) {
static assert(!hasAliasing!(T[0]), Cannot use type  ~ T[0].stringof ~ 
 in a message);
static assert(is(typeof(T[1]) : string), Message parameters must be 
named);

enum _fieldStr = { @(T[0].stringof) @T[1]; };
enum _initStr = { th...@t[1] = @T[1]; }
enum _readStr = { @t[1] = stream.g...@t[0].stringof; }
enum _writeStr = { (@T[1]) };

enum _paramStr = { @(T[0].stringof) @T[1]; };
enum _nameStr = {�...@t[1]; };
enum _callStr = { messa...@msgname.@T[1]; };

@Paste(fieldStr, \n); // field types and names in 
definition
@Paste(initStr,  \n); // field assignments in 
constructor
@Paste(readStr,  \n); // fields read from an 
InStream
@Paste(writeStr, );   // fields written to an 
OutStream

@Paste(paramStr, , ); // field types and names, 
comma-separated
@Paste(nameStr,  , ); // field names, comma 
separated
@Paste(callStr,  , ); // field values accessed in 
an enclosing union, comma separated
}
}

void delegate () Messages (T...) (string name)
{
static assert(T.length  0, Messages have to contain fields);

alias name msgName;

alias MessageStrings!(name, T) strings;

return
{
struct @(name)Msg
{

Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-15 08:57, Don wrote:

Jacob Carlborg wrote:

On 2010-12-14 13:05, Don wrote:

Graham St Jack wrote:

On 14/12/10 20:33, Vladimir Panteleev wrote:

On Tue, 14 Dec 2010 09:30:46 +0200, Graham St Jack
graham.stj...@internode.on.net wrote:


There is of course the worry that it could get so easy that everyone
starts doing it, and we have (relatively) impenetrable code
everywhere
instead of just deep in the bowels of framework libraries.


TBH, I'm more excited by AST macros which I understood are planned for
D3, as mentioned here:
http://s3.amazonaws.com/dconf2007/WalterAndrei.pdf
They seem to promise the power of mixins, but without the mess.



I took a look at the pdf, but couldn't see how the AST macros could
come
close to the kinds of things that are possible (but difficult) with
mixins.


That fact was recognized at the conference, on the following day. As a
result, AST macros were dropped from D2.


Do you have an example that would work with string mixins but not with
AST macros?


Well, it's a bit hard without a formal definition of AST macros.
But the stuff I talked about at the conference, I have no idea how to do
with AST macros.

There's code like this, which generates an asm instruction.

--
mixin( opToSSE[operations[done+1]] ~ suffix ~   ~ XMM(numOnStack-1) ~
,  ~ indexedSSEVector(ranklist, operations[done], vectorsize));
---

using the functions:

const char [][5] vectorRegister = [ECX, EDX, EBX, ESI, EDI];

char [] indexedSSEVector(char [] ranklist, char var, char [] vecsize)
{
return [ ~ vectorRegister[vectorNum(ranklist, var)] ~  +  ~ vecsize
~*EAX];
}

char [] XMM(int k) { return XMM~ itoa(k); }

char [][char] opToSSE() {
return ['*':mulp[], '+': addp, '-': subp, '/': divp]; }

int vectorNum(char [] ranklist, char var)
{
int numVecs=0;
for (int i=0; ivar-'A'; ++i) {
if (ranklist[i]=='1') ++numVecs;
}
return numVecs;
}



I can't quite visualize how the final code will look like and as you say 
it's hard without a formal definition of AST macros. But I think somehow 
it would be possible, I mean instead of combining strings one combine 
expressions/syntax. But I don't know if it would be possible to combine 
incomplete expressions.



They need to roughly match string mixins in power. At this stage, there
is no proposal for how they should work.


I think someone, Nick Sabalausky perhaps, suggested to have something
like the hygiene macros in Nemerle:
http://nemerle.org/wiki/index.php?title=Macros


 From an implementation point of view, the differences between Nemerle
macros and string mixins are mostly syntactic.
The one thing about them that I find really impressive is the IDE
integration, especially that they got syntax highlighting to work. I
don't know they've done that.


As far as I can see the content of a macro in Nemerle is just code. But 
if you're referring to the syntax expression/statement which adds new 
syntax to the language then I agree.


--
/Jacob Carlborg


Re: Why Ruby?

2010-12-16 Thread Jacob Carlborg

On 2010-12-15 17:06, Stephan Soller wrote:

On 14.12.2010 20:03, Jacob Carlborg wrote:

On 2010-12-14 19:33, Stephan Soller wrote:


I think it's a matter of consistency. In Ruby blocks are used all the
time for pretty much everything. In D this isn't the case because
usually templates are used for stuff where blocks are used in Ruby
(e.g.
map, group and find in std.algorithm).


I think that the templates that take a string as a predicate is just an
ugly hack because D has a too verbose delegate syntax.



I absolutely agree with that. However I don't have a better idea how to
write it. Delegate syntax is already fairly compact in D.

For example code as this isn't very uncommon in Ruby:

[1, 2, 3, 4, 5].select{|e| e  3}.collect{|e| e*e}

Of course this is a simplified example. Usually the collection would
contain some objects and the blocks would filter for a method call (like
e.even?). However I built a small D1 struct that implements a select
and collect function. With the unified function call synatax for array
with code should actually work:

[1, 2, 3, 4, 5].select((int e){ return e  3; })
.collect((int e){ return e*e; });

It's already fairly compact. The main overhead is the parameter type and
the return statement. I don't believe this can be reduced any more
without breaking consistency of the language.


Probably not, but, for example, Scala allows very compact delegate
literals:

Array(1, 2, 3, 4, 5).select(_  3).collect(_ * _)

Or more verbose:

Array(1, 2, 3, 4, 5).select((x) = x  3).collect((x, y) = x * y)

I'm not 100% sure I that the syntax is correct.


Delegates are way more verbose in other languages like PHP and
JavaScript (more or less the same syntax in both languages). Despite
that it's no problem to use it and in case of jQuery it's used very
often. I think the main reason why delegates are not used like that in D
is performance. I'm really not sure about it but I suspect that
delegates are less effective than code directly generated by a template
like map!(). I don't know how efficient templates can integrate
delegates so I just suspect that this is a performance problem.

Happy programming
Stephan Soller


PHP has a very verbose delegate syntax with explicit closures, one of
the many reasons I don't use PHP. JavaScript has quite similar syntax as
D but the function keyword is required, I try to use CoffeeScript
(compiles to javascript), which has a lot nicer delegate syntax, as
often I can.

D(dmd) needs to be able to inline delegates.



I'm not so much concerned about verbose delegate syntax. Personally I
don't mind using the current delegate syntax with templates like map!.
However I'm concerned about performance and parameter order. Does
someone know how delegates within templates are handled? I looked at the
source of std.algorithm and std.functional but I'm still not sure what
actually happens if you call something like

auto ary = [1, 2, 3];
map!((e){ return e*e; })(ary);

I can't test this code right now since I don't have a D2 compiler
installed at this computer but the std.algorithm source contains unit
tests with delegates.

If that now works with uniform function call syntax it could be written
like that:

auto ary = [1, 2, 3];
ary.map!((e){ return e*e; });

I don't know if chaining of such calls is possible but the above syntax
is already pretty good. Sure, it's not perfect and the return still is
some overhead, but I don't think it needs work. What's more important
(at least for me) is the chaining ability and how performant such
delegates actually are. From what I understood from std.functional it
wraps string expressions in delegates anyway so using

ary.map!(a*a);

is not more efficient. Please correct me if I'm wrong! The
std.functional code is definitely above my understanding.


I would though it just mixed in the string with some other code to make 
a complete expression.



So, _if_ we can figure out a way to do some nice chaining of such calls
we can get:

[1, 2, 3, 4, 5].filter!((e){ return e  3; })
.map!((e){ return e*e; });

Or if you don't like delegates and don't mind obvious compile time black
magic:

[1, 2, 3, 4, 5].filter!(a  3).map!(a * a);

I think if chaining would work like that D would already be pretty close
to the expressive power of Ruby. It's just that this kind of programming
is very dependent on the ability of built in collections and libraries
that allow such a programming style.

Happy programming
Stephan Soller


--
/Jacob Carlborg


Re: Binary heap method to update an entry.

2010-12-16 Thread Andrei Alexandrescu

On 12/16/10 10:06 AM, Matthias Walter wrote:

On 12/16/2010 10:53 AM, Andrei Alexandrescu wrote:

On 12/16/10 7:55 AM, Matthias Walter wrote:

On 12/16/2010 04:17 AM, Andrei Alexandrescu wrote:

On 12/15/10 10:21 PM, Matthias Walter wrote:

Hi all,

I uploaded [1] a patch for std.container to use BinaryHeap as a
priority
queue. For the latter one it is often necessary to change a value
(often
called decreaseKey in a MinHeap). For example, Dijkstra's shortest
path
algorithm would need such a method. My implementation expects that the
user calls the update method after changing the entry in the
underlying store.

My method works for value-decrease and -increase, but one might
want to
split this functionality into two methods for efficiency reasons.
But I
thought it'll be better, because one can change the MaxHeap to be a
MaxHeap by changing the template alias parameter, but this wouldn't
change the method names :-)

The patch is against current svn trunk.

[1]
http://xammy.xammy.homelinux.net/files/BinaryHeap-PriorityQueue.patch


A better primitive is to define update to take an index and a new
value, such that user code does not need to deal simultaneously with
the underlying array and the heap. No?

Well, I thought of the case where you have an array of structs and use a
custom less function for ordering. There you might not have a new value,
i.e. a replaced struct, but just a minor change internally. But I see
your idea, in most cases you would just call update after replacing your
array entry... Could we provide both, maybe?


Good point. Here's what I suggest:

/**
   Applies unary function fun to the element at position index, after
which moves that element to preserve the heap property. (It is assumed
that fun changes the element.) Returns the new position of the element
in the heap.

Example:


int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
auto h = heapify(a);
assert(equal(a, [ 16, 14, 10, 9, 8, 7, 4, 3, 2, 1 ]));
h.update!a -= 5(1);
assert(equal(a, [ 16, 10, 9, 9, 8, 7, 4, 3, 2, 1 ]));

*/
size_t update(alias fun)(size_t index);

Let me know of what you think, and thanks for contributing. When using
unaryFun inside update, don't forget to pass true as the second
argument to unaryFun to make sure you enact pass by reference.

Good idea. I like the interface!

Btw, can I then call a routine in the string, too? Like

h.update!a.updatePriority()(1);

Although this does look ugly, so separating the call would probably make
more sense.


That would work, and if you find the string unpalatable, use a real lambda:

h.update!((a) { a.updatePriority(); })(1);


Andrei


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Nick Sabalausky
Justin Johansson nore...@jj.com wrote in message 
news:ied4th$2vn...@digitalmars.com...
 Just wondering how others rate Thunderbird as a decent newsreader.

 My experience with Thunderbird is that it is not of a standard of 
 distinction that one would hope for in 2010 coming 2011.

 For one thing, and perhaps this is a newsgroup server problem, but I doubt 
 it, my Thunderbird client shows a number of D NG topics as being unread 
 though the folder tree item for d.D shows all items as read.

 Aside from that issue, my experience with Thunderbird is that it is not 
 particularly innovative in drawing my attention to the high-traffic topics 
 apart from telling me that one-or-more responses are unread (as opposed to 
 popular topics for example).

 Overall I think Thunderbird is a bit lame as a newsreader for this day and 
 age, and, though it owes me nothing and I paid nothing for it, I do wonder 
 what others think of their NG experience using Mozilla Thunderbird.


FWIW: I tried Thunderbird breifly a few years ago. It seemed to get the job 
done, but there were a number of little annoyances that left me going back 
to Outlook Express. Let's see if I can remember some of them...(and again, 
like I said, little annoyances, so obviously these aren't super-major 
issues or anything):

- When using view messages in plain-text (which I always use), it still 
converts *this* into bold (and removes the asterisks), /this/ into italic 
(and removes the slashes), and _this_ into underline (and removes the 
underscores). This really, really bugged me, but unfortunately there didn't 
seem to be a way to turn it off - despite the fact that it was supposedly 
plain-text mode.

- Many UI elements seemed to be rather big-n-chunky. Almost like a GTK app, 
although not quite as bad.

- There was a lot of invisi-text on my light-on-dark system. I seem to 
recall that it *was* possible to fix this, but it required manually hacking 
some obscure configuration files.

- I seem to have a vague recollection that the UI became unresponsive while 
it was downloading emails, but I may very well be completely wrong about 
that. I think there was *something* weird about when it downloaded emails...

I think there were some other little annoyances along similar lines, but I 
can't remember what they were. Granted, Outlook Express certainly has it's 
little annoyances too (a few people's NG messages show up as blank messages 
with the actual text in a text-file attachment, auto-quoting when replying 
doesn't always happen, and what I'm assuming are long GC collection cycles, 
and a few other things), but I found OE's annoyances to overall be somewhat 
less annoying than Thunderbird's.





Re: emscripten

2010-12-16 Thread Nick Sabalausky
Adam Ruppe destructiona...@gmail.com wrote in message 
news:ied469$2qg...@digitalmars.com...

 Thankfully, the popular Re-Captcha ones are among the
 easiest to read, but that doesn't help when someone still uses
 the green on red with purple stripes and tiny font variety.


Re-Captcha also doen't help when JS is off. ( Actually, that's the only 
reason I use TangoCMS's default captcha instead of Re-Captcha on my 
bitch-and-whine site (I'm irrationally not calling it a blog): 
https://www.semitwist.com/articles ) 




Re: emscripten

2010-12-16 Thread Nick Sabalausky
Michael Stover michael.r.sto...@gmail.com wrote in message 
news:mailman.1053.1292506694.21107.digitalmar...@puremagic.com...

 And CAPTCHAs prove that javascript and browsers are terrible???


Where are you gettng that? That's not even remotely what he said. He was 
clearly saying that CAPTCHAs and registration are a counter-argument to the 
notion that most webapps are zero-config. Or at least that they're not 
really much better than having to do some basic config.




Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-15 23:00, Nick Sabalausky wrote:

Jonathan M Davisjmdavisp...@gmx.com  wrote in message
news:mailman.1035.1292441722.21107.digitalmar...@puremagic.com...

On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:


That was my idea as well, that

@get_set(int, bar);

could be translated into

mixin(get_set(int, bar)); just like

just like scope statements are translated into try/catch/finally.


Honestly, I don't see much gain in using @ rather than mixin(). It's a
little
less typing, but that's it.


It does seem like a small difference, just replacing mixin with @ and
removing one layer of parens. But I think that extra layer of parens, minor
as it seems, makes a big difference in the readability (and typeability)
of mixin invocations. Those extra parens do get to be a real bother, major
visual noise at least to my eyes.


^^ I completely agree.


And it precludes stuff like mixin(lhs  ~ op ~ 
rhs) like happens all the time in overloaded operator functions.



I don't see why these shouldn't work:

@int foo;;
return @(lhs  ~ op ~  rhs);

At least with just the @ part of the proposal. Maybe the delegate thing
might make it tricker, I dunno.


My idea was actually to get rid of the strings where the code to be 
mixed in is defined and to have a better syntax where it's used.


The delegates are just a way of passing a block of code around. If you 
just use it in place then maybe one could do like this:


@(int foo;);
return @(lhs@(op)rhs);

--
/Jacob Carlborg


Re: Why Ruby?

2010-12-16 Thread Jacob Carlborg

On 2010-12-15 23:33, Andrei Alexandrescu wrote:

On 12/15/10 4:18 PM, retard wrote:

Wed, 15 Dec 2010 22:23:35 +0100, Jacob Carlborg wrote:

Array(1, 2, 3, 4, 5).sortWith(_ _)


The first instance of _ (from left to right) is replaced with the first
element of the parameter tuple, the second with second element, etc.

This is actually very useful since many lambdas only use 1-2 parameters.
It has its limitations. For example referring to the same parameter
requires a named parameter or some other hack. Combined with Haskell
style partial application this allows stuff like:

Array(1, 2, 3, 4, 5).foreach { println }

Array(1, 2, 3, 4, 5).filter(2)


For short lambdas I prefer Phobos' convention of using a and b, e.g.
2  a or a  b. Since it's a string, _  _ would have been usable
with Phobos too but I wouldn't like such a change.

Andrei


The point here isn't that we want a and b to be replaced with _ 
the point is that we want to get rid of the string and have a shorter 
and less verbose syntax for delegate literals.


--
/Jacob Carlborg


Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-16 11:18, Pelle Månsson wrote:

On 12/15/2010 11:00 PM, Nick Sabalausky wrote:

Jonathan M Davisjmdavisp...@gmx.com wrote in message
news:mailman.1035.1292441722.21107.digitalmar...@puremagic.com...

On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:


That was my idea as well, that

@get_set(int, bar);

could be translated into

mixin(get_set(int, bar)); just like

just like scope statements are translated into try/catch/finally.


Honestly, I don't see much gain in using @ rather than mixin(). It's a
little
less typing, but that's it.


It does seem like a small difference, just replacing mixin with @ and
removing one layer of parens. But I think that extra layer of parens,
minor
as it seems, makes a big difference in the readability (and
typeability)
of mixin invocations. Those extra parens do get to be a real bother,
major
visual noise at least to my eyes.



I agree with this. Actually, just removing the parenthesis would be a
huge gain for me.


And it precludes stuff like mixin(lhs  ~ op ~ 
rhs) like happens all the time in overloaded operator functions.



I don't see why these shouldn't work:

@int foo;;
return @(lhs  ~ op ~  rhs);

At least with just the @ part of the proposal. Maybe the delegate thing
might make it tricker, I dunno.



This could work, but I don't think anyone is suggesting completely
replacing the mixin. I think @ could be a function/template thing, and
have strings in a more explicit mixin;

Then again, inconsistency sucks.


The whole point of the idea/suggestion was to get rid of the strings. 
Then if the syntax I've suggested is translated into the string mixin 
syntax we have now then I would be fine with that.


--
/Jacob Carlborg


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Gour
On Fri, 17 Dec 2010 00:39:15 +1100
 Justin == Justin Johansson wrote:

Justin Just wondering how others rate Thunderbird as a decent
Justin newsreader.

I use Claws-mail as mailer, news reader, rss reader...and I'm more
than happy with it.


Sincerely,
Gour

-- 

Gour  | Hlapicina, Croatia  | GPG key: CDBF17CA



signature.asc
Description: PGP signature


Re: emscripten

2010-12-16 Thread retard
Thu, 16 Dec 2010 14:22:01 -0500, Nick Sabalausky wrote:

 Michael Stover michael.r.sto...@gmail.com wrote in message
 news:mailman.1053.1292506694.21107.digitalmar...@puremagic.com...

 And CAPTCHAs prove that javascript and browsers are terrible???


 Where are you gettng that? That's not even remotely what he said. He was
 clearly saying that CAPTCHAs and registration are a counter-argument to
 the notion that most webapps are zero-config. Or at least that they're
 not really much better than having to do some basic config.

This guy is trolling here. Any sane person would have already given up. 
This discussion is more or less useless.


Re: emscripten

2010-12-16 Thread Nick Sabalausky
Adam Chandler a...@paradise.com wrote in message 
news:iecv7f$1n1...@digitalmars.com...
 Michael Stover Wrote:

  there's no integration with the
 external environment

 But it is an advantage at the same time as it's a weakness.  The 
 advantage
 is, I can read and use gmail or google docs anywhere, firewall or not.

 I could sit here at home, open an openoffice doc, write in it, save it.
  Then tomorrow go to work, open open office and bitch and scream about 
 why
 the doc I made last night at home isn't in my recent docs list!! ZOMG!!! 
 I
 *LOATHE* Open Office!  I can't do the simplest thing!  But, no, I 
 recognize
 the limitations of the different mediums, and rather than look at what is
 not exactly the same as what I'm used to, I can see what it does that 
 I've
 not been able to do before.  If you'd asked me 1 year ago about 
 javascript,
 I would have laughed and said no way I would want to use that crap.  I've
 learned to think otherwise since.

 If you go looking for problems, you're going to find them.  To me, it 
 simply
 indicates inflexibility on your part.  Which is fine, like I said, the 
 world
 doesn't care about your inability to adapt and see new possibilities.

 It's just, the strength of the emotional response in this thread has been
 kind of revealing.

 Dear Mike, you're one of the most annoying wankers I've seen. Go f** 
 yourself or even better, go kill yourself. TYVM let us have a nice day.

Dear Adam, even though your post is technically trolling and I'm normally a 
don't feed the trolls kinda guy, I gotta say: HAVE THIS FRESH-BAKED BATCH 
OF COOKIES! Chocolate-chip! Macaroons! Whatever you want!

I'm amazed at how much Michael's been taking things the wrong way in this 
thread. Almost sounds like my mother: You say just about anything and they 
zero-in on one insignificant detail and blow it entirely out of proportion 
while completely misinterpreting it anyway.




Re: emscripten

2010-12-16 Thread Nick Sabalausky
Michael Stover michael.r.sto...@gmail.com wrote in message 
news:mailman.1046.1292468790.21107.digitalmar...@puremagic.com...
 there's no integration with the
 external environment

 But it is an advantage at the same time as it's a weakness.  The advantage
 is, I can read and use gmail or google docs anywhere, firewall or not.


That's entirely possible without cramming the whole thing through a webpage. 
I can thank of at least a couple ways just off the top of my head. The 
*only* reason you don't see outside of the web browser it is because 
everyone making use-anywhere apps is insisting doing it through the web 
browser. It's *not* a technical limitation of not using a web browser. If 
anything, it's just a widespread misconception amoung people who grew up 
writing web code and therefore don't know any better about what is and isn't 
possible.




Re: Why Ruby?

2010-12-16 Thread Andrei Alexandrescu

On 12/16/10 1:30 PM, Jacob Carlborg wrote:

On 2010-12-15 23:33, Andrei Alexandrescu wrote:

On 12/15/10 4:18 PM, retard wrote:

Wed, 15 Dec 2010 22:23:35 +0100, Jacob Carlborg wrote:

Array(1, 2, 3, 4, 5).sortWith(_ _)


The first instance of _ (from left to right) is replaced with the first
element of the parameter tuple, the second with second element, etc.

This is actually very useful since many lambdas only use 1-2 parameters.
It has its limitations. For example referring to the same parameter
requires a named parameter or some other hack. Combined with Haskell
style partial application this allows stuff like:

Array(1, 2, 3, 4, 5).foreach { println }

Array(1, 2, 3, 4, 5).filter(2)


For short lambdas I prefer Phobos' convention of using a and b, e.g.
2  a or a  b. Since it's a string, _  _ would have been usable
with Phobos too but I wouldn't like such a change.

Andrei


The point here isn't that we want a and b to be replaced with _
the point is that we want to get rid of the string and have a shorter
and less verbose syntax for delegate literals.


I understand. Using strings is witnessing the fact that we couldn't find 
a shorter syntax that didn't have problems. That being said, it's very 
possible there are some great ones, we just couldn't find them.


Andrei


Re: emscripten

2010-12-16 Thread Nick Sabalausky
Nick Sabalausky a...@a.a wrote in message 
news:iedqh5$6q...@digitalmars.com...
 Michael Stover michael.r.sto...@gmail.com wrote in message 
 news:mailman.1046.1292468790.21107.digitalmar...@puremagic.com...
 there's no integration with the
 external environment

 But it is an advantage at the same time as it's a weakness.  The 
 advantage
 is, I can read and use gmail or google docs anywhere, firewall or not.


Slight wording correction added in-line:

 That's entirely possible without cramming the whole thing through a 
 webpage. I can thank of at least a couple ways just off the top of my 
 head. The *only* reason you don't see
 [the access-your-data-from-anywhere ability]
 outside of the web browser it is because everyone making use-anywhere 
 apps is insisting doing it through the web browser. It's *not* a technical 
 limitation of not using a web browser. If anything, it's just a widespread 
 misconception amoung people who grew up writing web code and therefore 
 don't know any better about what is and isn't possible.

 




Re: emscripten

2010-12-16 Thread Nick Sabalausky
Jeff Nowakowski j...@dilacero.org wrote in message 
news:ied4mg$2u7...@digitalmars.com...
 On 12/15/2010 04:31 PM, Nick Sabalausky wrote:

 But if you're going to make, say, a mortgage rate calculator,
 excluding Lynx or requiring JS makes absolutely no sense whatsoever.

 This is actually a good example of why you might require JavaScript. Here, 
 JavaScript is useful to the end user because it doesn't require a request 
 and response to the server, so everything is faster and smoother.


That makes no sense, given that it's entirely possible to for the JS to be 
optional. A mortgage rate calculator would be a good example of why you 
might toss in *optional* JS to streamline things, but to require it? 
Ridiculous.

 Supporting both JavaScript and plain HTML takes extra work for little 
 benefit, since the vast majority of users have it enabled.

I do make my pages usable both ways and I've found the extra effort to be 
downright minimal. Unless you're doing things very, very, very wrong, the 
vast majority of the work in a site is independent of JS vs non-JS.


 It's not 1995 anymore.

What's that line about those who refuse to learn from history?

And besides, no one's ever going to get me to agree with something simply by 
trying to shame me into it with some idiotic newer-is-inherently-better, 
Oh no! I don't want to be un-trendy!! line of dumbass sheep-think.





Re: [OT] Mozilla Thunderbird

2010-12-16 Thread sybrandy
I personally like it a lot, though I haven't tried any other news 
readers on Linux.  I think the biggest reason I like it is the fact that 
it's the same regardless of what platform it's on and I also like the 
arrangement of the windows.


Overall, I've been quite happy with it.

Casey


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Justin Johansson

On 17/12/10 06:34, Gour wrote:

On Fri, 17 Dec 2010 00:39:15 +1100

Justin == Justin Johansson wrote:


Justin  Just wondering how others rate Thunderbird as a decent
Justin  newsreader.

I use Claws-mail as mailer, news reader, rss reader...and I'm more
than happy with it.


Sincerely,
Gour


Thanks Gour and others for comments.

Just been to the website.  Reckon I'll try out Claws Mail and perhaps 
any other Linux clients that folks here recommend.


Cheers
Justin




Re: New syntax for string mixins

2010-12-16 Thread Nick Sabalausky
Jacob Carlborg d...@me.com wrote in message 
news:iednio$2vj...@digitalmars.com...

 I can't quite visualize how the final code will look like and as you say 
 it's hard without a formal definition of AST macros. But I think somehow 
 it would be possible, I mean instead of combining strings one combine 
 expressions/syntax. But I don't know if it would be possible to combine 
 incomplete expressions.


One parallel that may or may not be applicable, but might be worth 
considering, is dynamically building XHTML: Using a string-template system 
is generally found to work very well, but building it via a DOM (essentially 
an AST) is often considered a bit of a pain. I guess the simplest take-away 
would be that string-based approaches may be easier get working well. FWIW.




Re: [OT] Mozilla Thunderbird

2010-12-16 Thread piotrek
On Thu, 16 Dec 2010 15:06:20 -0500, sybrandy wrote:

 I personally like it a lot, though I haven't tried any other news
 readers on Linux.  I think the biggest reason I like it is the fact that
 it's the same regardless of what platform it's on and I also like the
 arrangement of the windows.
 
 Overall, I've been quite happy with it.
 
 Casey

You can try Pan some day. I prefer it to Thunderbird (it's really nice - in two 
words).

Cheers
Piotrek


Re: New syntax for string mixins

2010-12-16 Thread Nick Sabalausky
Jacob Carlborg d...@me.com wrote in message 
news:iedpbg$3i...@digitalmars.com...
 On 2010-12-15 23:00, Nick Sabalausky wrote:

 I don't see why these shouldn't work:

 @int foo;;
 return @(lhs  ~ op ~  rhs);

 At least with just the @ part of the proposal. Maybe the delegate thing
 might make it tricker, I dunno.

 My idea was actually to get rid of the strings where the code to be mixed 
 in is defined and to have a better syntax where it's used.

 The delegates are just a way of passing a block of code around. If you 
 just use it in place then maybe one could do like this:

 @(int foo;);
 return @(lhs@(op)rhs);


Yea, my point was just that the @... stuff could work either way, with the 
string-based system or with your delegate-based one.

I don't mean to come across like I'm ignoring or against the idea of the 
whole delegate aspect, and I understand that the main point of the OP is to 
replace the strings with delegates, but with the q{...} syntax and 
string-templating, I'm still struggling to see a big enough benefit compared 
to the status quo. I see that using delegates instead of strings could 
probably be made to work, but my questions are For what benefit(s)? and 
Would those benefits be sufficient to warrant the change? I'm not 
necessarily saying the answer is no, but I'm unconvinced so far.

And here's another thing: Suppose we got a Ruby/PHP-like syntax for 
embedding code substitutions directly into a string (which would have other 
useful applications besides mixins):

auto name = Joe;
auto msg = hello #{name}, whaddup?;
mixin( q{ int #{name} = 7; } );
Joe++;

Would that eliminate much (or all) of the benefit of the delegate approach?




Re: emscripten

2010-12-16 Thread Michael Stover
On Thu, Dec 16, 2010 at 2:22 PM, Nick Sabalausky a...@a.a wrote:

 Michael Stover michael.r.sto...@gmail.com wrote in message
 news:mailman.1053.1292506694.21107.digitalmar...@puremagic.com...
 
  And CAPTCHAs prove that javascript and browsers are terrible???
 

 Where are you gettng that? That's not even remotely what he said. He was
 clearly saying that CAPTCHAs and registration are a counter-argument to the
 notion that most webapps are zero-config. Or at least that they're not
 really much better than having to do some basic config.

 The conversation was about technologies, not specific webapps. The
emotional outburst that began this aspect of the discussion was that
javascript sucks, period, end of story, without any possibility of ever
being otherwise.  CAPTCHAs are irrelevant.


Re: emscripten

2010-12-16 Thread Michael Stover
On Thu, Dec 16, 2010 at 2:48 PM, Nick Sabalausky a...@a.a wrote:

 Michael Stover michael.r.sto...@gmail.com wrote in message
 news:mailman.1046.1292468790.21107.digitalmar...@puremagic.com...
  there's no integration with the
  external environment
 
  But it is an advantage at the same time as it's a weakness.  The
 advantage
  is, I can read and use gmail or google docs anywhere, firewall or not.
 

 That's entirely possible without cramming the whole thing through a
 webpage.
 I can thank of at least a couple ways just off the top of my head. The
 *only* reason you don't see outside of the web browser it is because
 everyone making use-anywhere apps is insisting doing it through the web
 browser. It's *not* a technical limitation of not using a web browser. If
 anything, it's just a widespread misconception amoung people who grew up
 writing web code and therefore don't know any better about what is and
 isn't
 possible.


What's possible and what's reasonable to two are different things.  Clearly,
implementors and users are converging on the idea that browsers are the
easiest way to do this.  You can do it other ways, go ahead.  You think
you'll get widespread adoption?

 You can argue against javascript and browsers, sure, but I'm not sure why
you feel it's productive to be so insulting about it.


Does Phobos have thread pool class?

2010-12-16 Thread Craig Black

I don't see a thread pool anywhere.  Am I overlooking something?

-Craig


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Steven Schveighoffer
On Thu, 16 Dec 2010 08:39:15 -0500, Justin Johansson nore...@jj.com  
wrote:



Just wondering how others rate Thunderbird as a decent newsreader.

My experience with Thunderbird is that it is not of a standard of  
distinction that one would hope for in 2010 coming 2011.


For one thing, and perhaps this is a newsgroup server problem, but I  
doubt it, my Thunderbird client shows a number of D NG topics as being  
unread though the folder tree item for d.D shows all items as read.


Aside from that issue, my experience with Thunderbird is that it is not  
particularly innovative in drawing my attention to the high-traffic  
topics apart from telling me that one-or-more responses are unread (as  
opposed to popular topics for example).


Overall I think Thunderbird is a bit lame as a newsreader for this day  
and age, and, though it owes me nothing and I paid nothing for it, I do  
wonder what others think of their NG experience using Mozilla  
Thunderbird.


I tried the following newsreaders:

Outlook Express
Evolution
Thunderbird
Pan
Opera

Many of these systems had problems/features that I didn't like.  So far,  
Opera has been the best fit for me.  The only thing that annoys me about  
it is that my preferred browser is firefox, but it will only ever use  
itself to open links.


-Steve


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Andrej Mitrovic
VIM users should be pretty psyched about this thing:

http://danielchoi.com/software/vmail.html

Although it doesn't seem to work for Windows yet so I haven't tested
it myself. :/

On 12/16/10, piotrek star...@tlen.pl wrote:
 On Thu, 16 Dec 2010 15:06:20 -0500, sybrandy wrote:

 I personally like it a lot, though I haven't tried any other news
 readers on Linux.  I think the biggest reason I like it is the fact that
 it's the same regardless of what platform it's on and I also like the
 arrangement of the windows.

 Overall, I've been quite happy with it.

 Casey

 You can try Pan some day. I prefer it to Thunderbird (it's really nice - in
 two words).

 Cheers
 Piotrek



Re: Does Phobos have thread pool class?

2010-12-16 Thread Sean Kelly
Craig Black Wrote:

 I don't see a thread pool anywhere.  Am I overlooking something?

I believe there will be one in std.parallelism once it's accepted.


Re: New syntax for string mixins

2010-12-16 Thread Jonathan M Davis
On Thursday, December 16, 2010 11:28:03 Jacob Carlborg wrote:
 On 2010-12-15 23:00, Nick Sabalausky wrote:
  Jonathan M Davisjmdavisp...@gmx.com  wrote in message
  news:mailman.1035.1292441722.21107.digitalmar...@puremagic.com...
  
  On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:
  That was my idea as well, that
  
  @get_set(int, bar);
  
  could be translated into
  
  mixin(get_set(int, bar)); just like
  
  just like scope statements are translated into try/catch/finally.
  
  Honestly, I don't see much gain in using @ rather than mixin(). It's a
  little
  less typing, but that's it.
  
  It does seem like a small difference, just replacing mixin with @ and
  removing one layer of parens. But I think that extra layer of parens,
  minor as it seems, makes a big difference in the readability (and
  typeability) of mixin invocations. Those extra parens do get to be a
  real bother, major visual noise at least to my eyes.
 
 ^^ I completely agree.
 
  And it precludes stuff like mixin(lhs  ~ op ~ 
  rhs) like happens all the time in overloaded operator functions.
  
  I don't see why these shouldn't work:
  
  @int foo;;
  return @(lhs  ~ op ~  rhs);
  
  At least with just the @ part of the proposal. Maybe the delegate thing
  might make it tricker, I dunno.
 
 My idea was actually to get rid of the strings where the code to be
 mixed in is defined and to have a better syntax where it's used.
 
 The delegates are just a way of passing a block of code around. If you
 just use it in place then maybe one could do like this:
 
 @(int foo;);
 return @(lhs@(op)rhs);

I would have thought that template mixins would be the thing to use when you 
didn't want to deal with strings. string mixins are extremely powerful and 
flexible, and I'd really hate to lose them. And IIRC, Kenji Hara was working on 
a 
module to really help make dealing with complicated string mixins easier and 
less painful. Anything that you propose is going to have to have major benefits 
over the current string mixin situation for it to stand any chance of being 
accepted.

- Jonathan M Davis


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Lars T. Kyllingstad
On Thu, 16 Dec 2010 22:11:15 +0100, Andrej Mitrovic wrote:

 VIM users should be pretty psyched about this thing:
 
 http://danielchoi.com/software/vmail.html

That looks pretty cool!  But for some reason the web page calls it an 
interface to GMail, even though it seems to use IMAP.  Can anyone think 
of a reason why it shouldn't work with other IMAP servers?

-Lars


Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-16 21:13, Nick Sabalausky wrote:

Jacob Carlborgd...@me.com  wrote in message
news:iednio$2vj...@digitalmars.com...


I can't quite visualize how the final code will look like and as you say
it's hard without a formal definition of AST macros. But I think somehow
it would be possible, I mean instead of combining strings one combine
expressions/syntax. But I don't know if it would be possible to combine
incomplete expressions.



One parallel that may or may not be applicable, but might be worth
considering, is dynamically building XHTML: Using a string-template system
is generally found to work very well, but building it via a DOM (essentially
an AST) is often considered a bit of a pain. I guess the simplest take-away
would be that string-based approaches may be easier get working well. FWIW.


I the case of XML I think it can be quite easy if you use the right 
libraries/tools. I think the easiest library I've used for building XML 
files is the Ruby library Bulilder, a code example using Builder can 
look like this:


xml = Builder::XmlMarkup.new

xml.person do
xml.first_name John
xml.last_name Doe
xml.phone 5484654, :type = mobile
end

Which will generate this:

person
first_nameJohn/first_name
last_nameDoe/last_name
phone type=mobile5484654/phone
/person

Now I don't think that this library is a DOM library, which allows you 
to manipulate a DOM tree, it's something simpler that just generates XML.


Link: http://builder.rubyforge.org/

--
/Jacob Carlborg


Re: Why Ruby?

2010-12-16 Thread Alex_Dovhal

Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
 The cool thing about D is that with a little bit of string magic you
 can make your own DSL's. Here's a rather hardcoded and superficial
 example, but for this simple case it works:

 http://pastebin.com/Xkghv1ky

 Of course you'd need to build your own little DSL string parsing
 functions and use regex instead of hardcoding it like that. But all
 kinds of syntaxes are possible.

You are right. I tried making one. It parses things like sum !(q{  i=0:10; 
i * sum!(q{   j=0:10, j!=i;i*j   })  })
http://pastebin.com/mQaKXaYY -
But it doesn't work because not being CTFE friendly, and also syntax parser 
is ugly because I am not strong at syntax parsing.
Note that creating good syntax parser in CTFE is rather hard, especially for 
complex syntaxes like of D expressions.
Oh, if CTFE could:
 1) run external process
 2) do file i/o
 3) use dynamic libraries
This would be much much simpler, but I guess it will not.
This features also has safety issues, but D is system language, not browser 
one. 




Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-16 21:35, Nick Sabalausky wrote:

Jacob Carlborgd...@me.com  wrote in message
news:iedpbg$3i...@digitalmars.com...

On 2010-12-15 23:00, Nick Sabalausky wrote:


I don't see why these shouldn't work:

@int foo;;
return @(lhs  ~ op ~  rhs);

At least with just the @ part of the proposal. Maybe the delegate thing
might make it tricker, I dunno.


My idea was actually to get rid of the strings where the code to be mixed
in is defined and to have a better syntax where it's used.

The delegates are just a way of passing a block of code around. If you
just use it in place then maybe one could do like this:

@(int foo;);
return @(lhs@(op)rhs);



Yea, my point was just that the @... stuff could work either way, with the
string-based system or with your delegate-based one.

I don't mean to come across like I'm ignoring or against the idea of the
whole delegate aspect, and I understand that the main point of the OP is to
replace the strings with delegates, but with the q{...} syntax and
string-templating, I'm still struggling to see a big enough benefit compared
to the status quo. I see that using delegates instead of strings could
probably be made to work, but my questions are For what benefit(s)? and
Would those benefits be sufficient to warrant the change? I'm not
necessarily saying the answer is no, but I'm unconvinced so far.

And here's another thing: Suppose we got a Ruby/PHP-like syntax for
embedding code substitutions directly into a string (which would have other
useful applications besides mixins):

auto name = Joe;
auto msg = hello #{name}, whaddup?;
mixin( q{ int #{name} = 7; } );
Joe++;

Would that eliminate much (or all) of the benefit of the delegate approach?


I guess using q{...} with string interpolation is very similar to the 
delegate approach. It just feels wrong passing around strings to 
represent code. I haven't though much about it but with delegates one 
could at lest hope for better help from the compiler validating the 
code. I don't know how IDEs will treat q{...} but with delegates you 
would get the full benefit of the IDE like autocompletion and similar 
features.


--
/Jacob Carlborg


Re: Why Ruby?

2010-12-16 Thread Nick Sabalausky
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message 
news:iedqos$78...@digitalmars.com...
 On 12/16/10 1:30 PM, Jacob Carlborg wrote:

 The point here isn't that we want a and b to be replaced with _
 the point is that we want to get rid of the string and have a shorter
 and less verbose syntax for delegate literals.

 I understand. Using strings is witnessing the fact that we couldn't find a 
 shorter syntax that didn't have problems. That being said, it's very 
 possible there are some great ones, we just couldn't find them.


Any problem with the other Scala/C#-style one?:

(x, y) =  x * y

// Lowered to:

(x, y) { return x * y; }

(Maybe that was rejected before due the the weird float operators that are 
now being ditched?)

It wouldn't be used for delegates that involve actual statements (it would 
be expression-only), but that fits with the whole point of a lambda 
expression.

Also, unlike the strings it doesn't suffer the problem of being evaluated in 
the wrong scope. For instance I think it's perfctly sensible to want a short 
lambda to be able to do something like this (pardon me if I have the syntax 
for map() wrong):

int foo(int x) { ... }
collection.map!foo(a) + 3();
// Or if you want proper syntax highlighting:
collection.map!q{ foo(a) + 3 }();

I think that totally fits the charter of short lambdas, but the strings just 
can't do it (at least not without turning map() into something that needs to 
be mixed in). The lowered Scala/C#-style would be able to though:

int foo(int x) { ... }
collection.map!((a) = foo(a) + 3)();
// Lowered to the messier:
collection.map!((a) { return foo(a) + 3; })();




Re: New syntax for string mixins

2010-12-16 Thread Jacob Carlborg

On 2010-12-16 23:05, Jonathan M Davis wrote:

On Thursday, December 16, 2010 11:28:03 Jacob Carlborg wrote:

On 2010-12-15 23:00, Nick Sabalausky wrote:

Jonathan M Davisjmdavisp...@gmx.com   wrote in message
news:mailman.1035.1292441722.21107.digitalmar...@puremagic.com...


On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:

That was my idea as well, that

@get_set(int, bar);

could be translated into

mixin(get_set(int, bar)); just like

just like scope statements are translated into try/catch/finally.


Honestly, I don't see much gain in using @ rather than mixin(). It's a
little
less typing, but that's it.


It does seem like a small difference, just replacing mixin with @ and
removing one layer of parens. But I think that extra layer of parens,
minor as it seems, makes a big difference in the readability (and
typeability) of mixin invocations. Those extra parens do get to be a
real bother, major visual noise at least to my eyes.


^^ I completely agree.


And it precludes stuff like mixin(lhs  ~ op ~ 
rhs) like happens all the time in overloaded operator functions.


I don't see why these shouldn't work:

@int foo;;
return @(lhs  ~ op ~  rhs);

At least with just the @ part of the proposal. Maybe the delegate thing
might make it tricker, I dunno.


My idea was actually to get rid of the strings where the code to be
mixed in is defined and to have a better syntax where it's used.

The delegates are just a way of passing a block of code around. If you
just use it in place then maybe one could do like this:

@(int foo;);
return @(lhs@(op)rhs);


I would have thought that template mixins would be the thing to use when you
didn't want to deal with strings. string mixins are extremely powerful and
flexible, and I'd really hate to lose them. And IIRC, Kenji Hara was working on 
a
module to really help make dealing with complicated string mixins easier and
less painful. Anything that you propose is going to have to have major benefits
over the current string mixin situation for it to stand any chance of being
accepted.

- Jonathan M Davis


Template mixins and string mixins are used for different things. There's 
a lot of things that string mixins can do that template mixins can't. I 
have no intention what so ever to suggest something that isn't as 
powerful as string mixins, just a new syntax. If it turns out that a 
having a powerful syntax without strings isn't possibles than I'll guess 
we have to live with the strings.


Don't know if you read my first post put there I wrote that it wasn't a 
real suggestion (at least not yet) I just wanted the community's 
thoughts on the idea and see if we could turn it into something useful 
that could become a real suggestion, if people where interested.


The ideas I wrote in my extended suggestion, Taking it one step 
further, I think that those can have benefits over string mixins. 
Basically allowing you to pass the whole body of a class declaration to 
a function, as a delegate, with a syntax looking like Java annotations.


--
/Jacob Carlborg


Re: New syntax for string mixins

2010-12-16 Thread Nick Sabalausky
Jacob Carlborg d...@me.com wrote in message 
news:iee4en$tt...@digitalmars.com...
 On 2010-12-16 21:35, Nick Sabalausky wrote:
 Jacob Carlborgd...@me.com  wrote in message
 news:iedpbg$3i...@digitalmars.com...
 On 2010-12-15 23:00, Nick Sabalausky wrote:

 I don't see why these shouldn't work:

 @int foo;;
 return @(lhs  ~ op ~  rhs);

 At least with just the @ part of the proposal. Maybe the delegate 
 thing
 might make it tricker, I dunno.

 My idea was actually to get rid of the strings where the code to be 
 mixed
 in is defined and to have a better syntax where it's used.

 The delegates are just a way of passing a block of code around. If you
 just use it in place then maybe one could do like this:

 @(int foo;);
 return @(lhs@(op)rhs);


 Yea, my point was just that the @... stuff could work either way, with 
 the
 string-based system or with your delegate-based one.

 I don't mean to come across like I'm ignoring or against the idea of the
 whole delegate aspect, and I understand that the main point of the OP is 
 to
 replace the strings with delegates, but with the q{...} syntax and
 string-templating, I'm still struggling to see a big enough benefit 
 compared
 to the status quo. I see that using delegates instead of strings could
 probably be made to work, but my questions are For what benefit(s)? and
 Would those benefits be sufficient to warrant the change? I'm not
 necessarily saying the answer is no, but I'm unconvinced so far.

 And here's another thing: Suppose we got a Ruby/PHP-like syntax for
 embedding code substitutions directly into a string (which would have 
 other
 useful applications besides mixins):

 auto name = Joe;
 auto msg = hello #{name}, whaddup?;
 mixin( q{ int #{name} = 7; } );
 Joe++;

 Would that eliminate much (or all) of the benefit of the delegate 
 approach?

 I guess using q{...} with string interpolation is very similar to the 
 delegate approach. It just feels wrong passing around strings to represent 
 code.

Well, code *is* text after all. But I know what you mean - after all, it 
does have more semantic structure than just ordinary generic strings.

 I haven't though much about it but with delegates one could at lest hope 
 for better help from the compiler validating the code. I don't know how 
 IDEs will treat q{...} but with delegates you would get the full benefit 
 of the IDE like autocompletion and similar features.


My editor (Programmer's Notepad 2, based off Scintilla) handles that fine. 
It doesn't know anything about q{}, so it assumes it's an identifier (q) 
followed by a normal code block. And since it doesn't try to do any 
grammatical/semantic validation (only lexical, and only for the purpose of 
highlighting) it doesn't complain about identifier { ... } being invalid 
or any of the indentifiers-to-be-replaced inside of it being undeclared.

But for fancier IDE's, like Eclipse with Descent or DDT, I don't know - 
that's a good question.

OTOH, even with the delegate approach, I'm assuming that delegate would 
still get evaluated in a different context from where it's defined (which 
you'd probably want). So that might still cause some trouble with the more 
intelligent IDEs trying to tell you that identifierXYZ isn't accessable from 
within what it thinks is the delegate's scope.




Re: New syntax for string mixins

2010-12-16 Thread Nick Sabalausky
Jacob Carlborg d...@me.com wrote in message 
news:iee561$v5...@digitalmars.com...
 On 2010-12-16 23:05, Jonathan M Davis wrote:
 On Thursday, December 16, 2010 11:28:03 Jacob Carlborg wrote:
 On 2010-12-15 23:00, Nick Sabalausky wrote:
 Jonathan M Davisjmdavisp...@gmx.com   wrote in message
 news:mailman.1035.1292441722.21107.digitalmar...@puremagic.com...

 On Wednesday, December 15, 2010 11:27:47 Jacob Carlborg wrote:
 That was my idea as well, that

 @get_set(int, bar);

 could be translated into

 mixin(get_set(int, bar)); just like

 just like scope statements are translated into try/catch/finally.

 Honestly, I don't see much gain in using @ rather than mixin(). It's a
 little
 less typing, but that's it.

 It does seem like a small difference, just replacing mixin with @ 
 and
 removing one layer of parens. But I think that extra layer of parens,
 minor as it seems, makes a big difference in the readability (and
 typeability) of mixin invocations. Those extra parens do get to be a
 real bother, major visual noise at least to my eyes.

 ^^ I completely agree.

 And it precludes stuff like mixin(lhs  ~ op ~ 
 rhs) like happens all the time in overloaded operator functions.

 I don't see why these shouldn't work:

 @int foo;;
 return @(lhs  ~ op ~  rhs);

 At least with just the @ part of the proposal. Maybe the delegate 
 thing
 might make it tricker, I dunno.

 My idea was actually to get rid of the strings where the code to be
 mixed in is defined and to have a better syntax where it's used.

 The delegates are just a way of passing a block of code around. If you
 just use it in place then maybe one could do like this:

 @(int foo;);
 return @(lhs@(op)rhs);

 I would have thought that template mixins would be the thing to use when 
 you
 didn't want to deal with strings. string mixins are extremely powerful 
 and
 flexible, and I'd really hate to lose them. And IIRC, Kenji Hara was 
 working on a
 module to really help make dealing with complicated string mixins easier 
 and
 less painful. Anything that you propose is going to have to have major 
 benefits
 over the current string mixin situation for it to stand any chance of 
 being
 accepted.

 - Jonathan M Davis

 Template mixins and string mixins are used for different things. There's a 
 lot of things that string mixins can do that template mixins can't. I have 
 no intention what so ever to suggest something that isn't as powerful as 
 string mixins, just a new syntax. If it turns out that a having a powerful 
 syntax without strings isn't possibles than I'll guess we have to live 
 with the strings.

 Don't know if you read my first post put there I wrote that it wasn't a 
 real suggestion (at least not yet) I just wanted the community's thoughts 
 on the idea and see if we could turn it into something useful that could 
 become a real suggestion, if people where interested.

 The ideas I wrote in my extended suggestion, Taking it one step further, 
 I think that those can have benefits over string mixins. Basically 
 allowing you to pass the whole body of a class declaration to a function, 
 as a delegate, with a syntax looking like Java annotations.


It would seem to make sense to treat chucks of code the same way 
regardless of whether you're passing them around, mixing them in or 
instantiating them as a template.





Re: New syntax for string mixins

2010-12-16 Thread Graham St Jack


I've attached a part of how concurrency.d could look like translated 
to my suggested syntax. It probably contains a lot of errors because 
did a quick translation and I had some trouble understanding the mixins.


Yes, even I couldn't understand them even a week later. Maintenance is a 
real problem.


My initial reaction is that the proposed syntax helps a bit, but isn't 
really a game-changer. I will let you know if I change my mind on closer 
inspection.


--
Graham St Jack



gdc-4.5 testing

2010-12-16 Thread Iain Buclaw
Just announcing (before I nod off) that gdc is working with gcc-4.5.1. Builds D1
and compiles Tango.

Commit:
https://bitbucket.org/goshawk/gdc/changeset/8ac6cb4f40aa

Feedback, patches and bug reports welcome!

Regards


Re: Cross-post from druntime: Mixing GC and non-GC in D. (AKA, don't touch GC-references from DTOR, preferably don't use DTOR at all)

2010-12-16 Thread Robert Jacques
On Wed, 15 Dec 2010 16:23:24 -0500, Ulrik Mikaelsson  
ulrik.mikaels...@gmail.com wrote:



Cross-posting after request on the druntime list:
--

Hi,

DISCLAIMER: I'm developing for D1/Tango. It is possible these issues
are already resolved for D2/druntime. If so, I've failed to find any
information about it, please do tell.

Recently, I've been trying to optimize my application by swapping out
some resource allocation (file-descriptors for one) to
reference-counted allocation instead of GC. I've hit some problems.

Problem
===

Basically, the core of all my problems is something expressed in
http://bartoszmilewski.wordpress.com/2009/08/19/the-anatomy-of-reference-counting/
as An object’s destructor must not access any garbage-collected
objects embedded in it..


[snip]

Having run into this problem with CUDA C language bindings, I do feel your  
pain. However, the fact that An object’s destructor must not access any  
garbage-collected objects embedded in it. is a key assumption made by all  
GC algorithms (that I know of). Yes, D's current GC only does full  
collections, so a child-object knows that it's parent objects are either  
valid or are being collected at the same time it is. But this isn't true  
for generational collectors, and I wouldn't want D to exclude itself from  
a wide range of modern GC.


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Walter Bright

Nick Sabalausky wrote:
but I found OE's annoyances to overall be somewhat 
less annoying than Thunderbird's.


OE cannot back up or transfer its message database. That killed it for me.


(Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Craig Black
It was brought to my attention that the quick sort has a very bad worst 
case, so I implemented a simple fix for it.  Now the worst case (completely 
ordered) is the best case, and it only slows down the general case by a 
small percentage.  I thought to myself, it can't be this easy to fix quick 
sort.  Does anyone see a flaw in this simple fix?  Performs much better 
than Phobos in completely random and completely sorted data.  Perhaps there 
is another case where it doesn't do as well?


-Craig

import std.stdio;
import std.random;
import std.algorithm;

static bool less(T)(T a, T b) { return a  b; }

bool isOrdered(A, alias L)(A a, int low, int high)
{
 for(int i = low; i  high; i++)
 {
   if(L(a[i+1], a[i])) return false;
 }
 return true;
}

void insertionSort(A, alias L)(A a, int low, int high)
{
 for(int i = low; i = high; i++)
 {
   int min = i;
   for(int j = i + 1; j = high; j++)
 if(L(a[j], a[min])) min = j;
   swap(a[i], a[min]);
 }
}

void quickSort(A, alias L)(A a, int p, int r)
{
 if (p = r) return;
 if(isOrdered!(A, L)(a, p, r)) return;
 if(p + 7  r) return insertionSort!(A, L)(a, p, r);
 auto x = a[r];
 int j = p - 1;
 for (int i = p; i  r; i++)
 {
   if (L(x, a[i])) continue;
   swap(a[i], a[++j]);
 }
 a[r] = a[j + 1];
 a[j + 1] = x;
 quickSort!(A, L)(a, p, j);
 quickSort!(A, L)(a, j + 2, r);
}

void customSort(T)(T[] a)
{
 quickSort!(T[], less!T)(a, 0, a.length-1);
}

ulong getCycle() { asm { rdtsc; } }

ulong bench1(double[] vals)
{
 ulong startTime = getCycle();
 double[] v;
 v.length = vals.length;
 for(int i = 0; i  100; i++)
 {
   for(int j = 0; j  v.length; j++) v[j] = vals[j];
   sort(v);
 }
 return getCycle() - startTime;
}

ulong bench2(double[] vals)
{
 ulong startTime = getCycle();
 double[] v;
 v.length = vals.length;
 for(int i = 0; i  100; i++)
 {
   for(int j = 0; j  v.length; j++) v[j] = vals[j];
   customSort(v);
 }
 return getCycle() - startTime;
}

void main()
{
 Mt19937 gen;
 double[] vals;
 vals.length = 1000;
 for(int i = 0; i  vals.length; i++) vals[i] = uniform(0.0,1000.0);
 sort(vals[]);

 ulong time1, time2;
 for(int i = 0; i  100; i++)
 {
   time1 += bench1(vals);
   time2 += bench2(vals);
 }
 writeln(Sorting with phobos sort: , time1/1e5);
 writeln(Sorting with custom quickSort: , time2/1e5);
 if(time1  time2)
   writeln(100.0 * (time1-time2) / time1,  percent faster);
 else
   writeln(100.0 * (time2-time1) / time2,  percent slower);
}



Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Russel Winder
On Thu, 2010-12-16 at 20:36 -0600, Craig Black wrote:
 It was brought to my attention that the quick sort has a very bad worst 
 case, so I implemented a simple fix for it.  Now the worst case (completely 
 ordered) is the best case, and it only slows down the general case by a 
 small percentage.  I thought to myself, it can't be this easy to fix quick 
 sort.  Does anyone see a flaw in this simple fix?  Performs much better 
 than Phobos in completely random and completely sorted data.  Perhaps there 
 is another case where it doesn't do as well?

Is there any reason to not just follow Bentley and McIlroy,
``Engineering a Sort Function,'' SPE 23(11), p.1249-1265, November
1993.  It is what the Java folk and the Go folk do for sorting arrays
(and slices in Go).  The Java folk use a modified Merge Sort for sorting
collections.   It's all to do with stability as well as algorithmic
complexity.

Quicksort and Merge Sort is, however, a research industry so it will
undoubtedly be the case that there is significantly more work done in
the last 17 years.  This is especially true for parallel sorting.  A
library for D undoubtedly needs both a sequential and a parallel sort
function.  The Go folk haven't tackled this yet, and I can#t see the C++
and Java folk tackling it for the forseeable future even though it is
basically a necessity.

I have no doubt that people on this list could easily contribute to the
research activity in this area, and perhaps that is what some would like
to do, but to tinker away at algorithms outside the context of all the
research work done on this seems like the fastest way to be treated as
amateur hackers.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message 
news:ieegkh$1mu...@digitalmars.com...
 Nick Sabalausky wrote:
 but I found OE's annoyances to overall be somewhat less annoying than 
 Thunderbird's.

 OE cannot back up or transfer its message database. That killed it for me.

Yea, that has been in the back of my mind ever since one other time that you 
mentioned it. Been meaning to do somethng about it, but just been kinda 
sticking with it anyway while I have 100 more urgent things :/




Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Matthias Walter
On 12/16/2010 09:36 PM, Craig Black wrote:
 It was brought to my attention that the quick sort has a very bad
 worst case, so I implemented a simple fix for it.  Now the worst case
 (completely ordered) is the best case, and it only slows down the
 general case by a small percentage.  I thought to myself, it can't be
 this easy to fix quick sort.  Does anyone see a flaw in this simple
 fix?  Performs much better than Phobos in completely random and
 completely sorted data.  Perhaps there is another case where it
 doesn't do as well?

Yes, there is a flaw: There are still instances of arrays where you
will end up with a pivot element being one of the largest or one of the
smallest elements in *every* call. The means, that you split your array
from length n not into two arrays roughly of size n/2 and n/2, but of
O(1) and n - O(1). This implies a running time of n^2 (in contrast to n
log n), which is obviously bad.

I don't know how std.algorithm.sort works, but C++ STL uses an
Introspective sort, which is a quick-sort variant like you have, but it
has some measurements that observe whether the above worst case occurs
(e.g. by looking at the recursion depth) and switches to a heap-sort in
this case. [1]

Matthias

[1] http://en.wikipedia.org/wiki/Introsort


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Walter Bright

Nick Sabalausky wrote:
Walter Bright newshou...@digitalmars.com wrote in message 
news:ieegkh$1mu...@digitalmars.com...

Nick Sabalausky wrote:
but I found OE's annoyances to overall be somewhat less annoying than 
Thunderbird's.

OE cannot back up or transfer its message database. That killed it for me.


Yea, that has been in the back of my mind ever since one other time that you 
mentioned it. Been meaning to do somethng about it, but just been kinda 
sticking with it anyway while I have 100 more urgent things :/


I procrastinated doing something about it for a long time, too, for the same 
reasons. Until one day my machine got hit with a virus, and the only way to get 
rid of it was to wipe  reinstall Windows. That was I think the 3rd time I lost 
my O.E. database, and I'd had enough.


T-bird has its annoying problems, too, but losing my mail database can have 
disastrous consequences for my business. I can back up T-bird's database, and 
that is the #1 feature for me.


Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Craig Black
Amateur hacker?  Ah, go fuck yourself.  Just because I haven't researched 
sorting algorithms before doesn't give you any right to talk down to me.  I 
haven't been  ignoring research... but I do like to tinker.  For me it's a 
good way to learn.  In addition to tinkering I have been learning about 
other sort algorithms.  Again, please fuck yourself.


-Craig 



Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Craig Black


Matthias Walter xa...@xammy.homelinux.net wrote in message 
news:mailman.1065.1292557052.21107.digitalmar...@puremagic.com...

On 12/16/2010 09:36 PM, Craig Black wrote:

It was brought to my attention that the quick sort has a very bad
worst case, so I implemented a simple fix for it.  Now the worst case
(completely ordered) is the best case, and it only slows down the
general case by a small percentage.  I thought to myself, it can't be
this easy to fix quick sort.  Does anyone see a flaw in this simple
fix?  Performs much better than Phobos in completely random and
completely sorted data.  Perhaps there is another case where it
doesn't do as well?


Yes, there is a flaw: There are still instances of arrays where you
will end up with a pivot element being one of the largest or one of the
smallest elements in *every* call. The means, that you split your array
from length n not into two arrays roughly of size n/2 and n/2, but of
O(1) and n - O(1). This implies a running time of n^2 (in contrast to n
log n), which is obviously bad.

I don't know how std.algorithm.sort works, but C++ STL uses an
Introspective sort, which is a quick-sort variant like you have, but it
has some measurements that observe whether the above worst case occurs
(e.g. by looking at the recursion depth) and switches to a heap-sort in
this case. [1]

Matthias

[1] http://en.wikipedia.org/wiki/Introsort


Thanks for the advice!  I have been looking on the internet and it seems 
introsort is the best, but I haven't found any free C/C++ code for it.


-Craig 



Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Daniel Gibson

Craig Black schrieb:
Amateur hacker?  Ah, go fuck yourself.  Just because I haven't 
researched sorting algorithms before doesn't give you any right to talk 
down to me.  I haven't been  ignoring research... but I do like to 
tinker.  For me it's a good way to learn.  In addition to tinkering I 
have been learning about other sort algorithms.  Again, please fuck 
yourself.


-Craig


WTF
are you drunk or something?


Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Andrej Mitrovic
I've found a Java implementation of introsort:

http://ralphunden.net/?q=a-guide-to-introsort
http://ralphunden.net/?q=a-guide-to-introsort#42

Hope that helps. :)


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message 
news:ieen8f$25s...@digitalmars.com...
 Nick Sabalausky wrote:
 Walter Bright newshou...@digitalmars.com wrote in message 
 news:ieegkh$1mu...@digitalmars.com...
 Nick Sabalausky wrote:
 but I found OE's annoyances to overall be somewhat less annoying than 
 Thunderbird's.
 OE cannot back up or transfer its message database. That killed it for 
 me.

 Yea, that has been in the back of my mind ever since one other time that 
 you mentioned it. Been meaning to do somethng about it, but just been 
 kinda sticking with it anyway while I have 100 more urgent things :/

 I procrastinated doing something about it for a long time, too, for the 
 same reasons. Until one day my machine got hit with a virus, and the only 
 way to get rid of it was to wipe  reinstall Windows. That was I think the 
 3rd time I lost my O.E. database, and I'd had enough.


Oh, I thought you were saying that the whole problem was just the whole 
proprietary storage format and that there wasn't a way to migrate to/from 
another email program. It *is* possible to backup and restore OE's DB, it 
just doesn't have a simple option for it through the UI:

http://support.microsoft.com/kb/270670

Basically, for the messages, you just backup a certain directory, and 
there's a place in OE's options that will tell you the directory's path. 
There's also ways to backup/restore the address book and mail/NG accounts.

Yea, it would definitely be nice if it had a single simple button to backup 
everything, or a simple way to cron it or something, but it is at least 
possible to backup/restore OE's data.

 T-bird has its annoying problems, too, but losing my mail database can 
 have disastrous consequences for my business. I can back up T-bird's 
 database, and that is the #1 feature for me. 




Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Walter Bright

Nick Sabalausky wrote:
Oh, I thought you were saying that the whole problem was just the whole 
proprietary storage format and that there wasn't a way to migrate to/from 
another email program. It *is* possible to backup and restore OE's DB, it 
just doesn't have a simple option for it through the UI:


http://support.microsoft.com/kb/270670


Microsoft had no mechanism for backup/restore at the time; I called their 
support center.


Having the mail database in a proprietary format in a hidden directory didn't 
help.


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Jonathan M Davis
On Thursday 16 December 2010 21:37:11 Walter Bright wrote:
 Nick Sabalausky wrote:
  Oh, I thought you were saying that the whole problem was just the whole
  proprietary storage format and that there wasn't a way to migrate to/from
  another email program. It *is* possible to backup and restore OE's DB, it
  just doesn't have a simple option for it through the UI:
  
  http://support.microsoft.com/kb/270670
 
 Microsoft had no mechanism for backup/restore at the time; I called their
 support center.
 
 Having the mail database in a proprietary format in a hidden directory
 didn't help.

Using IMAP solves the problem, since then the mail is safely on a server 
somewhere rather on your own computer. It also has the advantage of making it 
possible to sync state between machines. It does mean, however, that you have 
to 
be deal with an e-mail account which is IMAP-capable.

- Jonathan M Davis


Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Andrei Alexandrescu

On 12/16/10 9:05 PM, Russel Winder wrote:

On Thu, 2010-12-16 at 20:36 -0600, Craig Black wrote:

It was brought to my attention that the quick sort has a very bad worst
case, so I implemented a simple fix for it.  Now the worst case (completely
ordered) is the best case, and it only slows down the general case by a
small percentage.  I thought to myself, it can't be this easy to fix quick
sort.  Does anyone see a flaw in this simple fix?  Performs much better
than Phobos in completely random and completely sorted data.  Perhaps there
is another case where it doesn't do as well?


Is there any reason to not just follow Bentley and McIlroy,
``Engineering a Sort Function,'' SPE 23(11), p.1249-1265, November
1993.  It is what the Java folk and the Go folk do for sorting arrays
(and slices in Go).  The Java folk use a modified Merge Sort for sorting
collections.   It's all to do with stability as well as algorithmic
complexity.

Quicksort and Merge Sort is, however, a research industry so it will
undoubtedly be the case that there is significantly more work done in
the last 17 years.  This is especially true for parallel sorting.  A
library for D undoubtedly needs both a sequential and a parallel sort
function.  The Go folk haven't tackled this yet, and I can#t see the C++
and Java folk tackling it for the forseeable future even though it is
basically a necessity.

I have no doubt that people on this list could easily contribute to the
research activity in this area, and perhaps that is what some would like
to do, but to tinker away at algorithms outside the context of all the
research work done on this seems like the fastest way to be treated as
amateur hackers.


Yeah, when reading this I was like, the last sentence ain't likely to 
be as well received as others. :o) All - let's take it easy.


I implemented std.algorithm sort and it reuses partition(), another 
algorithm, and uses Singleton's partition of first, middle, last 
element. I also eliminated a few obvious risks of quadratic behavior. 
See comment on line 3831:


http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/algorithm.d?rev=1279#L3808

I was familiar at the time with Bentley's paper but there is only so 
much time to spend on implementing one algorithm when I had fifty others 
on my plate. I think std.algorithm.sort does an adequate job but it can 
be improved in many ways.



Andrei


Re: [OT] Mozilla Thunderbird

2010-12-16 Thread Walter Bright

Jonathan M Davis wrote:
Using IMAP solves the problem, since then the mail is safely on a server 
somewhere rather on your own computer. It also has the advantage of making it 
possible to sync state between machines. It does mean, however, that you have to 
be deal with an e-mail account which is IMAP-capable.


I prefer to have control over my email database, and not rely on some remote 
server that may go dark at any moment, or that may sell my email database to anyone.


Having my old emails has saved me countless  over the years.

You wouldn't believe how many times companies (even large ones!) have lost the 
contracts I made with them, and I had to go back through the emails and forward 
them copies.


Re: Inlining Code Test

2010-12-16 Thread Nick Voronin
On Mon, 13 Dec 2010 01:50:50 +0300, Craig Black craigbla...@cox.net  
wrote:


The following program illustrates the problems with inlining in the dmd  
compiler.  Perhaps with some more work I can reduce it to a smaller test  
case.  I was playing around with a simple Array template, and noticed  
that similar C++ code performs much better.  This is due, at least in  
part, to opIndex not being properly inlined by dmd.  There are two sort  
functions, quickSort1 and quickSort2.  quickSort1 indexes an Array data  
structure. quickSort2 indexes raw pointers.  quickSort2 is roughly 20%  
faster on my core i7.


Compiled with dmd v2.050/win32  -g -O -inline -release

First, I looked in debugger on actual asm and I must say inlining is done  
very well. Code for two versions is almost identical with slight overhead  
in case of Array for there is extra level of indirection in data access,  
inlining or not.


Second, I have anywhere from 3.3 to 6.7% difference in performance, but no  
more than that. Tested on Core2Duo E6300, Windows XP SP3. I increased  
number of iterations for benchmark!() to 5 to reduce volatility of  
results. That's the only change to source I did.


Third... Now here is a funny thing. Absolute times and difference between  
implementation depends on how do you run the program. I was dumbfounded as  
of how does it matter, but the fact is that aforementioned avg 5%  
difference I get if I run it with command line as inline.exe. If I run  
it as inline without extension I get difference around 15% and absolute  
times are notably smaller.



X:\d\tests\craiginline.exe
Sorting with Array.opIndex: 6533
Sorting with pointers: 6264
4.11756 percent faster

X:\d\tests\craiginline
Sorting with Array.opIndex: 5390
Sorting with pointers: 4674
13.2839 percent faster

Something like that. It's not a fluke. I tested it on my old AthlonXp with  
XP SP2 and saw exactly the same picture (btw, difference in % between  
implementation was about the same).


I ran both variants under stracent and found no difference except one  
pointer on the stack when LeaveCriticalSection and GetCurrentThreadId are  
called was always off by 4 bytes. This made me thinking. The only  
observable difference is length of command line. And indeed, renaming  
program showed that only length of command line is a reason, not the  
content.


Further tests suggest that some value is either aligned to 8 byte or not  
depending on length of command line and this makes all the difference  
(which happens to be greater than difference between implementations of  
sorting). I couldn't find what value causes slowdown though.


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


Purity

2010-12-16 Thread bearophile
http://www.reddit.com/r/programming/comments/enajl/purity_in_d_language/

Bye,
bearophile


Why does this floating point comparison fail?

2010-12-16 Thread Jonathan M Davis
Maybe I'm just totally missing something, but this seems really wrong to me. 
This program:

import std.stdio;

void main()
{
writeln(2.1);
writeln(2.1 == 2.1);
writeln(3 * .7);
writeln(2.1 == 3 * .7);

auto a = 2.1;
auto b = 3 * .7;
writeln(a);
writeln(b);
writeln(a == b);
}



prints out

2.1
true
2.1
false
2.1
2.1
true


How on earth is 2.1 not equal to 3 * .7? Adding extra parens doesn't help, so 
it's not an operator precedence issue or anything like that. For some reason, 
the result of 3 * .7 is not considered to be equal to the literal 2.1. What's 
the deal? As I understand it, floating point operations at compile time do not 
necessarily match those done at runtime, but 2.1 should be plenty exact for 
both 
compile time and runtime. It's not like there are a lot of digits in the 
number, 
and it prints out 2.1 whether you're dealing with a variable or a literal. 
What's the deal here? Is this a bug? Or am I just totally misunderstanding 
something?

- Jonathan M Davis


Re: Why does this floating point comparison fail?

2010-12-16 Thread Don

Jonathan M Davis wrote:
Maybe I'm just totally missing something, but this seems really wrong to me. 
This program:


import std.stdio;

void main()
{
writeln(2.1);
writeln(2.1 == 2.1);
writeln(3 * .7);
writeln(2.1 == 3 * .7);

auto a = 2.1;
auto b = 3 * .7;
writeln(a);
writeln(b);
writeln(a == b);
}



prints out

2.1
true
2.1
false
2.1
2.1
true


How on earth is 2.1 not equal to 3 * .7?


0.7 is not exactly representable in binary floating point, nor is 2.1.
(they are the binary equivalent of a recurring decimal like 
0....)


 Adding extra parens doesn't help, so
it's not an operator precedence issue or anything like that. For some reason, 
the result of 3 * .7 is not considered to be equal to the literal 2.1. What's 
the deal? As I understand it, floating point operations at compile time do not 
necessarily match those done at runtime, but 2.1 should be plenty exact for both 
compile time and runtime. It's not like there are a lot of digits in the number, 
and it prints out 2.1 whether you're dealing with a variable or a literal. 
What's the deal here? Is this a bug? Or am I just totally misunderstanding 
something?


Constant folding is done at real precision. So 3 * .7 is an 80-bit number.
But, 'a' has type double. So it's been truncated to 64 bit precision.

When something confusing like this happens, I recommend using the %a 
format, since it never lies.

writefln(%a %a, a, 3*.7);


List of derived types?

2010-12-16 Thread d coder
Greetings

I need a way to know (using traits or other compile time constructs)
all the types derived from a given type.
Is it possible in D?

Is it possible to get a list of all the user-defined classes? I could
use that to filter out the classes that I need.

Regards
Cherry


Re: List of derived types?

2010-12-16 Thread Michal Minich
V Thu, 16 Dec 2010 18:46:41 +0530, d coder wrote:

 Greetings
 
 I need a way to know (using traits or other compile time constructs) all
 the types derived from a given type. Is it possible in D?
 
 Is it possible to get a list of all the user-defined classes? I could
 use that to filter out the classes that I need.
 
 Regards
 Cherry

you can iterate all modules to find base classes. see object_.d file to 
see sturcture of TypeInfo_Class or ModuleInfo.

 foreach(m; ModuleInfo)
foreach (c; m.localClasses)
if (c.base !is null)
writefln(c.base.name);


Re: List of derived types?

2010-12-16 Thread Pelle Månsson

On 12/16/2010 02:16 PM, d coder wrote:

Greetings

I need a way to know (using traits or other compile time constructs)
all the types derived from a given type.
Is it possible in D?

Is it possible to get a list of all the user-defined classes? I could
use that to filter out the classes that I need.

Regards
Cherry


I'm curious, why do you need that?


Re: List of derived types?

2010-12-16 Thread Simen kjaeraas

d coder dlang.co...@gmail.com wrote:


Greetings

I need a way to know (using traits or other compile time constructs)
all the types derived from a given type.
Is it possible in D?


No.


Is it possible to get a list of all the user-defined classes? I could
use that to filter out the classes that I need.


No.


However, it is possible at run-time to iterate through all classes and
at that time compare them to the base class:

T[] getDerivedClasses( T )( ) if ( is( T == class ) ) {
T[] result;
foreach ( mod; ModuleInfo ) {
foreach ( cls; mod.localClasses ) {
if ( mod.name == object ) {
break;
}
auto cls_base = cls;
do {
if ( cls_base.name == T.classinfo.name ) {
if ( T tmp = cast(T)cls.create( ) ) {
result ~= tmp;
}
}
} while ( ( cls_base = cls_base.base ) != Object.classinfo );
}
}
return result;
}


--
Simen


Re: List of derived types?

2010-12-16 Thread d coder
 I'm curious, why do you need that?


It is a long story.

But basically I am creating a platform wherein the users would be
deriving classes from some base classes that I write as part of the
platform. And the users would often be deriving many such classes.

The end-users would often not be programmers and would know little D
(as you can see I am also learning D :-). I want to automate some code
generation for them and I hope to do that by creating wrapper classes
that would shadow the classes that the end-users have written. Since
the and users would be instantiating these classes only inside a
particular class scope, I wanted to create some code inside that class
scope. Right now I am forcing the end-users to insert some mixin for
every class that they code. I wanted to automate that process.

Hope what I said makes sense to you.

Regards
Cherry

Hope what I said makes sense.


Problems with stdio.byLine() in D Book

2010-12-16 Thread Chris A
Hey all, I'm going over some examples in Alexandrescu's book, but I guess 
something has changed in the language because the example isn't working for me.

The simple example:

void main(string[] args)
{
uint[string] freqs;
foreach(lines; stdin.byLine()) {
foreach(word; split(strip(lines))) {
++freqs[word.idup];
}
}
foreach(key, value; freqs){
writefln(%6u\t%s, value, key);
}
din.getc();
}


This throws an error during compile, like:
main.d(11): Error: no property 'ByLine' for type '_iobuf'
main.d(11): Error: function expected before (), not 1 of type int
main.d(11): Error: foreach: int is not an aggregate type

So seemingly byLine is no longer an existing function on stdin.  What is the 
current version of what this code is trying to do?


Re: Problems with stdio.byLine() in D Book

2010-12-16 Thread Andrej Mitrovic
This works fine for me:

import std.stdio;
import std.string;

void main(string[] args)
{
   uint[string] freqs;
   foreach(lines; stdin.byLine()) {
   foreach(word; split(strip(lines))) {
   ++freqs[word.idup];
   }
   }
   foreach(key, value; freqs){
   writefln(%6u\t%s, value, key);
   }
getchar();
}

Perhaps you missed an import

On 12/16/10, Chris A codexarca...@gmail.com wrote:
 Hey all, I'm going over some examples in Alexandrescu's book, but I guess
 something has changed in the language because the example isn't working for
 me.

 The simple example:

 void main(string[] args)
 {
   uint[string] freqs;
   foreach(lines; stdin.byLine()) {
   foreach(word; split(strip(lines))) {
   ++freqs[word.idup];
   }
   }
   foreach(key, value; freqs){
   writefln(%6u\t%s, value, key);
   }
   din.getc();
 }


 This throws an error during compile, like:
 main.d(11): Error: no property 'ByLine' for type '_iobuf'
 main.d(11): Error: function expected before (), not 1 of type int
 main.d(11): Error: foreach: int is not an aggregate type

 So seemingly byLine is no longer an existing function on stdin.  What is the
 current version of what this code is trying to do?



Re: Problems with stdio.byLine() in D Book

2010-12-16 Thread Chris A
Hmm... maybe my compiler was out of date.  I downloaded DMD again and tried 
your code, and it seems to build fine now.  

Sorry for the trouble then, thank you for setting me on the right path Andrej. 


Andrej Mitrovic Wrote:

 This works fine for me:
 
 import std.stdio;
 import std.string;
 
 void main(string[] args)
 {
uint[string] freqs;
foreach(lines; stdin.byLine()) {
foreach(word; split(strip(lines))) {
++freqs[word.idup];
}
}
foreach(key, value; freqs){
writefln(%6u\t%s, value, key);
}
 getchar();
 }
 
 Perhaps you missed an import
 
 On 12/16/10, Chris A codexarca...@gmail.com wrote:
  Hey all, I'm going over some examples in Alexandrescu's book, but I guess
  something has changed in the language because the example isn't working for
  me.
 
  The simple example:
 
  void main(string[] args)
  {
  uint[string] freqs;
  foreach(lines; stdin.byLine()) {
  foreach(word; split(strip(lines))) {
  ++freqs[word.idup];
  }
  }
  foreach(key, value; freqs){
  writefln(%6u\t%s, value, key);
  }
  din.getc();
  }
 
 
  This throws an error during compile, like:
  main.d(11): Error: no property 'ByLine' for type '_iobuf'
  main.d(11): Error: function expected before (), not 1 of type int
  main.d(11): Error: foreach: int is not an aggregate type
 
  So seemingly byLine is no longer an existing function on stdin.  What is the
  current version of what this code is trying to do?
 



Re: Problems with stdio.byLine() in D Book

2010-12-16 Thread Andrej Mitrovic
Don't forget to bookmark the errata page:
http://erdani.com/tdpl/errata/index.php?title=Main_Page ;)

On 12/16/10, Chris A codexarca...@gmail.com wrote:
 Hmm... maybe my compiler was out of date.  I downloaded DMD again and tried
 your code, and it seems to build fine now.

 Sorry for the trouble then, thank you for setting me on the right path
 Andrej.


 Andrej Mitrovic Wrote:

 This works fine for me:

 import std.stdio;
 import std.string;

 void main(string[] args)
 {
uint[string] freqs;
foreach(lines; stdin.byLine()) {
foreach(word; split(strip(lines))) {
++freqs[word.idup];
}
}
foreach(key, value; freqs){
writefln(%6u\t%s, value, key);
}
 getchar();
 }

 Perhaps you missed an import

 On 12/16/10, Chris A codexarca...@gmail.com wrote:
  Hey all, I'm going over some examples in Alexandrescu's book, but I
  guess
  something has changed in the language because the example isn't working
  for
  me.
 
  The simple example:
 
  void main(string[] args)
  {
 uint[string] freqs;
 foreach(lines; stdin.byLine()) {
 foreach(word; split(strip(lines))) {
 ++freqs[word.idup];
 }
 }
 foreach(key, value; freqs){
 writefln(%6u\t%s, value, key);
 }
 din.getc();
  }
 
 
  This throws an error during compile, like:
  main.d(11): Error: no property 'ByLine' for type '_iobuf'
  main.d(11): Error: function expected before (), not 1 of type int
  main.d(11): Error: foreach: int is not an aggregate type
 
  So seemingly byLine is no longer an existing function on stdin.  What is
  the
  current version of what this code is trying to do?
 




[Issue 5043] writeln with empty arrays should write something useful

2010-12-16 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5043


Denis Derman denis.s...@gmail.com changed:

   What|Removed |Added

 CC||denis.s...@gmail.com


--- Comment #2 from Denis Derman denis.s...@gmail.com 2010-12-16 00:24:11 PST 
---
(In reply to comment #0)
 writeln( [1, 2, 3] ); // prints [1, 2, 3]
 writeln( [] ); // prints  (nothing)
 
 Why doesn't writeln( [] ) print []? It seems to me that [] would be far
 more useful, and it is certainly more consistent with the non-empty array
 behaviour.
 
 I know this is a minor thing, but if I'm trying to debug, blank lines aren't
 very much use, and actually cause more confusion than enlightenment.

+++

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---