Arc Forumnew | comments | leaders | submitlogin
1 point by absz 6132 days ago | link | parent

So the idea would be that you would write

  arc> (tempset x 10)
  10
  arc> (+ x 10)
  20
  arc> (tempset y -10)
  -10
  arc> (+ x y)
  0
  arc> (cleartemps)
  nil
  arc> (- x y)
  Error: "reference to undefined identifier: _x"
as opposed to

  arc> (let x 10
         (prn:+ x 10)
         (let y -10
           (+ x y)))
  20
  0
  arc> (- x y)
  Error: "reference to undefined identifier: _x"
? If so, I'm not sure how to do it--I don't see a good way. However, there should be some way to write a macro w/temps such that

  (w/temps
    (tempset x 10)
    #;(...))
does what you want; it would be (at a minimum) tricky, though.


2 points by lacker 6132 days ago | link

The part I can't figure out is how to make

  (w/temps
    (def foo (x) (+ x y))
    (tempset y 10)
    (foo 5))
work correctly.

-----

1 point by aston 6132 days ago | link

Might wanna have w/temps work more like

  (w/temps x y
    (def foo (x) (+ x y))
    (tempset y 10)
    (foo 5))
That is, like a with, but with x and y set to some dummy values. You wouldn't even need a tempset then, right?

-----

2 points by bogomipz 6131 days ago | link

Right indeed. The normal way to do this would be;

  (with (y nil foo nil)
    (= foo (fn (x) (+ x y)))
    (= y 10)
    (foo 5))
You can't use 'def there because, unlike in Scheme, def always makes a global binding in Arc. Including x in the with is not necessary, by the way.

From the sound of it, this does not solve lacker's problem, however, because he does not know up front what variables he needs to declare.

-----

1 point by absz 6132 days ago | link

As a first cut, I would scan through to find the tempsets, take out the variables, and then expand to a let or with block now that you know their names.

-----

2 points by almkglor 6132 days ago | link

  (mac make-things-difficult (c v)
    (if (some-property v)
      `(tempset ,c ,v)
      `(if (another-property ,v)
          (tempset ,c ,v)
          (= ,c ,v))))

-----

1 point by absz 6132 days ago | link

Ah. Right. (And I even worried about similar things when writing make-br-fn...). Well, it would work in simple cases, but let/with are looking like better ideas.

Actually, if we add another primitive (with $ or xdef) which works using mzscheme's namespace-undefine-value!, we could have tempset maintain a global list of tempset variables, and cleartemps go through and undefine them.

-----