read a quoted name as the name
'-fields read as (- fields), so (cat name '-fields) built name(- fields). A quoted list keeps the rule: it is code a macro returns as often as not.
This commit is contained in:
15
reader.scm
15
reader.scm
@@ -111,7 +111,7 @@
|
||||
(let ((line (current-line)))
|
||||
(stamp (read-comment port) line)))
|
||||
((char=? c #\") (read-string-lit port))
|
||||
((char=? c #\') (get-ch port) (list 'quote (read-datum port)))
|
||||
((char=? c #\') (get-ch port) (list 'quote (read-quoted port)))
|
||||
((char=? c #\`) (get-ch port) (list 'quasiquote (read-datum port)))
|
||||
((char=? c #\,)
|
||||
(get-ch port)
|
||||
@@ -193,6 +193,16 @@
|
||||
(finish-atom (list->string (reverse chars)))
|
||||
(begin (get-ch port) (loop (cons c chars)))))))
|
||||
|
||||
;;; ...except quoted, alone: '-fields is a name, as in (cat name '-fields).
|
||||
;;; A quoted list is code a macro hands back as often as not, and keeps
|
||||
;;; the rule
|
||||
(define negating? (make-parameter #t))
|
||||
|
||||
(define (read-quoted port)
|
||||
(if (memv (peek port) '(#\( #\[ #\' #\` #\, #\# #\" #\;))
|
||||
(read-datum port)
|
||||
(parameterize ((negating? #f)) (read-datum port))))
|
||||
|
||||
(define (finish-atom s)
|
||||
(let ((digits (if (substring-index "_" s) (or (ungrouped s (or (c-radix s) 10)) s) s)))
|
||||
;; 017 is 17 to Scheme and 15 to C: whoever reads the Sex and whoever
|
||||
@@ -353,7 +363,8 @@
|
||||
;;; -INFINITY is (- INFINITY), as -1 is minus one. No name begins with
|
||||
;;; a dash, and an operator that does goes on with a non-letter: -> --
|
||||
(define (negated-name? s)
|
||||
(and (> (string-length s) 1)
|
||||
(and (negating?)
|
||||
(> (string-length s) 1)
|
||||
(char=? #\- (string-ref s 0))
|
||||
(let ((c (string-ref s 1)))
|
||||
(or (char-alphabetic? c) (char=? c #\_)))))
|
||||
|
||||
Reference in New Issue
Block a user