Re: (eval X 1) not behaving as expected
Hi Maxim, Danilo, Rick, > It seems that 'apply' and 'let' do not call the same 'bind' procedure. Yes, you are all correct! The "upper context" in 'eval' and 'bind' refers to _lambda_ bindings (function calls), and not to local variable bindings like 'let', 'use', 'for' etc. While normally there is no inherent difference between those bindings, they are handled in a slightly special way in evironment offset counts for 'eval' and 'run', but also in debug backtraces ('trail', 'bt'). The reason for that is pragmatism. It would be tedious to count all nested 'let' calls in a function until you find your way out of it, and it would be impossible to determine the right value when you are in nested function calls more than one level deep. Also, the variable bindings in the current function are obvious anyway, and it doesn't make much sense to bind the same variable multiple times within the same lambda context and then to refer to the outer one. I fixed the references of 'eval' and 'run', by calling it "lambda-binding" offsets. BTW, the 'cnt' argument to 'up' has yet another meaning. It counts the nth _symbol_, and does not refer to binding evironments. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
(eval X 1) not behaving as expected
(let (a 500) (let (a 100) (up a))) # -> 500 (let (a 500) (let (a 100) (eval a 1))) # -> 100 (let (a 500) (let (a 100) (eval 'a 1))) # -> NIL I would like to know if evaluating whole expressions (as opposed to one value for 'up) in upper context is possible with picolisp.
Re: (eval X 1) not behaving as expected
> It seems that 'apply' and 'let' do not call the same 'bind' > procedure. I find this statement very interesting and salient. The Reference's example of `eval` with cnt is at http://www.software-lab.de/doc/refE.html#eval and looks like this. : (de f (A) (list (eval 'A) (eval 'A 1) (eval 'A 2) ) ) -> f : (de g (A) (f (inc A)) ) -> g : (one A) -> 1 : (g (inc A)) -> (3 2 1) But "aping" the Reference's example with `let`, like this : (one A) -> 1 : (let A (inc A) (let A (inc A) (list (eval 'A) (eval 'A 1) (eval 'A 2 -> (3 1 1) shows that the `(eval 'A 1)` expression "goes straight to the top", as Danilo mentioned and I believe that is precisely what he meant by his statement I quoted above. Again, quite interesting. What I mean, in essence, by "aping" is that in other lisps, `let` is equivalent to calling a lambda "on the fly"; so e.g., this (let A (inc A) ...) is equivalent to ((lambda (A) ...) (inc A)) However, this is not the case with picoLisp, because the "equivalent" in "lambda" (fexpr) on-the-fly calls of the above nested `let` expression is : ((quote (A) ((quote (A) (list (eval 'A) (eval 'A 1) (eval 'A 2))) (inc A))) (inc A)) -> (3 2 1) which yields the 2 that we were looking for[1], as it were, in the nested `let` expression. But, as I've learned in the past, picoLisp does not at times behave as other lisps do -- and for good reason -- so I'm looking forward to Alex shedding light on this, as he always does, and to learning something more/new. Best, --Rick ___ [1] https://www.youtube.com/watch?v=532j-186xEQ=30s -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe