Matlab vs Python (was RE: Discussion: Introducing new operators for matrix computation)

Alex Martelli alex at magenta.com
Mon Jul 17 17:17:32 EDT 2000


"Kevin Jacobs" <jacobs at darwin.epbi.cwru.edu> wrote in message
news:8kvocr$5mq$1 at eeyore.INS.CWRU.Edu...
    [snip]
> Silly idea 1:
>
>   Until add-on Python grammar modules are available, what about a
PyAlgebra
>   evaluator module.  For a precedent, see regular expressions.  The
>   difference is that linear-algebra syntax can be made too Python-like for
>   some tastes.
>
>   e.g.:
>
>   import PyAlgebra
>
>   PyAlgebra.run(r'A = (A .* B)\C')
>   e = PyAlgebra(r"D = A'*B")
>   e.run() # or e()
    [snip]
> Feel free to chime in!

Seems to me we could do better (in terms of concision) along
the general idea of KJSI1.  As PyAlgebra is basically just
parsing arbitrary syntax into (presumably) some suitable
Python function-like object, what it returns from parsing a
string could well have free variables just as well as bound
ones.

Free variables (to be bound at evaluation-time either by
name or positionally) might be the syntactic default, with
some special marker for parsing-time-bound variables.  Or
maybe the difference need not be know at parse-time.  And
I think this should be an expression-evaluator, only -- no
assignment -- dunno, it seems smoother to me... sort of:

    from PyAlgebra import parse

    expr = parse(r'(Left .* Right)\Divisor')
    Result = expr(Left=X, Right=Y, Divisor=Z)

being equivalent to something like:

    Result = X.dotProduct(Y).rightDiv(Z)


Is there anything that stands in the way of implementing this
sort of thing right now?  Is it much of an improvement?  Would
smoother integrated syntax sugar such as

    Result = (X .* Y) \ Z

be perceived as hugely better than

    Result = whatever(r'(X .* Y) \ Z')

???


I dunno -- I perceive no loss by having RE isolated in such
a way, rather than merged into the language's syntax as in
Perl; indeed, I personally perceive it as an advantage, for
all that RE's are something I use SO frequently.  But then,
I'm not the target-audience for this sort of thing, I guess.
So I can hardly judge how that target-audience would react.


Alex






More information about the Python-list mailing list