Arc Forumnew | comments | leaders | submitlogin
A proposal (to Anarkists) for ssyntax definitions
5 points by almkglor 5789 days ago | 2 comments

  ; earlier defined ssyntaxes have *lower*
  ; precedence: thus means
  ; (foo (compose bar x))
    ; capital L means left associative:
    ; so means ((foo bar) z)
    #\. (L r)
    ; also means that foo!bar!z now works
    ; properly with nested tables/objects
    #\! (L 'r)
    ; means split by #\: and
    ; replace the ... with the list
    #\: (compose ...)
    ; since there's no L, this is
    ; a prefix
    #\~ (no R))
Implementation of def-ss

  (mac def-ss rest
    (let paired (pair rest)
      `(= ssyntaxes*
          ',(map car paired))))
Implementation of 'ssyntax:

  (def ssyntax (s)
    (and (isa s 'sym)
         (some [some _ ssyntax-chars*]
               (coerce (string s) 'cons))))
Implementation of 'ssexpand:

  (let (has-dot3 dot3 expansion-fun
        do-expansion expand) nil
    (= has
       (fn (s exp)
           (acons exp)
             (or (has-dot3:car exp)
                 (has-dot3:cdr exp))
           (is exp s)
    (= dot3
       (fn (ls exp)
         (if (acons ls)
             (if (caris ls '...)
                 (+ ls (dot3:cdr exp))
                 (cons (dot3:car exp)
                       (dot3:cdr exp)))
    (= expansion-fun
       (fn (post exp)
         (fn (l r)
           (with (l (post l)
                  r (post r))
           ((afn (e)
                (acons e)
                  (cons (self:car e)
                        (self:cdr e))
                (in e 'L 'l)
                (in e 'R 'r)
    (= do-expansion
       (fn (char ls exp post)
           (has '... exp)
             (dot3 (map post ls) exp)
           (has 'L exp)
             (reduce  (expansion-fun post exp)
           (has 'l exp)
             (rreduce (expansion-fun post exp)
           ; no L or l: prefix only
             (if (empty:ls 0)
               ((compose post (expansion-fun post exp))
                 nil (apply + (intersperse (string char)
               (post (apply + (intersperse (string char)
    (= expand
       (fn (s expansions)
         (if expansions
           (withs (((char expansion) . rest) expansions
                   ls (ssplit s [is _ char]))
             (if (> (len ls) 1)
                 (do-expansion char ls expansion
                   [expand _ rest])
                 (expand s rest)))
           (coerce s 'sym))))
    (def ssexpand (s)
      (if (isa s 'sym)
          (expand (string s) ssyntaxes*)
All code untested ^^

(yeah, someone really has to tell me to start working in the office instead of programming Arc)

2 points by almkglor 5786 days ago | link

Okay, this is now partly implemented on the git. There's a new file, ssyntax.arc, which contains an 'a-ssyntax and 'a-ssexpand function. Those functions will eventually replace the builtin Anarki 'ssyntax and 'ssexpand functions.

What I intend is that the underlying ac.scm will call the arc-world 'ssyntax and 'ssexpand functions. This means that the user can redefine 'ssyntax and 'ssexpand, and all future symbols,when compiled by ac.scm, will be compiled using that schema.


3 points by sacado 5788 days ago | link

now that's a fork :)