Arc Forumnew | comments | leaders | submitlogin
Proposal for LET
2 points by tc-rucho 5602 days ago | 2 comments
Whenever I need to refactor some code and bind some stuff, I usually have to replace a LET or two and put a WITH, but this rises the question "why not have a LET that behaves like the new EACH?"

  (let (binding0 value0
        binding1 value1)
    ...)
LET would keep it's current behaviour, but when the first argument is a list, it would behave like a WITH. I think it doesn't make much sense to have two functions for the exactly same thing, and making LET work this way would make the code a little more intuitive for any CL/Scheme user.


5 points by absz 5602 days ago | link

This has come up before; see particularly http://arclanguage.org/item?id=6759 . The reason you can't just do this is that Arc supports list destructuring on variable binding; to wit,

  (def stats (data)
    (list (reduce + data) (avg data)))
  
  (let (sum avg) (stats '(1 2 3 4 5))
    (prn (string "sum = " sum ", avg = " avg)))
  
  ; Output: sum = 15, avg = 3
Thus, even if the first argument is a list, let has well-defined semantics. An alternative in the thread I linked to is to remove the implicit do (either modifying let or creating a new macro given), which never requires parenthesizing the arguments but requires an explicit do if its body contains more than one statement; I still think is is a good idea.

-----

1 point by tc-rucho 5602 days ago | link

Ouch, didn't know abut this. Thanks a ton.

-----