Skip to content

Instantly share code, notes, and snippets.

@cametan001
Created April 30, 2010 18:49
Show Gist options
  • Save cametan001/385607 to your computer and use it in GitHub Desktop.
Save cametan001/385607 to your computer and use it in GitHub Desktop.
CL-USER> #" " と \. を含みます。"#
" \" と \\. を含みます。"
CL-USER>
CL-USER> #>END
ここには何でも置けますよ: "、\、"#、や ># だって
置けちゃう。この文字列の読み込みを終わらせるには...END
"ここには何でも置けますよ: \"、\\、\"#、や ># だって
置けちゃう。この文字列の読み込みを終わらせるには..."
CL-USER>
;;; SHARP-DOUBLE-QUOTE
;; Scheme-style
(defun |#"-reader| (stream sub-char numarg)
(declare (ignore sub-char numarg))
(labels ((iter (chars prev)
(let ((curr (read-char stream)))
(if (and (char= prev #\") (char= curr #\#))
(reverse chars)
(iter (cons prev chars) curr)))))
(coerce (iter nil (read-char stream)) 'string)))
(set-dispatch-macro-character
#\# #\" #'|#"-reader|)
;;; SHARP-GREATER-THAN
;; Scheme-style
(defun |#>-reader| (stream sub-char numarg)
(declare (ignore sub-char numarg))
(labels ((foo (chars curr)
(if (char= #\newline curr)
(reverse chars)
(foo (cons curr chars) (read-char stream))))
(bar (curr pattern pointer output)
(if (null pointer)
(reverse (nthcdr (length pattern) output))
(bar (read-char stream) pattern
(if (char= (car pointer) curr)
(cdr pointer)
pattern) (cons curr output)))))
(let ((pattern (foo nil (read-char stream))))
(coerce (bar (read-char stream) pattern pattern nil) 'string))))
(set-dispatch-macro-character
#\# #\> #'|#>-reader|)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment