Re: Initializing static arrays without specifying size

2010-08-01 Thread Philippe Sigaud
On Mon, Aug 2, 2010 at 00:28, Ziad  wrote:

>
> If I want a static array:
>
> int[5] a = [1, 2, 3, 4, 5];
>
> I'd have to specify the size in advance (5 in this case), which
> means that adding extra elements later on would require that the
> size be update.
>
> Is there a way to let the compiler automatically determine the size
> based on the argument list?
>

Would a template-based solution be OK?

import std.stdio, std.traits;

CommonType!T[T.length] staticArray(T...)(T vals)
if ((T.length > 0) && is(CommonType!T))
{
return [vals];
}

void main()
{
auto a = staticArray(0,1,2,3,4);
writeln(typeof(a).stringof); // int[5u]

auto b = staticArray(3.14);
writeln(typeof(b).stringof); // double[1u]

auto mixed = staticArray(0,1,2,3,4, 3.14);
writeln(typeof(mixed).stringof);  // double[6u]
}


Philippe


null dereference exception vs. segfault?

2010-08-01 Thread Ryan W Sims
The following code fails with a "Bus error" (OSX speak for "Segfault," 
if I understand correctly).


// types.d
import std.stdio;

class A {
int x = 42;
}

void fail_sometimes(int n) {
A a;
if (n == 0) {
a = new A;  // clearly a contrived example
}
assert(a.x == 42, "Wrong x value");
}

void main() {
fail_sometimes(1);
}

It's even worse if I do a 'dmd -run types.d', it just fails without even 
the minimalistic "Bus error." Is this correct behavior? I searched the 
archives & looked at the FAQ & found workarounds (registering a signal 
handler), but not a justification, and the threads were from a couple 
years ago. Wondering if maybe something has changed and there's a 
problem with my system?


--
rwsims


Re: xfbuild, optlink and pragma(lib)

2010-08-01 Thread Mike Parker

Mafi wrote:

The tool sounds cool but it seems that I have to buy it, so that's no 
option for me. So I tried to compile SDL myself. I have to say I'm to 
stupid for it. I tried to do the same thing as the makefile in 
powershell. After I hacked together some solution that worked dmc 
complained about missing Gl.h. It isn't there. So I added some MinGW to 
the include-path and then I get a bunch of errors in SDL without 
linenumbers. And anyways I am trying to compile it without MinGW, aren't 
I. Please, help me!


I've converted it for you. You can download it here:

http://aldacron.net/downloads/sdl.lib


std.file.read

2010-08-01 Thread bearophile
Can you tell me why std.file.read() returns a void[] instead of something like 
a ubyte[]?

(Performing a cast(ubyte[]) in SafeD can be a problem. I presume in SafeD I 
have to use other safer functions to load binary data, like slurp() or 
something similar.)

Bye,
bearophile


Re: A confusing expression?

2010-08-01 Thread Andrej Mitrovic
Maybe we should have a special DMD flag to enable alternate warnings.

Maybe call it.. -walter ?

;P

bearophile Wrote:

> Time ago an automatic tool has said that in a line of C code similar to:
> int r = x / y * z;
> 
> a division operator followed by a mult is confusing, and to add parentheses 
> to improve the code:
> int r = (x / y) * z;
> 
> 
> When values are integral the position of parentheses can change the value of 
> the expression:
> 
> void main() {
> int x = 10;
> int y = 3;
> int z = 5;
> assert(x / y * z == 15);
> assert((x / y) * z == 15);
> assert(x / (y * z) == 0);
> }
> 
> 
> Turning 'x / y * z' into a D syntax error (as done in bug  
> http://d.puremagic.com/issues/show_bug.cgi?id=4077 ) looks excessive to me. A 
> warning seems enough, but Walter is not a lover of warnings (and sometimes I 
> agree, I'd like to turn three D warnings into errors). What do you think?
> 
> Bye,
> bearophile



Re: A confusing expression?

2010-08-01 Thread bearophile
mwarning:
> Turning it into a syntax error sounds to be the right way to do to me.
> From a mathematical syntax pov, it's undefined behavior.

Thank you for your answer. You may be right, but this a hard sell :-)
I'd like to know what others think about it. Eventually if the conditions are 
fit I can restart this thread in the main D newsgroup...

Bye,
bearophile


Re: A confusing expression?

2010-08-01 Thread mwarning
On Sun, 01 Aug 2010 19:22:42 -0400, bearophile wrote:

> Turning 'x / y * z' into a D syntax error (as done in bug 
> http://d.puremagic.com/issues/show_bug.cgi?id=4077 ) looks excessive to
> me. A warning seems enough, but Walter is not a lover of warnings (and
> sometimes I agree, I'd like to turn three D warnings into errors). What
> do you think?

Turning it into a syntax error sounds to be the right way to do to me.
>From a mathematical syntax pov, it's undefined behavior.


A confusing expression?

2010-08-01 Thread bearophile
Time ago an automatic tool has said that in a line of C code similar to:
int r = x / y * z;

a division operator followed by a mult is confusing, and to add parentheses to 
improve the code:
int r = (x / y) * z;


When values are integral the position of parentheses can change the value of 
the expression:

void main() {
int x = 10;
int y = 3;
int z = 5;
assert(x / y * z == 15);
assert((x / y) * z == 15);
assert(x / (y * z) == 0);
}


Turning 'x / y * z' into a D syntax error (as done in bug  
http://d.puremagic.com/issues/show_bug.cgi?id=4077 ) looks excessive to me. A 
warning seems enough, but Walter is not a lover of warnings (and sometimes I 
agree, I'd like to turn three D warnings into errors). What do you think?

Bye,
bearophile


Re: Initializing static arrays without specifying size

2010-08-01 Thread bearophile
Ziad:

> Is there a way to let the compiler automatically determine the size
> based on the argument list?

I don't know a clean way to do it. See the "related enhancement" here:
http://d.puremagic.com/issues/show_bug.cgi?id=3849
With other people I have proposed the syntax:
int[$] a = [1, 2, 3];

But so far Walter has not shown interest.

Bye,
bearophile


Re: Doubled newlines

2010-08-01 Thread Jonathan M Davis
On Sunday 01 August 2010 05:12:04 bearophile wrote:
> Jonathan M Davis:
> > So, while Wnidows is arguably more correct, it causes
> > problems and is arguably inferior.
> 
> The point is that probably there is a newline-related bug somewhere in
> Phobos and I'd like to find it.

Oh, I don't disagree. I'm just pointing out the situation with the various end-
of-line characters on the various OSes. It sounds like the two character 
solution of Windows might be messing things up somewhere, but I was just 
pointing out the character situation. However, the error does indeed need to be 
found and fiixed.

- Jonathan M Davis


Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-08-01 Thread Jonathan M Davis
On Sunday 01 August 2010 07:36:27 Jason Spencer wrote:
> == Quote from Jonathan M Davis (jmdavisp...@gmail.com)'s article
> 
> > For logic errors, efficiency isn't really an issue, since they
> > shouldn't be happening. If they are, go fix your code and it won't
> > be an issue.
> 
> That gets less true as the cost of a try block goes up.  Even if logic
> errors never occur, the infrastructure to check for them costs you
> something.  Ever compared the performance of a program w/ and w/o
> trys?
> 
> So, would you advocate for exceptions as the sole error reporting
> mechanism?  Return values are just for valid result values and
> everything else is an exception?  Where do you personally draw the
> line?
> 
> Jason

It really depends on what you're doing. I do think that exceptions are the 
better way to go, but it tends to be dangerous to say things like "always" and 
"never." Generally, however, I would use return for valid results only and use 
exceptions for errors. However, if error cases become very likely, then 
exceptions do tend to become a poorer solution since you don't want to be 
throwing lots of exceptions. Also, there are cases where you can take an error 
and simply turn it into a default value (particularly for things like parsing 
and conversion functions) if that's acceptable.

Still, I think that it generally makes for better code when you assume that the 
returned data is correct and then let exceptions deal with the error cases - 
particularly when dealing with user input and file I/O. And in such cases, 
efficiency is not generally the greatest concern. If you had cases where 
efficency 
was a great concern, then it might be worth looking at whether exceptions were 
the best way to handle things, but in the general case, I believe that they are.

As to where exactly I draw the line, I'd really have to look at the code in 
question to make any kind of judgement call. However, I'm generally going to go 
with exceptions unless I have a good reason not to, and I've found such reasons 
to be fairly rare.

- Jonathan M Davis


Initializing static arrays without specifying size

2010-08-01 Thread Ziad
Hi all,

I was wondering how I would go about initializing a static array
without explicitly specifying how big it is, given I lay out the
contents.

For example, if I do:

int[] a = [1, 2, 3, 4, 5];
auto a = [1, 2, 3, 4, 5];

both statements would result in a heap allocated array (slice). If I
want a static array:

int[5] a = [1, 2, 3, 4, 5];

I'd have to specify the size in advance (5 in this case), which
means that adding extra elements later on would require that the
size be update.

Is there a way to let the compiler automatically determine the size
based on the argument list?


Sections in Ddoc?

2010-08-01 Thread Philippe Sigaud
Hi,

as per Nick's advice, I was reading on Goldie's GenDocs template documentation 
system:

http://www.semitwist.com/goldiedocs/v0.3/Docs/Tools/GenDocs/TemplateFormat/

That's a nice work, and I saw there something I'd like to do with Ddocs: 
sections. As in, document sections.

Ideally there are some modules I'd like to document that way:


Module Name

some general documentation on the module, what its use is supposed to be, the 
things to do, etc. Imagine an algorithm
module, for example.

Section #1 - Sorting.
general documentation on the section, a specific part of the module. Say, 
sorting.

functions documentation for section 1.

Section #2 - Finding.
another subject there, say finding elements in a range... General explanations 
on the modules assumptions, trade-off, etc.

functions documentation for section 2.

an so on...

But I cannot do that with DDocs. Or can I?
Does anyone know a way to do this?

(ideally, I'd also like a summary-like part, like in Wikipedia :) )

Philippe


Re: alias = compile-time variants?

2010-08-01 Thread Philippe Sigaud
On Sat, Jul 31, 2010 at 21:17, Lutger  wrote:

> Jason Spencer wrote:
>
> > == Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article
> >> --0016e6d58a039d35e2048c9aa7e2
> >>
> >> I thought they could only be symbols. That is, an alias is a 'link',
> > a sort
> >> of pointer to a symbol: a template name, a module name, a function
> >> name, etc.
> >
> > Whatever confidence you inspired by removing type from the list is
> > quickly lost and more when you add module name--I hadn't thought of
> > that! :)
>

I discovered it by error, IIRC. That and the fact that template-like
statements like

auto members = __traits(allMembers, std.stdio);

work.  Try it, print the result. Though I do not know what to do with it :)


> >
> >
> >> Wisdom, I don't know, as I still feel like I'm exploring things. But
> >> template constraints are there to limit what you can instantiate.
> >> ...
> >> Say I have a template that takes an alias, fun, and a type, T.
> >> fun is supposed to be a function, but in fact why limit it to that?
> >> What I need is for foo to be callable with a T. So let's test for
> >> that:
> >> auto doSomething(alias fun, T)(T t)
> >> if (is(typeof( fun(T.init) )))
> >> {
> >> // now that I'm here, I can freely use fun as a callable on any T
> >>  auto result = fun(t);
> >> // ...
> >> }
> >
> > I understand this example, and (most of) the mechanics of constraints.
> > What I'm not so sure about is the recommended practice around their
> > use.  I see lot's of code that doesn't check those things.  Suppose
> > you left off the constraint and did:
> >
> > class Foo(U){}
> > doSomething!(Foo, int)(3)
> >
> > it seems like there's a good chance you could get:
> >
> > auto result = Foo!(int);  // type inferred from 3
> >
> > (since this doesn't actually work like I'm saying, please conveniently
> > imagine a similar case that does. :)
>
> Sure, but that would be quite a gotcha since you went from calling
> something to
> merely instantiating a template. Perhaps there are such gotcha's, I am not
> aware
> of them.
>

You can test for the alias to be a function (is(typeof(a) == function)), a
delegate, or you can test for the presence of an opCall operator (the '()'
operator), with __traits(hasMember, alias, "opCall")
I think there should be a isCallable trait in Phobos...
But in the opCall case, the gotcha is the class templates are not classes.
Only instantiated classes are really classes.
That is, given

class C(T)
{
 T t;
 T opCall(T u) { return t;}
}

__traits(hasMember, C, "opCall") will answer 'false'. That's normal, since C
is not a class, but a template, of type void.
__traits(hasMember, C!int, "opCall") will answer 'true'.





>
> > Even with your constraint, I'm not sure I feel any more comfortable.
> > If it compiles in the body of doSomething, it will compile in the
> > constraint--not sure I've added any value.
>
> Perhaps not in this case, but:
> - constraints add documentation, such as isInputRange!T or IsCallable!fun
> - you can add a constraint that may not be statically checked inside the
> body of
> the template. This way you can still reject template parameters considered
> to be
> invalid even if the template body *could* be instantiated with them.
>

I never thought of that.


> - a constraint is a nice place to add better compiler error messages
>

Except the compiler just say it cannot instantiate the template
NameWithConstraints.



> > So how do you sleep at night not knowing if there's some funky syntax
> > on somebody's template-that-takes-a-template which, when combined with
> > some inference, might look like your function call on a value param?
> > My initial reaction is to specify the hell out of the constraints, but
> > I couldn't beat the feeling I was going overboard.  I suspect that
> > most people rely on the fact that most improper calls won't compile.
>

Yes.


> > Maybe I'm still too new to the syntax to have a good feel for what
> > will get caught, and what could interpreted by the compiler in
> > multiple ways depending on the actual arguments.
>

I have nothing against long and well-documented constraints. I feel we are
not using them as much as we could. With things like staticMap and such, you
can do a lot!



> >
> > So, do folks write constraints to ensure that modules don't get passed
> > to their templates?  :)
> >
> > Jason
>
> Why not? As long as your module does the right thing, it may be used to
> instantiate my template :)
>

You can try to define an isTemplate template, and a isModule template :-)

Look at this:

T foo(T)(T t) { return t;}

class C(T)
{
T t;
T opCall(T u) { return t;}
}

template Describe(alias a)
{
enum string Name = a.stringof;
enum string Ident = __traits(identifier, a);
}

void main()
{
writeln(Describe!(foo).Name); // foo(T)
writeln(Describe!(foo).Ident); // foo
writeln(Describe!(C).Name); // C(T)
writeln(Describe!(C).Ident); // C
writeln(Describe!(C!int).Name); // C (really, I thought t

Re: xfbuild, optlink and pragma(lib)

2010-08-01 Thread div0

On 01/08/2010 16:22, Mafi wrote:

libSDL.dll.a is a MingW- or Cygwin-compiled link library. That's not
going to work on Windows with DMD and may very likely be the source of
your problem. If you want to link with a DLL link lib, then you need to
get the tool coff2omf[1] (part of the Extended Utilities Package[2]) run
it on SDL.lib (I suppose it might work on SDL.dll.a), and link with the
resulting converted file. Either that or compile SDL with DMC.

Alternatively, you could modify your binding to load SDL dynamically
like Derelict does. Then you don't need to fool around with any link
libs. But, you do need a fair amount of implementation code to load the
function symbols from the DLL.

[1] http://www.digitalmars.com/ctg/coff2omf.html
[2] http://www.digitalmars.com/download/freecompiler.html


The tool sounds cool but it seems that I have to buy it, so that's no
option for me. So I tried to compile SDL myself. I have to say I'm to
stupid for it. I tried to do the same thing as the makefile in
powershell. After I hacked together some solution that worked dmc
complained about missing Gl.h. It isn't there. So I added some MinGW to
the include-path and then I get a bunch of errors in SDL without
linenumbers. And anyways I am trying to compile it without MinGW, aren't
I. Please, help me!


Just use Derelict and save yourself a world of grief.

http://dsource.org/projects/derelict

Compiling C libs with dmc is easy if you are an experenced C developer,
but it's a nightmare if you aren't.


Re: Doubled newlines

2010-08-01 Thread div0

On 01/08/2010 18:22, div0 wrote:

On 01/08/2010 13:12, bearophile wrote:

Andrej Mitrovic:

The point is that probably there is a newline-related bug somewhere in
Phobos and I'd like to find it.

Bye,
bearophile


Yeah there is.

I get doubled new lines as well when passing a handle opened with fopen
to a CFile thingy.


That's on XP btw


Re: Doubled newlines

2010-08-01 Thread div0

On 01/08/2010 13:12, bearophile wrote:

Andrej Mitrovic:

The point is that probably there is a newline-related bug somewhere in Phobos 
and I'd like to find it.

Bye,
bearophile


Yeah there is.

I get doubled new lines as well when passing a handle opened with fopen 
to a CFile thingy.


Re: xfbuild, optlink and pragma(lib)

2010-08-01 Thread Mafi

libSDL.dll.a is a MingW- or Cygwin-compiled link library. That's not
going to work on Windows with DMD and may very likely be the source of
your problem. If you want to link with a DLL link lib, then you need to
get the tool coff2omf[1] (part of the Extended Utilities Package[2]) run
it on SDL.lib (I suppose it might work on SDL.dll.a), and link with the
resulting converted file. Either that or compile SDL with DMC.

Alternatively, you could modify your binding to load SDL dynamically
like Derelict does. Then you don't need to fool around with any link
libs. But, you do need a fair amount of implementation code to load the
function symbols from the DLL.

[1] http://www.digitalmars.com/ctg/coff2omf.html
[2] http://www.digitalmars.com/download/freecompiler.html


The tool sounds cool but it seems that I have to buy it, so that's no 
option for me. So I tried to compile SDL myself. I have to say I'm to 
stupid for it. I tried to do the same thing as the makefile in 
powershell. After I hacked together some solution that worked dmc 
complained about missing Gl.h. It isn't there. So I added some MinGW to 
the include-path and then I get a bunch of errors in SDL without 
linenumbers. And anyways I am trying to compile it without MinGW, aren't 
I. Please, help me!


Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-08-01 Thread Jason Spencer
== Quote from Jonathan M Davis (jmdavisp...@gmail.com)'s article
> For logic errors, efficiency isn't really an issue, since they
> shouldn't be happening. If they are, go fix your code and it won't
> be an issue.

That gets less true as the cost of a try block goes up.  Even if logic
errors never occur, the infrastructure to check for them costs you
something.  Ever compared the performance of a program w/ and w/o
trys?

So, would you advocate for exceptions as the sole error reporting
mechanism?  Return values are just for valid result values and
everything else is an exception?  Where do you personally draw the
line?

Jason


Re: Doubled newlines

2010-08-01 Thread bearophile
Andrej Mitrovic:

> I'm getting normal newlines here (XP):

Thank you for your test. Then maybe it's a problem that comes out on Windows 
Vista only, I don't know.

-

Jonathan M Davis:

> So, while Wnidows is arguably more correct, it causes
> problems and is arguably inferior.

The point is that probably there is a newline-related bug somewhere in Phobos 
and I'd like to find it.

Bye,
bearophile


Re: Naming suggestion for this particular delegate/function

2010-08-01 Thread Kagamin
Bruno Medeiros Wrote:

> What would you call such a function parameter (either for map or just 
> generally). That is, what would you call a function that takes one 
> parameter of some type, and produces another object/data from that input?

transform


Re: xfbuild, optlink and pragma(lib)

2010-08-01 Thread Mike Parker

Mafi wrote:



When I comment out the pragma(lib) optlink fails (correctly) and xfbuild 
crashes (:-(). Then I call optlink myself with libsdl.dll.a and it 
creates a corrupt exe without errormessages.


Please help me. It seems that there are bugs over bugs. I don't konw 
what to do.


I use Windows 7, dmd (2.047), xfbuild with cmd/powershell.


libSDL.dll.a is a MingW- or Cygwin-compiled link library. That's not 
going to work on Windows with DMD and may very likely be the source of 
your problem. If you want to link with a DLL link lib, then you need to 
get the tool coff2omf[1] (part of the Extended Utilities Package[2]) run 
it on SDL.lib (I suppose it might work on SDL.dll.a), and link with the 
resulting converted file. Either that or compile SDL with DMC.


Alternatively, you could modify your binding to load SDL dynamically 
like Derelict does. Then you don't need to fool around with any link 
libs. But, you do need a fair amount of implementation code to load the 
function symbols from the DLL.


[1] http://www.digitalmars.com/ctg/coff2omf.html
[2] http://www.digitalmars.com/download/freecompiler.html


Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-08-01 Thread bearophile
Jason Spencer Wrote:
> Unless D has made great strides in exception
> performance (which is entirely possible),

>From my tests dmd exceptions are more than ten times slower than Oracle-Java 
>ones. I have test code.

Bye,
bearophile


Re: xfbuild, optlink and pragma(lib)

2010-08-01 Thread Mafi

Ok,
OPTLINK is the problem. Without linking SDL, it complains about missing 
symbol (good) and creates a corrupt executable (so-so). With linking SDL 
in any way (explicitly or with pragma(lib)) it shows no errormessage 
(really bad) and does not create any executable (bad).

Should I fill a bug report or am I doing something wrong?



Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-08-01 Thread Pluto
== Quote from Jonathan M Davis (jmdavisp...@gmail.com)'s article
> On Saturday 31 July 2010 20:15:58 Jason Spencer wrote:
> > == Quote from Dmitry Olshansky (dmitry.o...@gmail.com)'s article
> >
> [...snip]
> >
> > Just a thought.
> > Jason
> I honestly don't think that exception handling is a particularly expensive
> solution in most cases. When dealing with an error, it's likely to either be
> related to I/O (be it an actual I/O error or input from a user or file) or a
> logic error in the code.
I have seen code which tries toInt and then does toFloat in the catch. Not sure
whether it was just bad code (looks like it though) but there are probably some
examples where people really don't know what kind of data they are handling and
use std.conv to try.
Not really sure about that now that I think about it.
~~
:Pluto



Re: Casting an expression to bool means testing for 0 or !=0 for arithmetic types

2010-08-01 Thread Pluto
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> Pluto  wrote:
> > == Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article
> >> Pluto  wrote:
> >> > This part has always bothered me. Could somebody please explain to me
> >> the
> >> > rationale behind limiting functions to one usable error code?
> >> Well, traditionally it was done because testing for 0/non-0 is a simple
> >> and fast operation.
> > So speed it is. Was <1 really slower back then?
> Likely not. But the assembly is easier:
> jnz ; vs cmp EAX 0; jg ;
That might explain things.

> >> Also, boolean logic can be thought of as simple maths,
> >> as AND is multiplication and OR is addition. This only makes sense if
> >> false == 0.
> > false < 1, is what I would expect.
> > It even makes it more symmetrical.
> How?
> Let's start out with a false value f of -1. Now AND it with itself
> (f * f), and you get 1, which is true. This does not seem correct.
Not knowing anything about assembler(and ignoring history), this seems sensible 
to me:
f is an integral, not a boolean. For it to work like a boolean it needs a cast,
implicit or explicit:
cast(bool); >0?true:false
if(returnsErrorCodes()); implicit cast from return value to bool
f*f; integral operation and should return the multiplication
f&f; bitwise operation and should return bitwise AND
cast(bool) f & cast(bool) f; bitwise operation on booleans
~~
:Pluto



Re: Naming suggestion for this particular delegate/function

2010-08-01 Thread Philippe Sigaud
On Sat, Jul 31, 2010 at 20:07, Bruno Medeiros
 wrote:

> Consider the familiar functional idiom "map" (
> http://en.wikipedia.org/wiki/Map_%28higher-order_function%29)
>
> What would you call such a function parameter (either for map or just
> generally).


What parameter?



> That is, what would you call a function that takes one parameter of some
> type, and produces another object/data from that input?
>

Do you mean the partial application of map, is in D with map!"a*a" ?
(without any argument).


Is there any usual name/term for this, I wonder, or not really?
>
>
Not sure if I'm saying something obvious to you, but map is a higher-order
function: a function that acts on functions, either taking them as
parameter(s) or as results. So are filter, fold/reduce, unfold, scan,
compose, power (of a function: power(f, n) = f(f(f(... n times)))
For map, filter or reduce, the function is just a parameter among two. Most
of the time, what they create is not a function.

In curried language like Haskell, you can easily create the partial
application of a function: n-args functions are in fact n 1-arg functions
each delivering the next step (a function).
So map x*x [0,1,2,3,4] is [0,1,4,9,16], but map x*x is a function, waiting
for an iterable and returning its transformation through x*x. In not-curried
language, map x*x is considered a partial application of map.

Note in D the asymmetry between the function which is a compile-time
argument and the range, a runtime argument. A recent change in Phobos (for
the next release) by Andrei will allow us to do:

alias map!"a*a" squarer; // squarer is a _generic_ function taking any
range, as long as the operation a*a makes sense for the range elements.


Before, we could do this with reduce, but not map and filter. That was
originally to avoid a bug in the compiler :-) but it's easy to code and very
useful.

We could have a map(fun, range) in D, I guess. Gone the currying, but
welcome runtime functions.

Philippe