Category : Miscellaneous Language Source Code
Archive   : XSCHMDOC.ZIP
Filename : QQUOTE.S

Output of file : QQUOTE.S contained in archive : XSCHMDOC.ZIP
;;; QQUOTE.S 01-14-89 11:34 AM by John Armstrong

;; Expands QUASIQUOTE/UNQUOTE/UNQUOTE according to Rev^3 Report specs.
;; This file can be included as is in XSCHEME.INI, or can be incorporated
;; into MACROS.S, with expander functions anywhere and macros after
;; after definition of COMPILER-SYNTAX

;;; EXPANDER-FUNCTIONS: compilable under the core XSCHEME, can be evaluated
;;; independently of MACRO system

(define APPEND-ME-SYM (gensym)) ;; must be a gensym to avoid capture in
;; certain (pathological) situations

(lambda (l)
(qq-lev 0) ; always >= 0
(lambda (exp)
(let ((qq-car (qq (car exp)))
(qq-cdr (qq (cdr exp))))
(if (and (pair? qq-car)
(eq? (car qq-car) append-me-sym))
(list 'append (cdr qq-car) qq-cdr)
(list 'cons qq-car qq-cdr)))))
(lambda (exp)
(cond ((symbol? exp)
(list 'quote exp))
((vector? exp)
(list 'list->vector (qq (vector->list exp))))
((atom? exp) ; nil, number or boolean
((eq? (car exp) 'quasiquote)
(set! qq-lev (1+ qq-lev))
(let ((qq-val
(if (= qq-lev 1) ; min val after inc
; --> outermost level
(qq (cadr exp))
(qq-car-cdr exp))))
(set! qq-lev (-1+ qq-lev))
((or (eq? (car exp) 'unquote)
(eq? (car exp) 'unquote-splicing))
(set! qq-lev (-1+ qq-lev))
(let ((qq-val
(if (= qq-lev 0) ; min val
; --> outermost level
(if (eq? (car exp) 'unquote-splicing)
(cons append-me-sym
(%expand-macros (cadr exp)))
(%expand-macros (cadr exp)))
(qq-car-cdr exp))))
(set! qq-lev (1+ qq-lev))
(qq-car-cdr exp)))))
(let ((expansion (qq l)))
(if check-qq-expansion-flag
(check-qq-expansion expansion)) ; error on failure

(lambda (exp)
(cond ((vector? exp)
(check-qq-expansion (vector->list exp)))
((atom? exp)
(if (eq? (car exp) append-me-sym)
(error "UNQUOTE-SPLICING in unspliceable position"
(list 'unquote-splicing (cdr exp)))
(or (check-qq-expansion (car exp))
(check-qq-expansion (cdr exp))))))))

(define CHECK-QQ-EXPANSION-FLAG #t) ; do checking

(lambda (l) (error "UNQUOTE outside QUASIQUOTE" l)))

(lambda (l) (error "UNQUOTE SPLICING outside QUASIQUOTE" l)))

;;; MACROS: must be evaluated with MACRO system in place

(compiler-syntax QUASIQUOTE qq-expander)
(compiler-syntax UNQUOTE unq-expander)
(compiler-syntax UNQUOTE-SPLICING unq-spl-expander)

;;; END

  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : XSCHMDOC.ZIP
Filename : QQUOTE.S

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: