lua-users home
lua-l archive

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


hi,

what about multimethod dispatch based on types or even constraints,
lispers are constantly bragging about:

tab.do_something(num foo, num bar)
tab.do_something(string blah, num baz)

could be sugar for

tab.do_something_number_number(foo,bar)
tab.do_something_string_number(blah,baz)

and calling protocol:
tab[do_something.."_"..type(arg1).."_"..type(arg2)](arg1,arg2)

similiarly as for argument type constraints, this is partially implementable using
metatables, but not to the degree i'd call satisfactory.

this is not trivial, if not impossible, to implement into current
parser.

<lua_vs_lisp_rants>
but having this along with first-class value macros (could be
possibly implemented, though with more overhead than usual functions) would keep
lispers shut about lua just being "another half-implemented lisp derivative" :-P
</lua_vs_lisp_rants>

as for the syntax for value constraints - prefix or postfix syntax allowing usual lua
expressions would be cool:

function fun(s($==1 or $=="a"), n isnumber($))
	local s2 (isstring($) and #$>5) = somethingcool(s)
	return somethingboring(s,s2,n) isstring($)
end

or something similiar.

the idea is to make it as flexible as asserts(), yet
in-place, not to mention use of existing mechanisms in lua, rather
than introducing new ones.

personally i find value constraints a bit redundant (type constraints
would be subset of value constraints in lua), useful only for the
debugging stage - i'm the kind of keep-it-short type of person
(and when it breaks ... well then). if something may break
seriously, that's what pcall() is for.

by the way, will be the current constraints code available on
the svn soon? still rather cool patch to take a look/steal/bastardize :)

On Mon, Oct 23, 2006 at 09:45:43AM +0200, askok@dnainternet.net wrote:
> 
> I'm repeating the request for help, from people interested 
> in getting function parameter, local var, and return value 
> constraints to Lua.
> 
> The approach I'm taking is a patch, because:
>    - I'd like this feature to get _into_ Lua, instead of 
> being a kludge add-on
>    - performance should be made as good as possible
> 
> Current state of the patch is that all parsing is done 
> (and works); constraint strings are placed in variable and 
> function data structures in seemingly meaningful places.
> 
> What remains is ways to enforce the constraints at 
> runtime.  A group of people for discussing different 
> alternatives would be useful, as bouncing something within 
> a sole person's head is never the most creative approach.
> 
> We could use this list, but I'm afraid it's bound to get 
> into teeny-weeny details pretty soon (= instantly).  Once 
> a working, tested concept patch is there, the list can be 
> informed.
> 
> thanks,   :)
> -asko