[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax questions
- From: Matthew Paul Del Buono <delbu9c1@...>
- Date: Fri, 12 Sep 2008 19:12:14 -0400 (EDT)
>
>> Speaking of which, is there a reason why number literals can't be passed as
>> function arguments without parentheses, as is allowed for table and string
>> literals?
>
>The idea of those sugars is not to "simplify" function calls, but to
>emulate other constructs. For instance,
>
> require "mod"
> newPoint{x = 10, y = 20}
>
>may be seen as new constructs in the language. Of course nothing prevents
>you from using
>
> print "hi"
>
>but that is not the motivation for that syntax. We do not see numerals
>being used in this same way.
>
Another construct I've been using allows much finer emulation of OOP:
class "foo" {
a = function() ... end,
x = 0
}
Which is simply implemented by a function named "class" which takes a single parameter (the name of the class as a string) and returns a function. This function is then called passing a single argument, the table which indicates the class definition.
It's not perfect, but it is much easier to see what's going on than the alternative:
foo = {};
foo._mt = {
a = function() ... end,
x = 0
}
function foo.new()
return setmetatable({}, foo._mt)
end
(Which may be get increasingly complex for desired functionality such as inheritance.)
-- Matthew P. Del Buono