lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Apr 28, 2009 at 4:11 AM, David Manura <dm.lua@math2.org> wrote:
> The pl.operator names perhaps should resemble Lua metamethod names
> (e.g. "lt" rather than "less").

Agreed.

> Instead of (or in addition to) operator names like ops.mul, one could
> have ops['a*b'] or ops 'a*b' containing the representation in Lua
> code.  This is generalizable to things like ops 'a+b^2' via code
> generation techniques [1] (with memoization above) and is an
> alternative to placeholder expressions (e.g. _1 + _2^2).

I had actually converged on something similar

   t = map2('+',t1,t2)

  t = map('*',t,-1)    (i.e result is the original with all elements
multiplied by -1)

This just looks up the corresponding operator.mul function.

(Yes, I'm persuaded, function goes first ;))

>
> This could also be used in the pl.test module, allowing asserteq(x,y)
> to alternately be written as test(ops'a=b', x, y) and more generally
> allow things like test(ops'a<b', x, y), possibly with shorthand
> test('<', x, y).

test('==',x,y) feels nice...

(The only other thing asserteq brings to the party is default
deepcompare of tables, but == could mean that)

But do we need an alternative to placeholder expressions?  Having a
number of ways to do the same thing can be confusing. (It's true that
memoizing PEs is rather more tricky than 'executable' strings)

On a different track, I am having difficulty coming up with sensible
names ;)  Most of these operations are very straightforward to write
(although there are subtleties), but I can't avoid things like map2
because map can take extra arguments to be passed to the function.
seq.copy is perhaps intuitive enough, but seq.copy2 (which takes a
double-valued sequence and makes it into {{x1,y1},{x2,y2}...} feels a
bit forced. Perhaps seq.copy_tuples?

steve d.