merits of Lisp vs Python

Ken Tilton kentilton at gmail.com
Thu Dec 14 02:11:46 EST 2006



Paul Rubin wrote:
> Ken Tilton <kentilton at gmail.com> writes:
> 
>>>Man that whole thing is messy.  I can't for the life of me understand
>>>why it's so important to use a macro for that.  Even in Lisp, I'd
>>>probably set up the reverse thingie as an auxiliary function.
>>
>>And when you got to skill 42 and you discovered you needed a new
>>optional argument to the reversal method you would throw up your hands
>>and register for bartending school rather than go edit the other 41.
> 
> 
> I don't see the problem.  Python uses keyword args sort of like
> Lisp's, and the called function (if it asks) receives a dictionary
> containing any keyword args not bound explicitly in the arg list.
> So you can invent new args whenever you want.

I am not making this up. I just decided to change the signature to the 
reversal function(s). I had been clever, trying to pass in just what I 
deemed necessary from a transformation (TF) data structure that needed 
reversing, now I recall -- because I needed something else from the TF 
-- I should never try to be smart, just pass in the whole frickin TF (duh).

So this:
     (defmethod tf-reverse (id (eql ',sub-id)) resx (drv-opnds tf drv))
         , at reverser)

becomes this:

     (defmethod tf-reverse ((id (eql ',sub-id)) tf drv
                         &aux (opnds (drv-opnds tf drv)))
        (loop for resx in (results drv)
          , at reverser))

I pass in drv (a derivation, a part of a transformation) because (I 
forgot) reversal code has to reverse each derivation of a TF separately.

In the new macroexpansion I preserve the bindings RESX and OPNDS 
expected by the 41 (not really, but it could be) existing uses of the 
defskill macro, and then <gasp> move an iteration across possible 
multiple results (RESXs) of a TF into the generate tf-reverse method 
(and the poor body of code has no idea I did that).

At this point if I had to redo these manually we can forget bartending 
school, I'd be going straight to the Betty Ford clinic .

btw, you called the defskill messy (repeated below) "messy". The only 
text not specific to absolute value is D-E-F-S-K-I-L-L. Expanding that 
into "tidy" separate methods adds 25% of dead weight boilerplate. In 4-5 
separate toplevel definitions instead of one. How is that less messy?

ken

(defskill absolute-value
     (title "Absolute Value")
   (annotations
    "Take the absolute value of #signed-value#."
    "The vertical bars around #signed-value# mean 'the absolute value 
of' #signed-value#."
    "Absolute value of #strn# is the 'distance' of #strn# from zero."
    "Absolute value is always zero or positive: #str|n|=n#, and 
#str|-n|=n#.")
   (hints
    "What do those vertical bars around #signed-value# mean?"
    "Have you learned about 'absolute value'?"
    "Absolute value can be thought of as the 'distance' of a value from 
zero on the number line, and distance is always positive."
    "The rule is:#str|-n|=|n|##str=n#.  Can you apply that to 
#signed-value#?"
    "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#."
    "To get the absolute value of a number such as #signed-value#, we 
simply drop any minus sign.")
   (reverse
    (ensure-cloning resx
      (make-instance 'mx-number
        :value (loop with op1 = (car opnds)
                   with log = (max 1 (ceiling (log (abs (value op1)) 10)))
                   for n = (* (signum (value op1))
                             (+ 2 (random (expt 10 log))))
                   when (/= n (value op1))
                   return n)
        :representation (representation resx)))))




-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon



More information about the Python-list mailing list