Arc Forumnew | comments | leaders | submitlogin
Wart update: compose is now '+'
1 point by akkartik 4082 days ago | 5 comments
It's bothered me for a while now that ':' does double duty. At the start of a symbol it's part of the symbol[1], but inside it is an infix operator[2]. I just found a way to avoid this: pun '+'! Now I can stop treating ':' as an infix char.

https://github.com/akkartik/wart/commit/2bdb37bd50

The challenge in doing this was to figure out when '+' should mean compose. The first answer that comes to mind is, when the args are functions. But other types can also be coercible to functions (for using them in function position). So perhaps it should mean compose if the args are both coercible to function? But what if we later refine '+' for a type that is also coercible to function? What should win then?

The solution I went with was to compose only if one of the args is actually a function, without any coercions needed. I've never seen an example composing other types so far. The most I use so far is:

  (a (car x))
..where a is a list or hash table. That will continue to work. But let me know if you ever need to run:

  (a1 (a2 x))
where neither a1 nor a2 are functions.

Also, comments on the aesthetics of this choice most welcome. One way to overuse it:

  def (foo x)
    if ~list?.x
      list.x
      (foo+car.x + foo+cdr.x)
('+' also joins lists and strings: http://arclanguage.org/item?id=17048.)

---

Now that ':' has no infix duties, I can bring back comment tokens! http://arclanguage.org/item?id=16495

And I have another idea for it that I hope to show off soon.

---

[1] http://arclanguage.org/item?id=12657

[2] http://arclanguage.org/item?id=16775



2 points by rocketnia 4081 days ago | link

Here's a discussion I remember every time I think of whether or not to use + as an identifier character: http://arclanguage.org/item?id=10069 "Looks like the answer is to use & instead of +. I like the look of + better, but I can tell people are going to want to use it in names."

-----

1 point by akkartik 4081 days ago | link

..which I've already taken off the table :)

-----

2 points by rocketnia 4081 days ago | link

I don't know what my point was in posting that link--I mulled over it for a long time before just posting what I'd typed in--and now I don't understand your reply. What did you take off the table, and when? ^_^;

-----

2 points by akkartik 4081 days ago | link

:) I assumed you were saying that wart wouldn't be able to include '+' in symbol names, but that was already true before this change. Wart has other constraints, but if you can use '&' for something you can also use '+'.

Does that trigger memories? Did I understand you right? Were you nostalgic for the good old days when wart symbols could include '+'? ^_^

-----

2 points by rocketnia 4081 days ago | link

"I assumed you were saying that wart wouldn't be able to include '+' in symbol names, but that was already true before this change."

Ah, point taken! You were already treating + as infix. Got it. ^_^

-----