Arc Forumnew | comments | leaders | submitlogin
2 points by lacker 6133 days ago | link | parent

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 6133 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 6132 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 6133 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 6133 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 6133 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.

-----