lua-users home
lua-l archive

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


On Sun, Mar 27, 2011 at 2:34 PM, Francesco Abbate
<francesco.bbt@gmail.com> wrote:
> new matrix. I don't have a solution for the problem but I was thinking
> that a sort of lazy evaluation could work. Here is the idea. When you
> type an expression like A+B the object that is created is a new type
> of object that just store the information that a sum of A and B should
> be done.

Something like that is  done with with Penlight's placeholder
expressions[1]. The problem here is that you want to 'quote' an
expression and not evaluate it immediately, and later compile this
into a function.[2]  But once you have your expression in this form,
you can do symbolic operations like differentiation [3]

So something like a + b*t can be represented in a AST form, and then
compiled into optimal code for the particular types.

steve d.

[1] http://stevedonovan.github.com/Penlight/#T36
[2] a runtime equivalent of that crazy C++ template expression stuff
than Fabien was alluding to.
[3] https://github.com/stevedonovan/Penlight/blob/master/examples/symbols.lua