lua-users home
lua-l archive

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


Javier Guerra <javier@guerrag.com> dixit:

> - use a table as the only parameter, so the user writes "func{arg=val,
> arg4=val4}" instead of "func(val1,val2,{arg5=val5})"

I recently realised the following:
* Most funcs have a main parameter defining "what" is processed (the 'subject', the prime mattery).
* Many have no other parameter.
* If any, they usually define "how" to process, ie they are parameters in the proper sense.
* These additional parameters often are optional.

   sort(seq, compfunc, reverse)

This is the reason why I intended to put additional parameters inside a table -- as opposed to the main one.

In OO programming, the main param is indeed most of the time the object itself, so it is implicit in func call.

   seq:sort(compfunc, reverse)

In this case, it would really make sense I guess to define methods with a table parameter only. Naming also allows:
* forgetting order
* auto-comment
* optionality
* (possibly) default values

The issue is indeed that the func def header doesn't describe the interface anymore. For this reason, and for the sake of consistency, I would like the possibility to define a func with a table of (possibly named) parameters, in the same way we can call them. (Note that this is not a feature request, as maybe it does not fit with Lua as an overall language, rather only with OO use it of it.)

Denis
________________________________

la vita e estrany

http://spir.wikidot.com/