Python syntax in Lisp and Scheme

james anderson james.anderson at setf.de
Tue Oct 7 18:16:06 EDT 2003


Eli Barzilay wrote:
> 
> Matthias Blume <find at my.address.elsewhere> writes:
> 
> ...
> >
> > This is false.  Writing your own macro expander is not necessary for
> > getting the effect.  The only thing that macros give you in this
> > regard is the ability to hide the lambda-suspensions.  To some
> > people this is more of a disadvantage than an advantage because,
> > when not done in a very carefully controlled manner, it ends up
> > obscuring the logic of the code.  (Yes, yes, yes, now someone will
> > jump in an tell me that it can make code less obscure by "canning"
> > certain common idioms.  True, but only when not overdone.)
> 
> (This hits one of the major differences between Lisp and Scheme -- in
> Lisp I'm not as happy to use HOFs because of the different syntax

which difference differnt syntax?

> (which is an indication of a different mindset, which leads to
> performance being optimized for a certain style).  Scheme is much more
> functional in this respect, for example -- using HOF versions of
> with-... compared to Lisp where these are always macros.)

in practice, as a rule, a with- is available at least optionally also as a
call-with-. not just for convenience, but also for maintainability.

in the standard there are but twelve of these. should they be an impediment,
in most cases there is nothing preventing one from writing call-with-...
equivalents. many expand fairly directly to special forms, so they are even
trivial to reimplement if the "double-nesting" were distasteful. i am curious,
however, about the HOF equivalents for macros which expand primarily to
changes to the lexical environment. not everything has a ready equivalence to
lambda. for instance with-slots and with-accessors. what is the HOF equivalent
for something like

? (defclass c1 () ((s1 )))

#<STANDARD-CLASS C1>
? (defmethod c1-s1 ((instance c1))
  (with-slots (s1) instance
    (if (slot-boundp instance 's1)
      s1
      (setf s1 (get-universal-time)))))

#<STANDARD-METHOD C1-S1 (C1)>
? (defparameter *c1* (make-instance 'c1))

*C1*
? (describe *c1*)
#<C1 #x69D95C6>
Class: #<STANDARD-CLASS C1>
Wrapper: #<CCL::CLASS-WRAPPER C1 #x69D95A6>
Instance slots
S1: #<Unbound>
? (c1-s1 *c1*)
3274553173
? (describe *c1*)
#<C1 #x69D95C6>
Class: #<STANDARD-CLASS C1>
Wrapper: #<CCL::CLASS-WRAPPER C1 #x69D95A6>
Instance slots
S1: 3274553173
?




More information about the Python-list mailing list