lua-users home
lua-l archive

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


On 29/06/2011 18.09, steve donovan wrote:
On Wed, Jun 29, 2011 at 5:48 PM, Lorenzo Donati
<lorenzodonatibz@interfree.it>  wrote:
For example, consider math vectors:

W = V1 :x: V2 + V3
W = V1:cross_product(V2) + V3   -- less readable

OK, good one. But you could overload ^ for that, and * for dot
product. (And % is also available)

Oh yes. I did it sometimes.


True, :x: is cute. To answer your question, one thing that LuaMacro
can not do is parse infix expressions. You could define ':x:' as a
lexical token and replace it by '%', that kind of thing.  But for such
a simple step, gsub is your friend ;)

Yes. I also read the stuff about "pseudo-custom" operators in the WIKI with all those tricks with higher order functions to capture arguments and the like.

I use those tricks sometimes, but to tame the syntax of a DSL, but not for custom operators, since they are too ugly anyway.

With gsub the problem begin when mixing prefix/postfix/infix operators and when the expression gets complex (just where a custom math-dsl should help!), so I never pushed it too far.


steve d.




-- Lorenzo