Arc Forumnew | comments | leaders | submitlogin
3 points by Jesin 6062 days ago | link | parent

Why are you complaining about def being redundant, instead of railing against let? Nobody will argue that let isn't redundant (although many will say that it's useful).

  arc> (macex1 '(let a b c d))
  (with (a b) c d)


1 point by tokipin 6061 days ago | link

i see 'let' as the core operator, and 'with' as the one that is redundant. you're right though. i wonder if they couldn't be combined into just let. i don't see the difficulty in something like

  (mac Let (first . rest)
       (if (alist first)
           `(with ,first ,@rest)
           `(let ,first ,@rest)))
(we need first-class macros so i can manufacture these things)

would there be any issues with something like that?

then you might ask, why don't we just merge everything so we only have two or three functions to work with?

  (def mathop args
       (map [apply _ args] '(+ - * /)))

  arc> ((mathop 3 2) 0)  ;addition
  5
but the intention isn't to merge everything for the sake of it, it's to simplify the surface "interface" for the programmer. fn/def and let/with are both things the programmer will use often

though in the case of let/with it may be more readable to keep the current setup since it saves the eyes the trouble of checking how many variables are bound, even though it's just a check for parens. i haven't programmed enough to really say

-----

4 points by absz 6061 days ago | link

Your Let fails on destructuring:

  (def mag (vec)
    (let (x y) vec
      (expt (+ (* x x) (* y y)) 1/2)))
Your Let would fail there, trying to bind x to y.

-----

1 point by tokipin 6061 days ago | link

ah, didn't know you could do that. thanks

-----

1 point by absz 6061 days ago | link

To be fair, that example would be more simply written

  (def mag ((x y))
    (expt (+ (* x x) (* y y)) 1/2))
, but destructuring in let does have real uses.

-----

1 point by eds 6061 days ago | link

I agree with you that 'let and 'with are redundant (although I still disagree about 'fn and 'def).

But I think the difference between the 'let and 'with forms would be removed better simply by removing the implicit progn. This was brought up previously in http://arclanguage.org/item?id=3234 .

This would allow (let a 1 form) like the current 'let, or (let a 1 b 2 form) like the current 'with. For multiple statements you would need (let a 1 (do forms)), but pg already said how he liked that 'do highlighted non-functional code.

-----