Arc Forumnew | comments | leaders | submitlogin
The proposed : syntax
10 points by EliAndrewC 6140 days ago | 17 comments
In the Arc FAQ on paulgraham.com Paul writes, "We may make the index of the cdr be the symbol n, so you could say (x 'n) to get the cdr. Then using the proposed : abbreviation (car x) becomes x:0 and (cdr x) becomes x:n."

Is there still a plan to do something like this? I was recently writing some code in Common Lisp which I ported to Arc which I think shows how this can improve readability. I've posted it to Pastebin to make sure that the indentation comes across:

http://pastebin.com/f17d88e20



9 points by fmota 6140 days ago | link

Another possibility (with pg asked me to post here) was to use : as a low-precedence infix apply operator.

I mentioned it at [http://reddit.com/r/programming/info/6710p/comments/c0317pb]. Here's the text:

----------

When programming in lisp you tend to accumulate parens on the right. One way to virtually eliminate this is to have a very low precedence infix operator apply, like Haskell's $. I used : in Atom:

Atom code - `(op: / _ 2)`

Arc code - `[/ _ 2]`

It also opens avenues to python-like block indentation syntax. For example...

Atom code:

    def (fact n):
        if (= n 0):
            1
            * n (fact: - n 1)
Arc code:

    (def (fact n)
        (if (eq n 0)
            1
            (* n (fact (- n 1)))))
This makes programming in Atom very different from programming in other Lisp dialects, but it's a feature I'd kill for... If Arc had it, I wouldn't have to design Atom. :P

----------- And then I clarified the meaning of the last example: -----------

Each line in the indented block is added to the if's line. For example:

    foo:
        bar
        baz
Is the same as:

    foo bar baz
And

    + 1:
        * x x
        * y y
is the same as

    + 1 (* x x) (* y y)
So, you see,

    if (predicate):
        (then-instr)
        (else-instr)
Is the same as

    if (predicate) (then-instr) (else-instr)

-----

2 points by bayareaguy 6139 days ago | link

Something doesn't look right here. I think I know what you're trying to propose but if

    foo:
        bar
        baz
is the same as

    foo bar baz
and

    if (predicate):
        (then-instr)
        (else-instr)
is the same as

    if (predicate) (then-instr) (else-instr)
then shouldn't the second example

    + 1:
        * x x
        * y y
be the same as

    + 1 * x x * y y
?

Or alternately if the indented lines gain implicit parens shouldn't

     foo:
        bar
        baz
be the same as

    foo (bar) (baz)

?

-----

3 points by fmota 6139 days ago | link

Yes, you stumbled right into the problem with this scheme. But it's not really a problem if you accept PG's idea that parens are allowed to be implicit whenever that is the only thing that makes sense.

So, in the case of

    + 1:
        * x x
        * y y
The parens around * x x and * y y are implicit.

-----

4 points by greatness 6140 days ago | link

(A) That looks suspiciously like python. (B) If it IS implemented at some point, I would not be against it, but that colon better be optional :p

-----

3 points by fmota 6140 days ago | link

(A) I love python. ;)

(B) Makes sense. After all, if you're going through the troubles of adding indentation, you might as well make the colon optional.

-----

3 points by chrisdone 6140 days ago | link

I have found s-expressions easier to edit with a smart editor than other syntaxes. Having to think again about the layout of syntax doesn't sound very appealing, but I would probably give it a try if someone implemented it.

-----

3 points by cratuki 6139 days ago | link

The more I think about this the more enthusiastic I am about it. Where are you going to go with it?

-----

2 points by fmota 6138 days ago | link

I'm prototyping an interpreter in Python, and then when it gets to the point that it's mostly executable, go from there.

-----

2 points by babo 6138 days ago | link

Is your code publicly available?

-----

2 points by cratuki 6139 days ago | link

I wonder if you could try implementing this as another compile step on top of arc (with another REPL layer, etc), and then see whether it becomes more popular to code with or without this.

-----

4 points by pg 6140 days ago | link

The most recent plan was to use e.g. x.y!z for (x y 'z).

I almost did this for the current release but left it out because I wasn't sure. I tried rewriting some code using it and it didn't really feel shorter. Whereas : as composition really does make programs shorter.

My current plan for syntax is to use chars in the middle of what would to earlier Lisps have been normal symbols. Restricting the introduction of syntax in this way keeps the Lispy feeling. So foo_bar for example will eventually mean something involving two symbols, foo and bar. But there are only so many characters I can make special in the midddle of symbols, and I don't want to use them up unless I'm sure.

-----

5 points by fab13n 6139 days ago | link

> But there are only so many characters I can make special in the midddle of symbols

Depends on whether you allow unicode in symbols

/ducks

-----

2 points by rkts 6140 days ago | link

It seems more natural to me if you reverse the meanings of . and !. I wouldn't expect x.y to mean that y is evaluated.

-----

2 points by icemaze 6140 days ago | link

Mhmm... I'm not sure. Personally, I prefer

  `((,curr))
to

  (list:list curr)
I think it's more readable.

-----

3 points by carbon 6140 days ago | link

I have been considering using Lisp one day, but I was discouraged by the lack of syntax. So I have created my one homoiconic syntax for my purposes. It has lists, but also tuples and records, and what can be most interesting for you - it has syntactic sugar, which I think can be adapted in Arc or in any other Lisp. If you are interested how I have solved it, have a look at: http://harpoon.sourceforge.net http://harpoon.sourceforge.net/sugar.html

-----

4 points by krustt_ar 6140 days ago | link

The last syntax in the example is amazingly clear to read for me (a non-lisp programmer that knows how lisp works).

-----

3 points by reitzensteinm 6140 days ago | link

I agree. It removes a lot of redundant characters. There are quite a few errors in the example (unless I'm missing something), but it sure looks a lot better, and the correct syntax would remove just as many (just be formatted a little differently).

Now this'll get me stoned, but what about combining it with a bracket pair that switches on infix? Here's the canonical factorial example in 3 views, implicit brackets on indentation and infix, implicit brackets on indentation, and standard Arc:

http://pastebin.com/f7a944cd5

The infix looks nicer (to me, but I'm also a non-lisp programmer that understands how lisp works), but probably isn't worth the cost of adding a whole new language element, not to mention precidence rules into the language itself. Representing longer math though it would probably get more and more succinct. I have to say, I'm really taken with the whole implicit brackets thing. The strong Python feel helps with readability (I use Python day to day).

-----