Arc Forumnew | comments | leaders | submitlogin
12 points by pg 5702 days ago | link | parent

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)