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

Andrew Dalke dalke at acm.org
Thu Apr 19 03:31:04 EDT 2001


Douglas Alan:
> It's very interesting, though, if you are a language wonk

'Fraid I'm more an applications developer these days.  I
like working on software tools to help science related problems.
My interest in computer languages is to make sure I'm using
the right parts.

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

Douglas Alan:
>What's "structural biology"?

Biological systems are made of molecules like proteins, DNA,
RNA, lipids, sugars, water, ions, etc.  These are physical objects
in a 3D world.  Structual biology studies those types of molecules
with a focus on understanding how they physically interact.

For pictures from my old research group,
  http://www.ks.uiuc.edu/Overview/gallery/structure.shtml

> One of my oldest friends has just finished writing one of the
> first textbooks on computational biology.

I'm confused (again :).  There are quite a few books on
computational biology.  See for example

Algorithms on Strings, Trees, and Sequences: Computer Science
and Computational Biology by Dan Gusfield
 -or-
Introduction to Computational Molecular Biology by Joao Carlos
Setubal
 -or-
(any of the other 46 matches returned from Amazon on a search
for "computational biology").

The first of these is quite good.  Haven't read the second.


>>>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.
>[...]
>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.

Naah.  Checksum the text and cache the created module to disk.
But I wouldn't really do things they way.

I have written converters from other languages into Python and
used the f2c model of converting the code into actual Python
source code.  If used during run-time it would exec the code.
If run as a standalone program it spews the code to a file
that can be imported directly by Python.


>(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.)

Yes and no.  Python deliberately makes it hard.  You need
to raise an exception and look up the stack frames.  There
are things you can't do with it, like:

  def spam():
    a = 1
    add_to_locals(b = 2)  # adds locals to the calling stack frame
    print a, b

because the compiler prevents it, and because locals() is
supposed to be a read-only dict.  (I think there's some support
to allow an exec to modify the local namespace including adding
new variables.  Not sure.)

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

Sorry for the poor explanation.  In Emacs there are times where
I'm writting a regular expression ... oh yeah, this in for Perl
code ... and Emacs doesn't know Perl well enough to figure out
where the regexp ends, so I've needed to put in extra text,
like "#)) emacs foo" to fake it out.

Python code has similar problems with triple quoted strings.
Emacs thinks the following is still inside of a 'string quote

s = """'Tack f"ur det' he said"""
if 1:
 <pressing tab here does not indent>

so I need to fix it up with

s = """'Tack f"ur det' he said""" # Emacs foo --> '
if 1:

This is a long known problem and is mentioned in the python-mode
FAQ in full detail.

My point is, existing tools don't quite handle Python's
syntax without some coercing, so making things more powerful
(eg, with the ability to define macros, new keywords, etc.)
makes those tools even harder to write.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list