Arc Forumnew | comments | leaders | submitlogin
1 point by absz 6083 days ago | link | parent

What about what cchooper proposed in http://arclanguage.org/item?id=4712 : ($car ...) == (map car ...)? That's straightforward to add, if we add a new macro: def-ss-, to add new ssyntax with lower precedence (def-ss+ can be defined by analogy):

  (mac def-ss- rest
    (let pairs (map (fn ((s e)) `(,(string s) ,e))
                    (pair rest))
      `(do (zap [join _ ',pairs]           ssyntaxes*)
           (zap [join _ ',(map car pairs)] ssyntax-strings*))))
  
  (= mac-seval $)
  (def-ss-
    $ (fn lists (apply map R lists))
    $ mac-seval)
. Then we have

  arc> ($car '((1 2) (3 4) (5 6)))
  (1 3 5)
(The reason $ is lower precedence is that then we can write things like $.sin.)


1 point by almkglor 6083 days ago | link

Actually the prefix $ will have to be higher precedence than . if we want to support $.sin syntax.

Basically what is done is, it scans linearly through the ssyntaxes* list, and performs the splitting at the time. So if the list is:

  $ prefix
  $ standalone
  :  infix
  ~prefix
  ~ standalone
  . infix
  ! infix
Then when processing $.sin, it will see the prefix $ first, so it will split it into {$, .sin} and attempt to return a curried 'map with '.sin

-----

1 point by absz 6083 days ago | link

Actually, that's precisely why it has to be lower precedence: we want $.sin to turn into ($ sin), so as to get at trig from mzscheme; if it were to become (map .sin ...), things would die because of the malformed ssyntax in .sin. (I tried it both ways, which is how I figured this out.)

-----

1 point by almkglor 6083 days ago | link

Ah, I think we have a misunderstanding here: from my point of view, objects earlier in the list have lower precedence to objects later in the list. ^^ So your "lower precedence" is my "higher precedence". Basically, it has to do with stuff like:

  foo!bar:qux!quux
which is compiled as:

  {{foo ! bar} : {qux ! quux}}
So !, which is listed later, has higher precedence (it gets grouped more tightly)

-----