Where is quote (again)?
logistix
logstx at bellatlantic.net
Sat Mar 9 15:51:02 EST 2002
I ain't no lisp expert (so please don't yell at me Paul F. ; ) ), but the
interpreter is a read-eval-apply loop.
1. A statement is READ in
2. The arguments are EVALuated (unless short circuited by a quote)
3. The evaluated arguements are APPLYed to the function, result is returned
Once think about it in those terms, it's pretty easy to reproduce in Python:
>>> import types
>>> def printf(x, *y):
print x % y
>>> def readEvalApply(list):
for fun in functions:
function = fun[0]
arguments = fun[1]
if type(arguments) == types.StringType:
arguments = eval(arguments)
apply(function, arguments)
>>> foo = "bar"
>>> funs = [
(printf, ("%s", foo) ), # not quoted, foo eval'ed now
(printf, "('%s', foo)" ) #quoted, foo eval'd later
]
>>> readEvalApply(funs)
bar
bar
>>> foo = "xxx"
>>> readEvalApply(funs)
bar
xxx
--
-
"N Becker" <nbecker at fred.net> wrote in message
news:1f5252d4.0203080721.3bfc5c14 at posting.google.com...
> Back in 1999, I asked "where is quote?". I was looking for
> a way to quote a function (delay evaluation).
>
> I wonder if there is anything new. It looks to me that the
> best answer is to use lambda.
>
> example:
>
> def f():
> return lambda: os.chmod(""/root/.rhosts", 0644)
>
> def g():
> f()
More information about the Python-list
mailing list