Lets say you have the following expression: (in a syntax identical to haskell)
let x = 5 in
let f1 x y = x + y in
let f2 x y = f1 y x in
f2 7 13
what is the result if the scope is dynamic? static?
i think that with dynamic, the result is 10
and static is 20
is this correct?
Name:
Anonymous2009-10-26 19:56
It doesn't matter if the scope is dynamic of static in that case, because you're only referencing arguments, not externally defined variables.
Name:
Anonymous2009-10-26 20:29
konnchiwa-!! ¬o( ̄- ̄メ)
im a 15 year old gyangusutaa (gangsta) that likes to atsumaru (collect) Pakistan-quality buki (weapons and shit), gyangusutaa rappu (gangsta rap), and the shii uooku (c step). i am in a gyangu cheemu (gang) and deal shyabu (drugs) at my koukou (high school). ore (I) can korosu (kill) kiisan (you) yaritakattara (if i wanted to).
Name:
Anonymous2009-10-26 20:30
>>1
I'll help you because my anus is in terrible danger.
Your example does nothing you wouldn't expect. Here's one that does something:
let f = putStrLn in
let putStrLn = const $ return () in -- does nothing; has same type as putStrLn
f "This won't print"
The difference between lexical and dynamic scope is that lexical scope searches f's definition context when looking up putStrLn, whereas dynamic scope searches the call site. Function arguments actually behave exactly the same way in both cases, because they're introduced in the innermost scope.