lua-users home
lua-l archive

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


Le mer 29/11/2006 à 08:52 Andreas Stenius à écrit:
> 
> I'm not sure I follow what your syntax would expand to... or how
> you'd like to use it. Can't make sense of it.
> 

The idea behind this syntax is to change the not so pleasent syntax of
anonymous function to something more readable.

My last issue was with a class() function that create a class from
functions. Why creating classes from functions and not tables ? because
in tables you have to write something like :

	myclass = class{
		slot = value;
		slot = function(self, ...)
			...
		end;
	}

There are two things I don't like in this. First you have to write
'slot = function()' whereas I prefer writing 'function slot()'. And
also, because I have to write a little comma or semicolon after each
slot definition. Since I generally don't put these in my lua code, I
often forget them.

So, actually, I created a class thunction that takes a function as
argument, change the environment of the function (then defined slots
would go in that environment table), and then run the function to
populate the environment (the class). Actually the syntax is :

	myclass = class(function()
		slot = val
		function slot(self, ...)
			...
		end
	end)

With my new syntax, it would be possible to write instead :

	in myclass = class do
		slot = val
		function slot(self, ...)
			...
		end
	end

With that syntax, you drop the 'function() ... end' syntax, and also you
drop the brackets around the anonymous function. It appears strongly it
is a block of code and integrates nicely with the syntax of others lua
blocks.

My proposition also integrates the local heyword, if you want to make
local assigments. And you can also give to the function (here 'class')
others parameters by placing them after the function name.

I also would like to handle the parameters of the anonymous function
but I don't see how. If anyone has an idea ...




Thanks for this reply.
Mildred

-- 
Mildred       <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG :    <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]