why tags?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

why tags?

John Belmonte-2
Hello,

With recent mention of the designers meeting to discuss about what can
be removed from Lua in mind...

I've been studying Lua and I noticed that the concept of tags was not
present in the language at the time the SPE paper was written.  Is
there any information available on the designers' reasoning for adding
tags?

It seems like everything you can do with tags could have been done in
the original language by wrapping values in table "classes" and setting
the fallbacks to pass control to a handler function within the class. 
It would be less efficient but more monolithic than what tags provide. 
By monolithic I mean no arbitrary constraints such as "this method
cannot be set for tables with default tag" for the "gettable" event,
etc.

Regards,



Reply | Threaded
Open this post in threaded view
|

Re: why tags?

Sean Thomas Middleditch
> It would be less efficient but more monolithic than what tags provide.

I for one have no use for an unefficient language, if that's reason enough
for you.  As I understand it, Lua was intended to be both small AND fast AND
easy to use.

Sean Middleditch

Reply | Threaded
Open this post in threaded view
|

Re: why tags?

Luiz Henrique de Figueiredo
In reply to this post by John Belmonte-2
>From: "John Belmonte" <[hidden email]>
>
>I've been studying Lua and I noticed that the concept of tags was not
>present in the language at the time the SPE paper was written.  Is
>there any information available on the designers' reasoning for adding
>tags?

The notion of tags was always present in Lua, but only used for userdata until
version 3.0, which introduced "tag methods" to replace "fallbacks".

While, as you point out, everything could in principle be done with fallbacks,
the tag method meta-mechanism is much cleaner, because it avoids clashes
between different fallbacks.

For instance, if you might want to have different schemes for inheritance.
With fallbacks, you'd have to remember to chain the fallbacks for the two
schemes, which was a hassle and inefficient too.  Tag methods ended this
confusion by grouping the fallbacks correspoding to a given tag in a way that
methods for different tags do not interfere with each other.

If you're happy with fallbacks, then see lua/etc/setfallback.lua for an
implementation of fallbacks on top of tag methods.
--lhf