<Iter>
mmm I think erlang might also have a let form, I forget.
<systems>
i see
<Iter>
do you know what it means to be lexically scoped?
<systems>
i think, it means it look for the names last in
<systems>
not first in
<Iter>
mmm not sure what you mean by that, but I suspect that might suggest some confusion.
<systems>
well, you program is like a nested list of expression, dynamic look for var values, outside in, lexical looks for values, inside out
<systems>
thats what i think it is
<Iter>
nope, that's not quite right :(
<systems>
:)
<systems>
a let expression like sets a new root for a certain name
<systems>
dynamic scoping looks for the first set value for a name, lexical scoping for the last set value, of course within an expression space
<systems>
or scope
<Iter>
given a function f = \x.\y.x+y, does the expression (let g = f 4 in (let x = 5 in (g 2))) return 6 or 7? In lexical scope it returns 6, dynamic scope returns 7.
<Iter>
The question is what does the value of x bind to? In lexical scope it binds to the value of x in the closest *defining* environment. In dynamic scope it binds to the value of x in the closest *calling* environment.
<Iter>
(I'm expecting questions, I doubt that explaination was sufficient ;)
<systems>
let x = 5 in (g 2) ?? this is missing something, right
<systems>
x is not called in g 2
<Iter>
g = f 4 which of course returns \y.x+y.
<Iter>
so there is a reference to x in g.
<Iter>
the question at issue is, which x does the x in g refer to?
<Iter>
does it refer to the x in the environment in which g was defined (the call to f, ie. 4)
<Iter>
or does it refer to the x in the environment in which g is called (the call to g 2, which is enclosed in a let x = 5, so x would be bound to 5)
<Iter>
help?
kinners has quit [Read error: 110 (Connection timed out)]
<Iter>
mmm that elisp manual is poorly worded.
<systems>
hehe
<Iter>
the binding of a symbol is visible only in functions ***called*** in the let form; in Emacs Lisp, scoping is dynamic, not lexical. <= emph added.
<systems>
well, it's an intro for non programmers as well
<systems>
so i believe its kinda dumbed down
<Iter>
in lexical scoping, the symbol would be visible to functions ***defined*** in the let form.
<Iter>
(and in fact would _not_ be visible to functions merely called)
<systems>
yes excatly, so let in elisp, prevent a variable from being global by default
<Iter>
nope. dosn't have anything to do with global or local.
<Iter>
both are local. Just a question of what get's to see it.
<Iter>
in fact in a very real sense, dynamic scope is more 'global' in its visibility.
<systems>
what the let body gets to see
<Iter>
There's a problem called variable capture, which is particularly nasty, and is avoided in lexical scope.
<Iter>
dynamic scope is a rather unfortunate design flaw in elisp.
<systems>
i dont know for sure, but in ocaml, you don't explicitly define parameters
<systems>
right
<Iter>
Again, I'm not sure I understand your question, and suspect you're mistaken :)
<systems>
example, let x = 1 ;; let f = x + y ;;
<systems>
f now is like a function who needs one param
<systems>
but if we didnt define x ;;
<systems>
f would be more like a functions hungry for 2 params
<Iter>
that's going to run into trouble as y is free. y needs to be bound.
<systems>
in elisp or c or c++, you never have this situation right
<systems>
where a function definition depends on what was previouly defined
<Iter>
let x = 1 ;; let f y = x + y ;; is fine, that is equiv to f y = 1 + y.
<systems>
aaaa, right, i forgot that
<Iter>
systems: except f isn't just a function. It's a closure over it's lexical environment.
Lemmih_ is now known as Lemmih
<systems>
in ocaml, f is always a closure right..
<Iter>
This is a very very powerful feature that gives you a huge boost in expressivity and power over languages like C or C++.
<Iter>
yes.
cjohnson has joined #ocaml
<systems>
yea, i like ocaml
<Iter>
then again it is in common-lisp, scheme, erlang, haskell, clean, python, ruby, or sml as well :)
<systems>
i dont think elisp got closures
<Iter>
I don't know.
<Iter>
That would be a very major lack.
<Iter>
systems: How do you define a function that takes one number and returns a function that increments it's argument by that number?