Arc Forumnew | comments | leaders | submitlogin
Can someone explain why assign is implemented as it is?
1 point by akkartik 5566 days ago | 1 comment
assign eventually calls set1:

  (cond ((eqv? a '()) (error "Can't rebind nil"))
        ((eqv? a 't) (error "Can't rebind t"))
        ((lex? a env) `(set! ,a zz))
        (#t `(namespace-set-variable-value! ',(ac-global-name a) 
                                            zz)))
Why do lexical vars get assigned using set! rather than namespace-set-variable-value! ? And how does set! not raise an error? I don't see the corresponding define anywhere..


2 points by fallintothis 5566 days ago | link

ac will have compiled Arc lexical variables down to Scheme lexical variables. So, they'll already be bound -- no need for define. E.g.,

test.arc

  (let x 5
    (assign x 10))
At the REPL

  $ mzscheme -if as.scm
  Welcome to MzScheme v4.2.1 [3m], Copyright (c) 2004-2009 PLT Scheme Inc.
  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> :a
  > ((lambda (x) (set! x 10) x) 5)
  10
  > (acompile "test.arc")
  #t
test.arc.scm

  ((lambda (x) (begin (let ((zz 10)) (set! x zz) zz))) 5)

-----