merits of Lisp vs Python

K

Ken Tilton

Ken said:
But you could have just flipped thru the rest of the pages to see if he
/had/ gone nuts with them!



One has to be from the US and of a certain age to remember this, but
this old line from a commercial for high-octane gasoline says it for me:
power to be used, not abused.

Here is a bit of concrete I just tossed off:

(defmacro defskill (id &body skill-info)
`(progn
,@(loop with sub-id = id
for (q . q-def) in skill-info
collecting
(ecase q
((title annotations hints)
`(defmethod ,(intern (conc$ 'skill- q)) ((tf-id (eql
',sub-id)))
,@q-def))))))

It lets me code this:

(defskill absolute-value
(title "Absolute Value")
(annotations
"Take the absolute value of #op#."
"The vertical bars around #op# mean 'the absolute value of' #op#."
"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 #op# 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 #op#?"
"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#."
"To get the absolute value of a number such as #op#, we simply drop
any minus sign."))


....and get this:

(PROGN
(DEFMETHOD SKILL-TITLE ((TF-ID (EQL 'ABSOLUTE-VALUE)))
"Absolute Value")
(DEFMETHOD SKILL-ANNOTATIONS ((TF-ID (EQL 'ABSOLUTE-VALUE)))
"Take the absolute value of #op#." "The vertical bars around #op#
mean 'the absolute value of' #op#."
"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)))
"What do those vertical bars around #op# 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 #op#?" "Some
examples: #str+42=42#, #str-42=42#, and #str0=0#."
"To get the absolute value of a number such as #op#, we simply
drop any minus sign."))

The above is how my upcoming death-defying interactive Algebra
tutor-in-a-drum ("You'll laugh! You'll cry!") will know how to coax some
befuddled teen through |-42| -> 42 if they get stuck. And a hundred
other subskills (so there will be a hundred of these definitions).

If I hire someone they will look at defskill and not fall to the ground
frothing at the mouth. They likely will not even macroexpand it because
it is self-explanatory. If they wonder if there are other options they
can alt-. to the source. The language has been extended, but I followed
a pattern familiar to Lispniks. Zero confusion results.

If I decide not to use generic method dispatch to "look up" the hints I
just have to change the macro and then write a DEFUN (no dispatch on
type) to, say, look up the symbol in a hash table.

hth,ken

ps. I won't mention the other benefit, which is that I want educators to
edit these if they have a better idea on how to tutor absolute value. I
am not mentioning it because I am as impatient with superfluous syntax
as a non-programmer would be. k

pps. How would Python do this? Is it possible to avoid committing to an
implementation mechanism? Compare and contrast. k

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

Paul Rubin

Ken Tilton said:
pps. How would Python do this? Is it possible to avoid committing to
an implementation mechanism? Compare and contrast. k

You'd just write a function. Python's expression syntax is comparable
to a Lisp reader (you can have nested values of mixed types etc.) so
you can use Python expressions to initialize pretty much anything.
 
G

greg

Ken said:
pps. How would Python do this?

Here's one way it could look:

defskill("absolute-value",
title = "Absolute Value",
annotations = [
"Take the absolute value of #op#.",
"The vertical bars around #op# mean 'the absolute value of' #op#.",
"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 #op# 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 #op#?",
"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#.",
"""To get the absolute value of a number such as #op#, we simply drop
any minus sign."""
]
)
> Is it possible to avoid committing to an
> implementation mechanism?

The defskill function could do just about anything with this.
Here's one possibility:

skills = {}

class Skill:
pass # fill in whatever methods you need here

def defskill(name, title, annotations, hints):
skill = Skill()
skill.title = title
skill.annotations = annotations
skill.hints = hints
skills[name] = skill

This gives you a dictionary of Skill instances indexed by name,
each one having a title and lists of annotation and hint strings.
The rest of the system can process this however required.
 
K

Ken Tilton

greg said:
Ken said:
pps. How would Python do this?


Here's one way it could look:

defskill("absolute-value",
title = "Absolute Value",
annotations = [
"Take the absolute value of #op#.",
"The vertical bars around #op# mean 'the absolute value of' #op#.",
"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 #op# 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 #op#?",
"Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#.",
"""To get the absolute value of a number such as #op#, we simply drop
any minus sign."""
]
)
Is it possible to avoid committing to an
implementation mechanism?

The defskill function could do just about anything with this.
Here's one possibility:

skills = {}

class Skill:
pass # fill in whatever methods you need here

def defskill(name, title, annotations, hints):
skill = Skill()
skill.title = title
skill.annotations = annotations
skill.hints = hints
skills[name] = skill

This gives you a dictionary of Skill instances indexed by name,
each one having a title and lists of annotation and hint strings.
The rest of the system can process this however required.

Ok, not too bad, not much syntax in there. But now I have a tougher
requirement for you, which I noticed only after posting. (I tried
running the damn thing and it whined about not knowing how to "reverse"
absolute-value (to clone one problem into a similar problem).) A
reversal must be able to yield any given a result, and sometimes must
use given operands already settled on by the larger reversing algorithm.
In the simpler case, to reverse absolute-value with result 42 we produce
either |42| or |-42|. In the more complicated case, the multiply-literal
reverser may discover 6 is an operand and 42 is the result (meaning it
does no randomization, it just supplies the (* 6 7) reversal. Why am I
telling you all this? I don't know. The point is, we need code (not just
data) in defskill (apologies for nasty formatting):

(defmacro defskill (id &body skill-info)
`(progn
,@(loop with sub-id = id
for (q . q-def) in skill-info
collecting (ecase q
((title annotations hints)
`(defmethod ,(intern (conc$ 'skill- q))
((tf-id (eql ',sub-id)))
(list ,@q-def)))
(reverse
`(defmethod tf-reverse ((id (eql ',sub-id))
resx opnds)
(declare (ignorable resx opnds))
,@q-def))))))

--------------- (Abbreviated) Example.... ------------------------------

(defskill absolute-value
(title "Absolute Value")
(annotations
"Absolute value is always zero or positive: #str|n|=n#, and
#str|-n|=n#.")
(hints
"What do those vertical bars around #op# mean?")
(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)))))

-------------- Producing.... ---------------------------------


(progn (defmethod skill-title ((tf-id (eql 'absolute-value))) (list
"absolute value"))
(defmethod skill-annotations ((tf-id (eql 'absolute-value)))
(list "absolute value is always zero or positive: #strn=n#,
and #str-n=n#."))
(defmethod skill-hints ((tf-id (eql 'absolute-value)))
(list "what do those vertical bars around #op# mean?"))
(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)))))

How close can Python get when code is involved? The reverse function
signature is fixed, so can lambda help?

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
 
P

Paul Rubin

Ken Tilton said:
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 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.
 
K

Ken Tilton

Paul said:
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.

defskill is writing my code for me. When things change, I have it write
different code. Implementation is hidden, even from the programmer. I am
one step removed from the code when writing a macro. This is the "meta"
in metaprogramming.

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
 
P

Paul Rubin

Ken Tilton said:
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.
 
K

Ken Tilton

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.

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
 
P

Paul Rubin

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

The macro calls aren't so bad, but the macro definition is pretty
horrendous. There's no need to invent and program all that new syntax
when Python's existing syntax does the job perfectly well.
I don't know, perhaps the best argument against macros is that no
Pythonista wants them. That is actually a damn good reason.

I've wanted macros from time to time, but this isn't a situation that
calls for them. They're just less important in Python than in Lisp.
Python already has enough syntax to not constantly need new syntax
extensions.
 
K

Ken Tilton

Paul said:
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))
,@reverser)

becomes this:

(defmethod tf-reverse ((id (eql ',sub-id)) tf drv
&aux (opnds (drv-opnds tf drv)))
(loop for resx in (results drv)
,@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
 
P

Paul Rubin

Ken Tilton said:
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.

No, the messiness was not in the macro instantation (defskill blah...),
but in the defmacro that tells the compiler how to expand it. Python
function defs are lightweight enough that I don't experience a big pain
from using an extra one for a thing like that.
 
K

Ken Tilton

Ken said:
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)))))

Even better. That "(car opnds)" up there is an unpleasant hard-coding
that must align with how operands get recorded by the transformation
code that built the TF log entry that is being reversed. Ewww. What the
first opnds is supposed to be is the signed value of which the absolute
vale is being taken. Wouldn't it be nice to just say "signed-value"?:

We can just look at the reverse option now:

(defskill absolute-value
....
(reverse (signed-value)
(ensure-cloning resx
(make-instance 'mx-number
:value (loop with svn = (value signed-value)
with log = (max 1 (ceiling (log (abs svn) 10)))
for n = (* (signum svn)(+ 2 (random (expt 10 log))))
when (/= n svn)
return n)
:representation (representation resx)))))

A major point here is that the above (trust me) is the exact syntax of
FLET and LABELS in Lisp. The big hobgoblin (and precise objection
offered by GvR) is that macro use yields unrecognizably (in this case)
Lisp code. But we love lisp and its patterns, and one ethic for macro
writers is to follow those patterns in extending the language.

Maybe that poor horse can be allowed to rest in peace, or must we flog
it some more for youse people?

Now operands and results get tagged at TF time with symbols. How on
earth does a local variable of the same name get bound to the operand
logged at TF time? Easy, look it up. But where is the code? Not outside
the function; the caller of the reversal function does not know which
logged operand to pass in which function parameter position. So the
lookup code has to be in the reverse function source, like this:

(defmethod tf-reverse ((id (eql 'absolute-value)) tf drv
&aux (opnds (drv-opnds tf drv)))
(declare (ignorable opnds))
(let ((signed-value (tf-drv-lookup tf drv 'signed-value))) <=====
(loop for resx in (results drv) do
(ensure-cloning resx
(make-instance 'mx-number :value
(loop with svn = (value signed-value)
with log = (max 1 (ceiling (log (abs svn) 10)))
for n = (* (signum svn)
(+ 2 (random (expt 10 log))))
when (/= n svn) return n)
:representation (representation resx))))))

WordPerfect says thats 405 characters, 64 words vs 241/38 for the actual
source.

Now in this case I happen to be just starting on this mechanism, so i do
not really have 42 I do not have to change, but I am about to start
churning these things out and I expect refinements to continue.

No problem.

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
 
K

Ken Tilton

Paul said:
The macro calls aren't so bad, but the macro definition is pretty
horrendous.

(a) /Precisely/ :)

(b) Omigod, that macro is trivial (except I forgot how to reach out two
levels of backquote to get a parameter and had to kludge it!). You just
aren't used to thinking at a level where one is writing code to write code.

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
 
K

Ken Tilton

Paul said:
No, the messiness was not in the macro instantation (defskill blah...),
but in the defmacro that tells the compiler how to expand it.

Again, that is precisely the point of macrology (in cases like this).
When a pattern will repeat a sufficient number of times, and a function
cannot handle the job, we do a little extra work (write some meta-code)
to make dozens (or hundreds) of applications as minimalist as possible.

That makes them concise, readable, and maintainable.
Python
function defs are lightweight enough that I don't experience a big pain
from using an extra one for a thing like that.

Check out the latest, plz. The example has grown now beyond what a
function can do, I think. meanwhile, I have not seen how Python lets you
avoid revisiting dozens of instances when changes to a mechanism are
required.

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
 
J

jurgen_defurne

Ken said:
And it interesting that VB is almost three times "better" than Python,
and that a Honda could kick a Lamboghini's ass for it at Laguna Seca:

http://www.googlefight.com/index.php?lang=en_GB&word1=lamborghini&word2=ford

Come on, COBOL is a great language, even has macros (copy ... replacing)
and the worlds greatest case statement, evaluate. We are proud to be its
neightbor.

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

Well, Cobol still has the largest and most easy to comprehend system
for doing decimal arithmetic.

Jurgen
 
A

Andrew Reilly

You just
aren't used to thinking at a level where one is writing code to write code.

Firstly, I'm looking into lisp because my current python project is too
full of boilerplate :) and too slow. Coming from a C and assembler
background, I'm *used* to meta-programming, and do it all the time. I
even use python, Matlab and bash to write C, sometimes :)

However, in this particular instance, I'm inclined to wonder why
meta-programming is the right answer, rather than just doing all of the
interpolation and what-not at run-time, based on a big table of your
algebra rules? It's for output to a human, isn't it? It's not as though
it needs to be particularly fast?

Maybe I'm just not digging the example sufficiently. That's likely: I've
yet to write my first lisp program...

Cheers,
 
K

Ken Tilton

Andrew said:
Firstly, I'm looking into lisp because my current python project is too
full of boilerplate :) and too slow. Coming from a C and assembler
background, I'm *used* to meta-programming, and do it all the time. I
even use python, Matlab and bash to write C, sometimes :)

However, in this particular instance, I'm inclined to wonder why
meta-programming is the right answer, rather than just doing all of the
interpolation and what-not at run-time, based on a big table of your
algebra rules?

I am afraid I do not see what alternative you are suggesting. I
especially do not see how interpolation is in play.

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
 
P

Paul Rubin

Ken Tilton said:
Again, that is precisely the point of macrology (in cases like
this). When a pattern will repeat a sufficient number of times, and a
function cannot handle the job,

But this is not a case where a function can't handle the job.
Check out the latest, plz. The example has grown now beyond what a
function can do, I think. meanwhile, I have not seen how Python lets
you avoid revisiting dozens of instances when changes to a mechanism
are required.

I'm missing what the difficulty is.
 
K

Ken Tilton

Ken said:
I am afraid I do not see what alternative you are suggesting. I
especially do not see how interpolation is in play.

[Guessing pending your clarification] "Interpolation" does happen at
runtime. This not about the actually quite rare use of macrology to move
certain calculations to compile time, this is about getting dozens of
transformation-specifc rules written to fit into a larger mechanism (by
having the right arguments and returning the right kinds of results,
with a minimum of boilerplate and a maximum of resiliency in the face of
refactoring.

The reason I post macro expansions along with examples of the macro
being applied is so that one can see what code would have to be written
if I did not have the defskill macro to "write" them for me. I sugest
one start there, by comparing before and after.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top