[Looks like this never made it to the newsgroup; resending through 
ruby-list.]

Hi,

I thought some people here might find the following trick useful,
possibly for other sorts of applications.

Original comp.lang.python thread:

  Re: ANNOUNCE: PySymbolic - Doing Symbolics in Python

Alex Martelli wrote:
> 
> "Tim Peters" <tim_one / email.msn.com> wrote in message
> news:mailman.971399443.5181.python-list / python.org...
>     [snip]
> > >         Diff(x*x,x)
>     [snip]
> > [Alex Martelli]
> > > Python evaluates the arguments before passing them to any
> > > callable-object.  So, for example, if you write
> > >     Diff(x*x, x)
> > > the x*x multiplication will take place before Diff ever sees
>     [snip]
> > >     Diff('x*x', 'x')
> >
> > I believe Pearu has already discovered "the right way" to get the 
effect
> > he's after in Python:  define a class for symbolic variables, and 
precede
> > his examples by, e.g.,
> >
> >     x = Symbolic('x')
> >     a = Symbolic('a')
> >
> > and so on.  Then define Symbolic.__add__ etc to build up an expression
> tree.
[snip]
> > That slick trick has been rediscovered several times in Python, and 
I've
> > found it quite satsifying in practice the few times I've used it.
> >
> > beats-incessant-quoting-anyway-ly y'rs  - tim
> 
> Definitely.  Once again, Python's simplicity, dynamicity, regularity,
> combine to make the seemingly-impossible into the actually-pretty-easy.
> What a language...!

Well, likewise for Ruby.

-- 
Conrad Schneiker
(This note is unofficial and subject to improvement without notice.)


Conrad Schneiker
(This note is unofficial and subject to improvement without notice.)