Arc Forumnew | comments | leaders | submitlogin
2 points by waterhouse 5138 days ago | link | parent

The function in ac.scm (in plain Arc) that expands ssyntax is this:

  (define (expand-ssyntax sym)
    ((cond ((or (insym? #\: sym) (insym? #\~ sym)) expand-compose)
           ((or (insym? #\. sym) (insym? #\! sym)) expand-sexpr)
           ((insym? #\& sym) expand-and)
       ;   ((insym? #\_ sym) expand-curry)
           (#t (error "Unknown ssyntax" sym)))
     sym))
You could modify that function directly, by sticking (if (eq? sym '.) '. <proceed-as-usual>) in front of it. Or, if the Anarki guys have been through it, I'm guessing they added a hook at the beginning of that function, and wrote another function that would make it easy to add things to the hook. Look for 'expand-ssyntax in ac.scm, and follow where it leads you.


3 points by rocketnia 5138 days ago | link

Changing ac.scm's 'expand-ssyntax will make Arc's 'ssyntax predicate incorrect. The exception should be added in here, where there happen to already be a few exceptions that are currently meaningless:

  (define (ssyntax? x)
    (and (symbol? x)
         (not (or (eqv? x '+) (eqv? x '++) (eqv? x '_)))
         (let ((name (symbol->string x)))
           (has-ssyntax-char? name (- (string-length name) 1)))))
(This is quoted from Anarki 'cause the source is handier for me right now.)

Note, however, that calling Arc's 'ssexpand will expand a symbol regardless of whether it's an exception. I don't know whether this is a bug or not; the workaround is just to check with 'ssyntax first if it matters.

-----

1 point by evanrmurphy 5136 days ago | link

Thanks for the tip, this is working well. The only minor issue I'm still dealing with on this is how to strip the dot of all special meaning except in the context of rest parameters.

By adding the dot ssyntax exception in ac and not applying the read-normal macro from the OP to #\., I've gotten this to work so long as dot is inside the scheme bars:

  ; Dot treated as a symbol when inside the bars

  arc> (= |.| 2)
  2
  arc> (is (+ 1 1) |.|)
  t

  ; It still works in the rest parameter context

  arc> (def foo (x . args)
         `(,x ,@args d))
  #<procedure: foo>
  arc> (foo 'a 'b 'c)
  (a b c d)

  ; But it doesn't work as a symbol without the bars.
  ; Note that (read-normal #\.) can make this work but
  ; it breaks the rest parameter case.

  arc> (= . 2)
  Error: "map: expects type <proper list> as 2nd argument,
  given: 2; other arguments were: #<procedure:ac-niltree>"
So I'm about 3/4 of the way there. :)

-----