[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua as (Matlab like) calculator
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 30 Jun 2011 14:01:35 +0200
On Thu, Jun 30, 2011 at 1:42 PM, Oscar Chinellato
<oscar.chinellato@gmail.com> wrote:
> This is exactly why I would appreciate the __assign metamethod - it's
> non-intrusive (existing code would behave exactly the same) and,
> assuming that the programmer does a good job, it's safe.
I can see one problem with __assign; it means that every assignment
needs a metatable check. That would probably slow things down for all
programs. And you'd have to do it as well for values passed as
function arguments.
Having survived C++, I must say that 'overloading the assignment
operator' leads to 'subtleties' (as Stroustrup puts it in his
restrained way) It makes programs harder to understand, because of
the increasingly paranoid feeling you get that the programmer is doing
something _clever_ in the simplest of statements.
In the context of a DSL meant to be used by numerical people[1], then
sure. The restriction to a domain means that object behaviour can be
specialized.
So either a patch or some preprocessor? I was entertaining myself the
other day with this kind of macro-ized syntax:
$> luam -llist -i
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
Lua Macro 2.3.0 Copyright (C) 2007-2011 Steve Donovan
> list a = {'one','two'}
> = a:map(\x(x:sub(1,1)))
{o,t}
> a:append 'three'
> a:append 'four'
> = a
{one,two,three,four}
> = a[2:3]
{two,three}
> = a[2:2] = {'zwei','twee'}
{one,zwei,twee,three,four}
> = a[1:2]..{'five'}
{one,zwei,five}
It's amazing what you can do with a little bit of lexical look-ahead...
steve d.
[1] this set definitely does not include Dirk, of course