Arc Forumnew | comments | leaders | submitlogin
15 points by rntz 4117 days ago | link | parent

x!y!z is (x 'y 'z) rather than ((x 'y) 'z); likewise x.y.z. While perhaps not a bug per se, this is clearly undesirable (at some point, adding more infix dots is less clear than just parenthesising, so x!y!z for (x 'y 'z) is not very useful, but chaining lookups is common and is much nicer to read as x!y!z than ((x 'y) 'z)) and should be fairly simple to fix.


12 points by pg 4107 days ago | link

Ok, this is done.

    (define (expand-sexpr sym)
      (build-sexpr (reverse (tokens (lambda (c) (or (eqv? c #\.) (eqv? c #\!)))
                                    (symbol->chars sym)
                                    '()
                                    '()
                                    #t))
                   sym))

    (define (build-sexpr toks orig)
      (cond ((null? toks)
             'get)
            ((null? (cdr toks))
             (chars->value (car toks)))
            (#t
             (list (build-sexpr (cddr toks) orig)
                   (if (eqv? (cadr toks) #\!)
                       (list 'quote (chars->value (car toks)))
                       (if (or (eqv? (car toks) #\.) (eqv? (car toks) #\!))
                           (err "Bad ssyntax" orig)
                           (chars->value (car toks))))))))

    (define (tokens test source token acc keepsep?)
      (cond ((null? source)
             (reverse (cons (reverse token) acc)))
            ((test (car source))
             (tokens test
                     (cdr source)
                     '()
                     (let ((rec (if (null? token)
                                acc
                                (cons (reverse token) acc))))
                       (if keepsep?
                           (cons (car source) rec)
                           rec))
                     keepsep?))
            (#t
             (tokens test
                     (cdr source)
                     (cons (car source) token)
                     acc
                     keepsep?))))
get, incidentally, is a new operator defined thus:

    (def get (index) [_ index])
so

    arc> (map !a (list (obj a 1) (obj a 2)))
    (1 2)

-----

2 points by drcode 4117 days ago | link

seconded.

-----

2 points by conanite 4117 days ago | link

ditto

-----