[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Q&A with Roberto on Workshop 2012
- From: Dimiter 'malkia' Stanev <malkia@...>
- Date: Fri, 30 Nov 2012 12:46:15 -0800
I would much rather ask whether this seems good feature to be accepted
in the language, rather than some patches.
Something more general might be even better, but it might complicate
things more, something like Common-Lisp's #1= #1#
http://www.lispworks.com/documentation/HyperSpec/Body/02_dhp.htm
((a b) . #1=(#2=(p q) foo #2# . #1#))
In this case #1= and #2= are markers, and later #2# #1# point to the
same expression from these markers. The confusion/ambiguity here is that
some people might expect #2# to be a fresh copy of #2 (deep-copy), but
it really points back to where it was declared (thus allowing loops).
That's probably overkill for lua, and it's users, but it would avoid
duplication when declaring structures.
In Lua this would be something like
local t1 = {
{ "a", "b " },
#1{ #2{"p", "q" }, "foo", #2#, #1# }
}
or maybe just
local t1 = {
{ "a", "b " },
#1{ #2{"p", "q" }, "foo", #2, #1 }
}
or replace # with some other character.
This would also allow lua to print recursive loops in structures, and
serialize-deserialize them
Duh... now that I think more about it - it's probably better candidate
for metalua.
On 11/30/2012 12:20 PM, Sven Olsen wrote:
local t1 = {
v1 = v2 = v3 = 10
}
I'd think this would be doable with a small lparser.c diff, provided
that you limited it to the string-key shorthand.
A more general patch, allowing things like: { [a(b) ]= [a] = 10 },
would be harder to write -- but probably not that useful.
If you're itching to give it a shot -- take a look at
lparser.c:recfield(). Your entry point is probably a testnext(ls,'='),
inserted immediately before the OP_SETTABLE gets committed.
-Sven