Arc Forumnew | comments | leaders | submitlogin
3 points by typhon 4686 days ago | link | parent

Providing a string (or char) as first argument to + changes its behaviour so that it concatenates all its arguments into one big string.

See the definition of it in ac.scm :

  (xdef + (lambda args
           (cond ((null? args) 0)
                 ((char-or-string? (car args))
                  (apply string-append 
                         (map (lambda (a) (ar-coerce a 'string))
                              args)))
                 ((arc-list? (car args)) 
                  (ac-niltree (apply append (map ar-nil-terminate args))))
                 (#t (apply + args)))))


So, if you want to create an interpreter for "standard arc code" (i.e. vanilla arc), I think you have to recreate this behaviour, and all the other quirks of the functions defined in ac.scm and arc.arc, unless they are definitely bugs.


4 points by Pauan 4686 days ago | link

This effectively amounts to dispatching on the type of the first argument. You can see this in the definition for mappend and string:

  (def mappend (f . args)
    (apply + nil (apply map f args)))

  (def string args
    (apply + "" (map [coerce _ 'string] args)))
By passing nil as the first argument to +, it causes + to treat the remaining arguments as a list. Likewise, passing "" as the first argument causes it to be treated as a string. I much prefer this model to JavaScript's somewhat insane model where it takes both arguments into account.

With Arc, it's simple: the return type of + is always the same as the type of the first argument to +. I can understand if you (dido) don't like this kind of polymorphism or implicit coercion, but it does fit in well with Arc's philosophy.

I would also like to note that if it were up to me, (+ 'foo "bar") would also be valid: it would return the symbol 'foobar. And (+ (obj a 1) (obj b 2)) would return (obj a 1 b 2). Arc 3.1 doesn't do this by default, though, unfortunately.

I would also like to point out that I'm not against using + for only addition. In Arubic I would probably prefer a different operator for concatenation, like `join`, or maybe `cat`.

---

Here's an old thread where we discussed this issue a bit: http://arclanguage.org/item?id=14057

And an even older one: http://arclanguage.org/item?id=12347

-----

2 points by dido 4686 days ago | link

Well, I don't have a great dislike for overloading operators per se. I don't mind the fact that you can add together arguments of many different numeric types together and get a reasonable result (I was particularly irked by the +. operator in Ocaml for example). What I don't particularly like is that the + operator is used as a concatenation operator as well as an addition operator. The two operations are not at all the same, and using one operator to do both things seems more troublesome than not. I even remember that Paul Graham once wrote that he felt that using + in that way was not such a good idea after all for many of the same reasons, but unfortunately it seems that that opinion didn't quite gain traction in the most recent versions of Arc that have come down to us.

Well, I suppose I'll just have to suck it up, my personal opinions aside. I set out to make with Arcueid a C implementation of Arc, not my own personal Arc dialect. The most recent git head now accepts this behavior.

-----

3 points by rocketnia 4686 days ago | link

"Well, I suppose I'll just have to suck it up, my personal opinions aside. I set out to make with Arcueid a C implementation of Arc, not my own personal Arc dialect."

Once you start down the Arc path, forever will it dominate your destiny. :-p Really though, I'm glad to hear you're seeing your goal through before you veer off in some other direction.

For a while Rainbow has been the fastest Arc implementation, by my measure. Now Rainbow.js and Nu have come along and challenge that, and with Arcueid there's a C competitor in the race as well. :)

-----

3 points by Pauan 4686 days ago | link

"Now Rainbow.js and Nu have come along and challenge that"

While Nu is drastically faster in certain areas, like the + function, in general it's slower than Arc 3.1 (by my estimates, about 5-10%). Unfortunately any Arc implementation built on Racket will have a hard time beating Arc 3.1's speed, simply because Arc 3.1 already pushes Racket pretty far. To get faster, I think you'd either need to find some serious oversight in Arc 3.1, or use Racket's modules.

-----

1 point by rocketnia 4686 days ago | link

Oh, sorry. :) Because of your your active work to make it fast, I figured it would challenge at least Arc 3.1, if not Rainbow, and I guess I got carried away. :-p

While you could probably trivially start from Arc 3.1 and streamline things here and there (like '+), you have a point about Nu adding other features.

-----

2 points by Pauan 4686 days ago | link

That's right, and because the compiler is only a (small but important) part of Arc, I can only do so much. Arubic, however, can potentially be a lot faster than Arc 3.1, because it makes many more changes to the language. But that's a different topic.

Anyways, the only real reason Nu would be slower than Arc 3.1 is because it wraps every global Arc variable in a function. This is so useful that I consider it worth the 5-10% performance hit.

-----

1 point by rocketnia 4686 days ago | link

Whoops, you replied while I was in the middle of editing my comment, in case that makes a difference. (It doesn't look like it does.)

-----

2 points by Pauan 4686 days ago | link

"Well, I suppose I'll just have to suck it up, my personal opinions aside. I set out to make with Arcueid a C implementation of Arc, not my own personal Arc dialect."

I too struggled with this. I wanted to change ar significantly in ways that I considered better. Then when I started the Nu project, it too made many incompatible changes to Arc 3.1. I still believe these ideas are good and improve Arc 3.1, but they're incompatible nonetheless.

But now my opinion is that any new language based on Arc should be cleanly separated. So I've started my work on Arubic (my own language based on Arc) as a separate project from Nu. To be more specific, it's one language implemented with Nu, the other one being Arc 3.1.

So now the Nu compiler should be very compatible with Arc 3.1, and any incompatible changes (like Arubic) will be implemented as something akin to a module or library. I think, ideally, an Arc implementation should be reasonably compatible with Arc 3.1, but still allow you to easily change it into a different language if you wish.

-----

1 point by rocketnia 4686 days ago | link

"What I don't particularly like is that the + operator is used as a concatenation operator as well as an addition operator. The two operations are not at all the same, and using one operator to do both things seems more troublesome than not."

Concatenation has an identity element, and it's associative, making it a monoid operation. I just think of '+ as a polymorphic monoid operation. When the monoid is a group, unary '- comes in to be an inverse operator. When the group is a field, '* comes in to be a multiplication operator, with unary '/ as its inverse.

So I don't have any mathematical objection to using '+ for concatenation, and I actually think it fits quite well. I've even thought about using '+ for function composition, since that's another monoid. (However, recently I've been more attracted to the idea of managing each monoid theory as a separate entity, rather than sniffing the arguments to figure out which operation to use. This is made easy by Haskell type classes, which essentially do the sniffing at compile time based on the static type system.)

As it happens, I've talked about monoid '+ before, in a thread other than the ones Pauan linked to: http://arclanguage.org/item?id=13018

-----

3 points by typhon 4686 days ago | link

Thank you for this. Your excellent links make me think that, while it is obviously a good idea to have an arc-powered arc forum, it would probably be a good idea not to have it behave like HN and more like a regular forum.

While it make sense for a news aggregator to prevent thread necromancy in order to have only fresh content on the new page, on a forum like this, it only provokes burying of interesting content, (especially painful since we no longer have a custom search) and needless thread duplications.

Hmm, maybe I should create another thread for this.

-----

1 point by Pauan 4686 days ago | link

This has been brought up before, multiple times I believe. Unfortunately no competitor or substitute to the Arc forum has become popular, so it looks like we're stuck with it for the near future.

Right now it seems to me that the best alternative to the Arc forum would be convore[1], which ar uses[2]. It has some problems, though. In particular I remember it being quite difficult to paste in code snippets. That would be problematic for a forum related to Arc. Any other suggestions?

---

* [1]: https://convore.com/

* [2]: https://convore.com/arc-runtime-project/

-----

1 point by kinleyd 4685 days ago | link

I agree. The Arc community will be better served with more forum focused ways to highlight important/useful threads no matter how old. Dedicated threads with high visibility, including sticky posts within those threads, are used to great effect at many successful community sites.

And search is a huge missing feature on this forum. Googling Arc Forum helps, but not the same thing.

-----