Super-dee-duper D features

Brad Anderson brad at dsource.org
Tue Feb 13 20:24:33 PST 2007


Walter Bright wrote:
> X Bunny wrote:
>> (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.
> 
> I see:
>     1- x
> in the Lisp code, and have to mentally translate it to:
>     x - 1
> and not:
>     1 - x
> 
> This just hurts my brain.

The first atom is the function to operate on the rest of the args.

(defun (subtract-one-from-it x)
  (- x 1))

(subtract-one-from-it 43) -> 42

(defun (1- x)
  (- x 1))

(1- 43) -> 42

same thing, first one is more verbose.  Maybe this was a bad example?

(+ 2 3 1) -> 6

(defun (who-is-the-bomb boorad kris sean_k)
   boorad)

BA



More information about the Digitalmars-d mailing list