Super-dee-duper D features

X Bunny xbunny at eidosnet.co.uk
Wed Feb 14 04:20:57 PST 2007


Kevin Bealer wrote:
> 
> Actually, I can understand the structure in both languages for this 
> simple example without too much trouble.  But the LISP one is a lot 
> 'slower' for me to scan with my eyes.  Some of that is a learned reflex, 
> of course, but personally I don't think all of it is.
> 
> My point is less about indentation than the other aspects of syntax. For 
> one thing, the '(){};,' punctuation, which for me, is a win over the 
> LISP way (again, assuming both examples are indented).  If the LISP 
> syntax is readable for you throughout, then that's okay.  For me it 
> definitely isn't -- I think most people would agree.

I certainly see your point and accept it.

I think its worth noting the Lisp 'if' isnt neccasarily the same as the 
C like one though, I suppose its closer actually to the ternary 
operator. This lisp expression:

(quite possibly the indentation will screw again in which case Im sorry)

(let ((k (if (if (zerop x)
	       (foo 100)
	     (bar 100))
	   (zen 30)
	 (wibble q)))))

would be like this C (I think!):

k = ((x == 0) ? foo(100) : bar(30)) ? zen(30) : wibble(q));

Using the structured C 'if' you get:

int t;
if(x == 0)
   t = foo(100);
else
   t = bar(100);

int k
if(t)
   k = zen(30);
else
   k = wibble(q);

I prefer the Lisp, the ternary version is bizarre to read and the 
structured if version fails to properly show how the first if expression 
controls the second, you have to memorize (and use for that matter) the 
temporary variable which represents the nested expression.

Regarding how its useful to have different bracket types to delimit the 
layout, I think thats a decent point, Im pretty sure there is an editor 
mode which colours each nested level of parans a different colour I 
think that would acheive a similar thing.

> 
> Someone I know at work told me today that the LISP notation is very much 
> like mathematical formulas.  I couldn't help remembering math classes in 
> college, when (at the time) I was always thinking, 'why can't they break 
> this up into simple steps like a computer program would?'  (Of course, I 
> learned a lot about programming before I took algebra, so maybe that's 
> part of the problem.)

Its an interesting observation, I learnt algebra before computer 
programming and also learnt computer programming without a specific 
language. My introduction to Computer Science was entirely theoretical; 
we learnt all about computers and programming without ever actually 
touching a computer (seems kinda bizarre now I think about it - we did 
have computers!) I didnt start programming seriously until after I left 
school. My first practical programming experience was Sinclair Basic, 
then some Lispish language on a programmable calculator, then Zortech C. 
I always prefered to write math formulas in something like Lisp (ie 
prefix, no precedence rules, no funky math syntax) my teachers hated it. 
When I first tried to learn C it took me ages to get my head around all 
the different bits of syntactic sugar, precedence rules and unexpected 
corner cases. I dont have a problem with that now but certainly if I do 
have something mathematical to write or a complicated algorithm to 
devise I often sketch it out in Lispish form first or fire up Lisp and 
program until I get an understanding of how its going to work before 
starting the C++.

Bunny



More information about the Digitalmars-d mailing list