If you want X, you know where to find it (was Re: do...until wisdom needed...)

Douglas Alan nessus at mit.edu
Wed Apr 18 23:28:19 EDT 2001


"Andrew Dalke" <dalke at acm.org> writes:

> Douglas Alan wrote:

> > It's a very modern language (more modern in some ways than Python,
> > multimethods and a sophisticated meta-object protocol being examples
> > of two very modern features that it supports),

> Yet more things I don't know about.

Don't worry -- there's plenty of time to learn about this stuff.  It's
not going anywhere.  It's very interesting, though, if you are a
language wonk.

> *Sigh*.  OTOH, if you want to know about details of structural
> biology data structures and use cases .. I'm there!

What's "structural biology"?  One of my oldest friends has just
finished writing one of the first textbooks on computational biology.

> Someone else pointed out to me in private mail a converter from
> Fortran to Lisp.  I think would prefer doing that by calling a
> function with a string parameter and getting back, say, a module
> object with the right function interfaces and constants defined.

I'm not sure that this sort of thing should be held up as the poster
child for what you can do with macros, since I'm not sure I can see a
good reason why you would want to translate Fortan to Lisp in a macro.
If you did it the way that you propose, however, the translation would
happen at runtime, which would slow down your program.  If it was done
as a macro, it would happen at compile time, which would not slow down
your program.

Also, using your scheme, the Fortran code would not have access to any
Lisp variables or data.  With Fortran, I'm not too worried about this,
but a good use for a macro mechanism might be because it would help
you to embed some very specialized structural biology notation in with
your Lisp code, and it would be convenient if your notation and the
standard Lisp notation interoperate with each other smoothly and can
see each other's variables, etc.  It's hard to do this with just
procedures and strings.  (Is there a way in Python of finding local
variables by name on the Python stack so that a procedure can get and
set variables in the caller's environment?  If so, you could do it,
but it would be pretty ugly.)

> > More modestly, you
> >might define two macros, "let" and "set" so that

> >   let x = 3
> 
> This would at present raise a SyntaxError exception.  I suppose
> beforehand there would be a statement to make "let" be known
> as a new keyword?

Something like that.  In Lisp this is not a problem since Lisp has no
keywords.  Just how to do it in Python is not obvious and it would
require some deep thought.  You might have to settle instead for
something like

   @let x = 3

where "@" means that a macro invocation is coming up.

> How do linters and other code checking utilities work on this sort
> of mutability?

They might operate on the code after it has been macro-expanded.  Then
the linters never see the macro invocations.

> After all, they don't right now do a good job
> parsing escaped ()s inside of regexps, which is another example of a
> little language embedded inside of a bigger (and different) one.

I'm not sure what problem you are refering to here.  Is it just that
they don't count the parens correctly?  It sounds like these programs
just need better parsers.

|>oug



More information about the Python-list mailing list