Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 4433 days ago | link | parent

Aaand now mutable variables work. I decided to make all variables mutable by default, but I miiiiight add in a way to make a variable constant.

Now there's two primitives for dealing with names: var and set!

  (var a 10)
  (set! a 20)
"def" then is built on top of them:

  (var def
    (vau e (list n v)
      (eval e (list do (list var n %f)
                       (list set! n v)))))
Basically, that means (def a 5) is equivalent to (do (var a %f) (set! a 5))

This is important for recursive functions, which need to refer to themself. In other words, "var" is like "let" in Arc, and "def" is like "var" in JavaScript:

  (var a a) -> error
  (def a a) -> #f


2 points by Pauan 4433 days ago | link

Okay, I actually managed to get away with using only "var". Instead, I defined "set!" in terms of "set-box!"

  (var set!
    (vau e (list n v)
      (set-box! (get (unbox e) n)
                (eval e v))))
Oh, by the way, here's a link to the latest version: https://github.com/Pauan/nulan

-----

2 points by akkartik 4433 days ago | link

Looks like you've broken fn in the process :)

  > (def foo (fn (list a b) (+ a b)))
  hash-ref: no value found for key
    key: 'fn
    context..

-----

1 point by Pauan 4433 days ago | link

Ah, yes, I actually took out fn because I plan to build it in "02 nulan.nu" rather than "01 nulan.rkt". I put in a quick fix to get fn working, but I'll need to change that later.

-----