3 ms·
Depends what you are astonished by, I suppose. As far as I can tell the Ruby behaviour has to do with the fact that Ruby variable definition appears to take pla
by pvg 17y ago
Depends what you are astonished by, I suppose. As far as I can tell the Ruby behaviour has to do with the fact that Ruby variable definition appears to take place sometime before evaluation, maybe during parsing. So as long as the statement parses and looks like a variable definition/assignment, you get your variable. On evaluation, undefined variables cause barfage but in the case above, the a got defined before the statement was actually executed.
- gaius 17y agoWell, I am astonished that entering invalid code can cause a persistent state change within my interpreter. I can't think of any other REPL language in which that happens. OCaml: # let a=b;; Error: Unbound value b # a;; Error: Unbound value a # Haskell: Prelude> let a=b <interactive>:1:6: Not in scope: `b' Prelude> a <interactive>:1:0: Not in scope: `a' Prelude> Scheme: guile> (define a b) Backtrace: In standard input: 1: 0* (define a b) standard input:1:1: In expression (define a b): standard input:1:1: Unbound variable: b ABORT: (unbound-variable) guile> a ERROR: Unbound variable: a ABORT: (unbound-variable) You can see where my astonishment comes from...
- pvg 17y agoYeah I was a little surprised too. It looks like the parser just defines foo for any parsable foo = .... before anything actually runs. Kind of a funky design choice, especially for such a dynamic language.
- deleted 17y ago[deleted]