
On Sun, 5 Oct 2003 11:02:37 +0000
Petter Egesund
Hi & thanks for answering.
I think I got it - the chaning of the functions lies in the last part of
(\w -> if v==w then n else sto w)
I am used to higher ordered functions from Scheme, but it was the delayed evaluation which played me the trick here. This function is built when updating, and not executed before asking value 'x'?!
If by delayed evaluation you mean lazy evaluation then that has nothing to do with it. Obviously the function isn't executed before asking the value of 'x' because no function can run without it's argument(s). The same representation will behave exactly the same in Scheme. (define init-store (lambda (key) 0)) (define (lookup-store store key) (store key)) (define (update-store store key value) (lambda (lookup-key) (if (equal? key lookup-key) value (lookup-store store lookup-key)))) Obviously, this will make the function taking lookup-key when update-store is called (just like Haskell) and (just like Haskell) it will only be executed when applied to a key to lookup.