Difference in F# and Clojure when calling redefined functions

Posted by Michiel Borkent on Stack Overflow See other posts from Stack Overflow or by Michiel Borkent
Published on 2010-04-03T08:09:34Z Indexed on 2010/04/03 8:23 UTC
Read the original article Hit count: 296

Filed under:
|
|

In F#:

> let f x = x + 2;;

val f : int -> int

> let g x = f x;;

val g : int -> int

> g 10;;
val it : int = 12
> let f x = x + 3;;

val f : int -> int

> g 10;;
val it : int = 12

In Clojure:

1:1 user=> (defn f [x] (+ x 2))
#'user/f
1:2 user=> (defn g [x] (f x))
#'user/g
1:3 user=> (g 10)
12
1:4 user=> (defn f [x] (+ x 3))
#'user/f
1:5 user=> (g 10)
13

Note that in Clojure the most recent version of f gets called in the last line. In F# however still the old version of f is called. Why is this and how does this work?

© Stack Overflow or respective owner

Related posts about clojure

Related posts about F#