lua-users home
lua-l archive

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


----- Original Message -----
From: <RLake@oxfam.org.uk>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Thursday, February 20, 2003 4:42 PM
Subject: Re: Need for help


> Perhaps:
>   account.type = "Debit"
> Actually it would be a particular account, no? So you would say:
>   Account(10030).type = "Debit"
> for example.
Something like the last is what I am actually doing, but thru ´full function
calls´
SetAccount( "Debit", 10030 )
mainly because I was ( and, really, I _am_ ) a newbie to lua and functional
languages at
the time I designed the stuff, and worser, I started with lua 3.2.
Incidentally, your complete example comes to my point: some account numbers
are
´well known accounts´ ( examples  SalesTax, PurchaseTax ) and they well
deserve a
simbolic name from the global env !!! also, to grep the scripts it´s useful.
Moreover, with lua >= 4, where an application can easily use more than one
lua interpreter:
it can ( and in fact, in the 5.0 ´adaptation´ of the ledger system, is )
have one ´ledger_lua´,
which has its global space ´polluted´ Other interpreters which the whole
system may need
are ´clean´.


> Or perhaps:
>   ManchersterOfficeRent = Account{code = 10030, type = "debit", ...}
> Or:
>
> MOR = Account {
>   code = 10030,
>   description = "Manchester Office Rent",
>   type = "debit"
> }
>
> Plus other possibilities. I think the Lua syntax is very flexible in this
> regard.

You are right.

> But that was my point about assignment sending a message to the container,
> not to the value. If you used the first one (account.type = "debit"), it
is
> the object "account" which is being told to set its type to debit. To me,
> that makes sense, and it makes just as much sense in the global
> environment,
> For example:
>
> TimeZone = "gmt"
>
> is a reasonable way of telling the global environment what the time zone
> is.
> It was precisely this line of thinking that promoted the code that I put
on
> the Wiki.

> I think that it is not very different from what you want, really. It is
> only
> how you think about it. Once you think of assignment as sending a message
> to
> the container (whether it is a table, a userdata, or the global
> environment),
> then you no longer think about assignment as a value method.

You are right regarding ´the way of thinking´. I readed your pages in the
wiki, and I must
confess I don´t fully understand ( at first glance ) what is going ´under
the hood´.
That is a clear indication that I must go a lot more far in my lua
understanding before claiming
for features.

> So in the above example, one line of thinking would say that I set
TimeZone
> to an object (a userdata, say), and then assignment magically changes to
> being
> an object method.
>
> But the other way of thinking is that I tell the global environment that
> TimeZone is a special variable, and then assignment stays being a message
> to
> the global environment.
>
> Now, the only question is how I tell the global environment to make
> TimeZone
> special. I could do that with assignment, of course, since that is a
> message
> to the global environment. Or I could use some function to register it as
> a special. Either way, I am not doing much differently from what you are
> asking for, I am just thinking about it differently (and, I would argue,
in
> a way that is more consistent with functional languages such as Lua.)

Yes.

> > what if my metamethod __lt can cope with any type ?

> I take your point here, but it is a contentious issue. OO languages do
> not deal very well with binary operators, and there is much debate about
> this issue. What if c and d both have _lt metamethods? Which one wins?
> Why should it be the first one (if that is what you are thinking)?

No, I´m not thinking the ´left´ operand having priority.
My full ´way´ is as follows.
Given de two operands, check in the first place if at least one of them has
a metamethod for
the operation required. Then if both have metamethods, check they are the
same. If not,
raise the exception ... This would be the ´elaborated´ method to ´guess´ the
involved types.
some pseudocode

leftmeta = getmetamethod( op, leftop )
rigthmeta = getmetamethod( op, rightop )

if leftmeta or rightmeta
     if leftmeta and rightmeta
         if  leftmeta != rightmeta
             raise exception
     else if rightmeta
          leftmeta = rigthmeta
     return leftmeta( lop, rop )
else
    current code
I don´t remember the exact lvm code now, to tell where the ´hacking´ would
be better.
But even if the tests migth be conducted at the start of the functions, the
worse overhead
incurred when no table or userdata are involved is two calls to
getmetamethod, ( I don´t remember the exact name ) and at most two tests for
´no metamethod´ - not a lot of time even for 16 bits systems

> Binary dispatch is probably the answer, but that is complicated (and
> can be slow, too.)

What is ´binary dispatch´ ? may it be something like the simple code I´m
thinking about ?

Ok.
The whole question could be simplified to
a) follow your guidelines for ´assignment´, setting ´special variables´ and
methods
    could that be done from C code ?
b) hack a bit the lvm.

Thanks