Arc Forumnew | comments | leaders | submitlogin
3 points by conanite 5663 days ago | link | parent

Notes on intrasymbol +

I got a little shock with this:

  arc> (ssexpand '+.a.b)
  .a.b
  arc> (ssexpand 'a.+.b)
  (andf a. .b)
... but I guess this usage is sacrificed for the greater good of having andf compression. Gentle reminder that #\& wouldn't conflict with a pre-existing builtin function, while making intuitive sense.

Another little surprise:

  arc> (ssexpand '++x)
  x
  arc> (ssexpand 'x++)
  x
It's a pity to silently drop pre- and post-fix #\+, instead making special cases for '+ and '++. These are probably "valuable semantic space" - eg expand ++x to (++ x).

Final surprise: I wanted to try all the ssyntax together.

  arc> (ssexpand 'odd+~x.p)
  odd+~x.p
  arc> ; I expected (andf odd ~x.p)
I fiddled a bit with ac.scm to get what I wanted. The problem is that expand-ssyntax invokes expand-compose even if there is only a non-initial #\~ in the symbol. But expand-compose does nothing with non-initial #\~, so my test expression never gets expanded. This fix triggers expand-compose iff #\~ is the first character. Making #\~ have lower precedence than #\+ (as a comment in ac.scm suggests) should also do the trick, but I haven't tried that. (warning: manual diff)

    (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)))))
  +           (or (eqv? (string-ref name 0) #\~)
  +               (has-ssyntax-char? name (- (string-length name) 1))))))

    (define (has-ssyntax-char? string i)
      (and (>= i 0)
           (or (let ((c (string-ref string i)))
  -                  (or (eqv? c #\:) (eqv? c #\~)
  +                  (or (eqv? c #\:)
                     (eqv? c #\+)
                     ;(eqv? c #\_)
                     (eqv? c #\.)  (eqv? c #\!)))
               (has-ssyntax-char? string (- i 1)))))

...

    (define (expand-ssyntax sym)
  -   ((cond ((or (insym? #\: sym) (insym? #\~ sym)) expand-compose)
  +   ((cond ((or (insym? #\: sym) (symstart? #\~ sym)) expand-compose)
             ((insym? #\+ sym) expand-and)
         ;   ((insym? #\_ sym) expand-curry)
             ((or (insym? #\. sym) (insym? #\! sym)) expand-sexpr)
             (#t (error "Unknown ssyntax" sym)))
       sym))

  + (define (symstart? char sym) (eqv? char (car (symbol->chars sym))))
Now,

  arc> (ssexpand 'odd+~x.p)
  (andf odd ~x.p)
Hurrah!