Arc Forumnew | comments | leaders | submitlogin
3 points by almkglor 5918 days ago | link | parent

Actually no - the problem is that you said:

  if          --->    (if
    test      --->      (test)
    exp       --->      (exp)
    test2     --->      (test2)
    exp2      --->      (exp2))
So, what if I need the variable test, not the function test? Suppose instead I have something like this:

  (if
    test
       (exp
          (exp2
             (very-long-exp3 5 6 7 8))
          (some-random-exp4))
    test2
       (exp5
          (exp6)
          (exp7)))
If a naked symbol all by itself becomes (symbol), how do I format the syntax if I need symbol, not (symbol)?


2 points by eds 5918 days ago | link

Yeah, I don't know what to do about that one. I've been thinking about it for a while, I just didn't know that was what you were asking.

I can't see any way to make indentation show you need just a symbol and not a function call with no arguments. You could add symbols, but that works against the removal of the parentheses in the first place.

Its a bit of a hack but if you had a simple read macro for an identity function you could do it. (Quote doesn't quite work because it prevents evaluation.) But say you had a function identity like such:

  (def identity (x) x)
And you defined a CL style read macro (e.g. $) to expand to (identity x). Then in my current function, because the read macro would expand before checking the subexpression to see if it was a list or not, you could do the following:

  if
    $test
      exp
        exp2
          very-long-exp3 5 6 7 8
        some-random-exp4
    $test2
      exp5
        exp6
          exp7
Which basically exchanges all the parentheses in the traditional version for a identity macro. Of course, it isn't exactly the same because you are adding extra meaning (the call to identity) to the expression. But maybe you could make it a macro instead of a function, and do the expansion at compile time (although this is dangerous because if you expanded the macro too soon you would defeat the purpose of using it in the first place...):

  (mac identity (x) x)
On the other hand you could alway just use traditional s-expressions in the middle of significant-indent code. The goal is to make parentheses optional, not to remove them entirely. Sometimes it may just be more convenient to leave them in than take them out.

-----

1 point by eds 5917 days ago | link

I just thought of another solution which might fix this problem without needing any special syntax characters.

If you consider that the reason we know to add parentheses around structures in the first place is the indentation of forms below the current line, then it is ambiguous whether a form with no nested forms should be wrapped in parentheses or not. If the system then does not assume the innermost forms are function calls, then it solves the problem of interpreting literals as function calls. Thus you can now do this:

  if
    test
    exp
      exp2
        (very-long-exp3 5 6 7 8)
      (some-random-exp4)
    test2
    exp5
      (exp6)
      (exp7)
Which cleans up many parentheses (removing all parentheses was never our goal in the first place), and doesn't result in the extra parentheses that were a problem before.

I found that it was trivial to implement this in my previous code. You can find the updated version at: http://blackthorncentral.net/files/read-indentation.scm

-----

1 point by almkglor 5917 days ago | link

Note that the above syntax is already what is pretty much the basis for all i-exprs in the mailinglist I posted, which is the main reason I posted the mailinglist.

-----