lua-users home
lua-l archive

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


It's certainly quite a fundamental issue.  There's great nicety and
freedom in bare types with their own behaviors, but great advantages
to behavior extension.  I have hacked up my own prelude for Lua, which
included a relatively large function for determining the potential
behaviors of an object, abstracted for use for callable(),
numerical(), etc. functions (try it yourself if you haven't;  it's
really not that hard, is quite fun, and at least in my case gave me a
bit more understanding of the Lua Type System).

The danger is that you'll end up with a system like Python's.  Python
is really quite wonderful to work with, but attempting to divine types
-- or more, the issue at hand, type groups like Sequence, Map, Text --
can get unwieldy very quickly.  It starts and ends at one of the
better features of Python: duck typing.  Unfortunately for such
divination, anything can quack like a duck, or implement a __getitem__
special method, which behavior varies between a Sequence or Map.  The
tutorial and manuals in fact recommend against straight type-checking
and instead one should use "hasattr", which has all the appeal of
smashing stones in a prison yard.

Back to the point, callables and such... seem against the Lua Way from
what I see, and if you really need the functionality, roll your own
interface (which, like I said, is relatively easy).  The Lua Way seems
very tied into "There Are 8 Types And Only 8 Types And Thou Shalt Have
No Other Types Before Me (And You Can Fudge A Little With Tables
Because I Am A Merciful Language)".  (I'm aware of the temerity of a
newbie posting opinions of the Lua Way, but I believe it reasonable.)
The barebones simplicity is quite refreshing after the type morass
that is Python, and also perfectly functional, with cases like the
above seeming the exception.

That is to say, I've only maybe wanted a "callable" interface once or
twice, and I feel I can finangle around it now.

Sorry, Petite, and Peter, too, I guess, for taking the theory thing
and running with it!  But it is so fascinating... ;)  Looks like there
are reasons in the thread already.

Cheers,
Ben

On Feb 11, 2008 5:30 PM, Javier Guerra Giraldez <javier@guerrag.com> wrote:
> On Monday 11 February 2008, Peter Odding wrote:
> > Should the Lua API be extended to (transparently) treat callable objects
> > as functions in the appropriate contexts?
>
> ultimately, that could end in deprecating the value type concept in favor of
> capabilities.
>
> i mean, a table wouldn't be any different from a function, or a number... just
> that if you use {}, an 'indexable' object is created; if you type 143, you
> get an 'arithmeticable' object.  and function(...)...end returns a 'callable'
> object.  but if you want, you could create an indexable + arithmeticable
> object, or a callable 'number', or whatever you could conceive.
>
> instead of the type() function, we would have several tests, 'callable(v)'
> would return true if v() is valid, no matter how it was created.
>
> does it make any sense? i really wonder...
>
> --
> Javier
>