[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: setfenv/getfenv
- From: Leo Razoumov <slonik.az@...>
- Date: Tue, 12 Jan 2010 14:40:38 -0500
On 2010-01-12, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> > Just to say it again: the concatenation of "in ... do" really feels
> > hackish and detriments an otherwise beautiful language.
>
> Just to say it (again?): the concatenation of "in ... do" is a particular
> technique for a very particular problem (running a chunck of code with
> multiple environments). Very few people would use it, and maybe even
> these few can find a different approach to their problem.
>
> -- Roberto
Roberto,
I do not know what do you mean by "different approach to their problem".
Just for starters lets take your own example in the PiL2 section 10.1
"Data Description", pages 87-90. There you define a database entry
using global function "entry"
entry{
title = "Tecgraf",
.....
}
Then you load all the entries into a chunk called "f" and execute it
multiple times with different definitions of the global function
"entry" (Listing 10.4, page 90). This trick allows you to run multiple
queries, produce reports, do any arbitrary data analysis of the
entries. So far so good.
Now, let say you have multiple entry types "book_entry", "jnl_entry",
"kitchen_sink" etc and you wants to have multiple views on such an
inhomogeneous dataset.
Currently, one can keep such views (aka data interpretations) cleanly
separated and isolated from data inside multiple f-environments. Then
one calls a chunk multiple times tossing in an appropriate environment
each time. Thus, Lua allows for a very clean Data/View model. The
approach with loadstring("in ... do " .. code .. " end") is quite
ugly, to be honest. May be restricting setfenv from modifying fenv up
the call stack would be a better less intrusive solution to Lua's "too
dynamic" problem.
--Leo--