Arc Forumnew | comments | leaders | submitlogin
User defined symbol parsing or symbol macros
4 points by garym 6654 days ago | 3 comments
PG suggests that foo_bar will be some kind of magic symbol that is really infix syntax to deconstruct into some S-expression on foo and bar but is cautious of introducing any because he doesn't want to run out of special characters

My suggestion is to give users the power to define their own 'symbol macros' that hook into the symbol reader and expand into S-expressions. Kind of a way to let users define their own syntax but without it getting too complicated.

For example, let's say base symbols are made of letters,numbers and '-' and all the other characters are potentially special characters for symbol macros. Then maybe a notation for defining prefix,postfix and infix symbol-macros

; prefix symbol macro for '.' (symac .^ ...)

; postfix symbol macro for '.' (symac $. ...)

; infix symbol macro for '.' (symac ^.$ ...)

Then when the reader reads a symbol it evaluates from right to left expanding symbol macros as it goes

; symbol macros for a java style dotted notation (symac ^.$ `(get ^ '$))

so a symbol x.y.z expands to (get (get x 'y) 'z)

(symac #\$^ `(len ^))

arc>(= x '(1 2 3) arc>$x 3

(symac ^..$ (range ^ $))

arc> 0..3 (0 1 2 3)

You probably get the basic idea.



4 points by nex3 6654 days ago | link

I like the idea, although I'm not sure what your syntax is. All those ^s and $s start making it look like line noise.

Since we'd need to have a predefined set of "definable" operators anyway, why not just make the syntax as follows?

  (symac target.message
    `(send ,target ',message))

  (symac start..end `(range ,start ,end))

-----

3 points by pg 6653 days ago | link

I'll probably do something like this. I want to err on the side of making Arc customizable.

-----

1 point by treef 6653 days ago | link

great! This is a feature i would design a whole language for! But i will not have to if you do it.

-----