merits of Lisp vs Python

Ken Tilton kentilton at gmail.com
Thu Dec 14 01:25:00 EST 2006



Ken Tilton wrote:
> 
> 
> Paul Rubin wrote:
> 
>> Ken Tilton <kentilton at gmail.com> writes:
>>
>>> don't know. The point is, we need code (not just data) in defskill
>>> (apologies for nasty formatting):
>>
>>
>>
>> Man that whole thing is messy.

I do not see much difference, except that the character count is 25% 
less in the macro version:

(defskill absolute-value
     (title "Absolute Value")
   (annotations
    "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
    "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)))))

(defmethod skill-title ((tf-id (eql 'absolute-value)))
   (list "absolute value"))

(defmethod skill-annotations ((tf-id (eql 'absolute-value)))
   (list "absolute value of #strn# is the 'distance' of #strn# from zero."
     "absolute value is always zero or positive: #strn=n#, and #str-n=n#."))

(defmethod skill-hints ((tf-id (eql 'absolute-value)))
   (list "some examples: #str+42=42#, #str-42=42#, and #str0=0#."
     "to get the absolute value of a number such as #signed-value#, we 
simply drop any minus sign."))

(defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds)
   (declare (ignorable resx opnds))
   (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)))))


Let's lose the strings and count again, since they are a fixed cost. OK, 
now the macro version is 30% shorter.

>>  I can't for the life of me understand
>> why it's so important to use a macro for that.

Pythonistas, when arguing about macros, always seem to forget that one 
of the primary design imperatives of Python is cleaner code. Indentation 
is use to avoid single characters { and }. But when macros come up you 
all suddenly become the Mavis Beacon of programmers.

And, again, perhaps the bigger thing going on here is that the 30% is 
boilerplate code representing implementation, which can change.

I don't know, perhaps the best argument against macros is that no 
Pythonista wants them. That is actually a damn good reason.

ken

-- 
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