Arc Forumnew | comments | leaders | submitlogin
let and with
3 points by projectileboy 5948 days ago | 5 comments
From the tutorial:

There are two commonly used operators for establishing temporary variables, let and with. The first is for just one variable.

arc> (let x 1 (+ x (* x 2))) 3

To bind multiple variables, use with.

arc> (with (x 3 y 4) (sqrt (+ (expt x 2) (expt y 2))))

I know this is nitpicky, but can we just have one operator, "let" or "with", that can take one or more variable bindings? It seems to me like a win (however minor) when you can get rid of something.



4 points by randallsquared 5948 days ago | link

"It seems to me like a win (however minor) when you can get rid of something."

I actually like the Arc way, in this case. What was gotten rid of was extra parens. I think that

(let x 1 ...)

(with (x 1 y 2) ...)

are more readable than

(let ((x 1)) ...)

(let ((x 1) (y 2)) ...)

-----

3 points by elibarzilay 5948 days ago | link

If you mean a single form, then that won't work, because arc destructures values. For example:

  (let (x y) (list 1 2) (+ x y))

-----

2 points by nzc 5948 days ago | link

Yeah, I agree with this, although as a Lisp programmer I may be biased.

And while we're at it, is with like CL "let" or "let*"?

-----

6 points by elibarzilay 5948 days ago | link

Easy to check yourself -- try this:

  (with (x 1 y 2) (with (x y y x) (list x y)))

-----

3 points by chaos 5948 days ago | link

There is also withs:

    (withs (x 1 y 2) (withs (x y y x) (list x y)))

-----