Arc Forumnew | comments | leaders | submitlogin
Local variables
1 point by stefano 6153 days ago | 4 comments
In arc1 using (= varname value) creates a global variable. I would really appreciate if it created instead a local variable when used within a function: that way it would be possible to create local variables without passing through (let ...)or (with ...) forms, saving thus an extra indentation level every time a local variable is needed.


8 points by PJW 6153 days ago | link

pg once commented that this had some unexpected interactions with macros and dropped it for now or permanently. http://www.paulgraham.com/arclessons.html

-----

4 points by bogomipz 6153 days ago | link

Wasn't part of the problem that they made the innermost do the scope of the variable? What if they had used the outermost do instead? That would normally mean a def, which would be quite intuitive for the user.

The compiler should then be smart enough to figure out which closures actually make use of the variable and optimize away the overhead of holding onto a variable that is not needed.

-----

2 points by raymyers 6152 days ago | link

If you are using so many local variables that it is becoming a problem, you might need to reorganize. However, I would suggest declaring them all at the beginning and only losing one indentation level.

    arc> (with (a 1 b nil) (= b a) b)
    1
    arc> b
    Error: "reference to undefined identifier: _b"

-----

2 points by kennytilton 6152 days ago | link

you might need to reorganize

Amen. Try to think more functionally. "On Lisp" is available on-line, see chapter 3. The funny thing is that one can achieve good functional style by making one's code look a certain way.

-----