Super-dee-duper D features
X Bunny
xbunny at eidosnet.co.uk
Tue Feb 13 15:36:49 PST 2007
Kevin Bealer wrote:
> X Bunny wrote:
>> Kevin Bealer wrote:
>>>
>>> 2. The syntax doesn't provide visual hints that let you read a program.
> What I mean, is this (from the Computer Language Shootout):
>
> (defun ack (x y)
> (declare (fixnum x y))
> (the fixnum
> (if (zerop x)
> (1+ y)
> (if (zerop y)
> (ack (1- x) 1)
> (ack (1- x) (ack x (1- y)))))))
>
> as compared to this:
>
> int Ack(int x, int y)
> {
> if (x == 0) {
> return y + 1;
> } else if (y == 0) {
> return Ack(x-1, 1);
> } else {
> return Ack(x-1, Ack(x, y-1));
> }
> }
>
> These two things do the same thing in the same way, but the structure
> and syntax make the C example much more readable. If I want to know
> input and output types, I can find them. When I see the top of the
> if/elseif/else structure, I can find each part. It's layed out like a
> table, rather than like a ball of yarn.
If the C was indented like this would it be as unreadable as the Lisp?
int ack(int x, int y)
{
if(x == 0)
{ return y + 1; }
else if(y == 0)
{ return ack(x-1, 1); }
else {
return ack(x-1, ack(x, y-1));
}
}
(I cant even match up all the brackets with that one!)
My editor indents the Lisp like this:
(defun ack (x y)
(declare (fixnum x y))
(the fixnum
(if (zerop x)
(1+ y)
(if (zerop y)
(ack (1- x) 1)
(ack (1- x) (ack x (1- y)))))))
The structure is no less obvious to me then the C. I can see the input
and output types are clearly fixnums. The branches of the ifs are obvious.
>
> More importantly, I can understand *parts* of this code without
> understanding the whole thing.
Mmmm I dont what to say about that, for me with the Lisp I can do the same.
Bunny
More information about the Digitalmars-d
mailing list