Arc Forumnew | comments | leaders | submitlogin
1 point by aw 5389 days ago | link | parent

but I can't see how those features could include adding to the syntax...

I'm not sure if this is what you mean, but if you want to create your own syntax, one option is to use http://awwx.ws/extend-readtable0. What this does is allow you to specify a particular character that you want to trigger a call to your own parser. When the reader sees that character, it calls your parser, which reads your syntax from the input and returns the Arc value that you want your syntax to generate.

For example, here's a simple syntax parser for literal tables (from http://awwx.ws/table-rw3):

  (def parse-table-items (port (o acc (table)))
    (scheme.skip-whitespace port)
    (if (is (peekc port) #\})
         (do (readc port) acc)
         (with (k (read port)
                v (read port))
           (= (acc k) v)
           (parse-table-items port acc))))

  (extend-readtable #\{ parse-table-items)
The example above returns a table value, but you can also return a list, which can then be expanded as a macro:

  arc> (extend-readtable #\@ (fn (port) `(at ,(read port))))
  #<void>
  arc> (read "@3")
  (at 3)
  arc> (mac at (v) `(+ ,v 1))
  #(tagged mac #<procedure: at>)
  arc> @3
  4