Created
September 14, 2018 18:47
-
-
Save y2q-actionman/6ff62c755bd00ccf54fcae277925fa34 to your computer and use it in GitHub Desktop.
land of lisp には game-read という関数があるらしい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; http://programcat.hatenablog.com/entry/2018/09/13/213126 | |
(in-package :cl-user) | |
;;; この定義すごい!、というかパッと読めない・・ | |
(defun game-read () | |
(let ((cmd (read-from-string | |
(concatenate 'string "(" (read-line) ")")))) | |
(flet ((quote-it (x) | |
(list 'quote x))) | |
(cons (car cmd) (mapcar #'quote-it (cdr cmd)))))) | |
;;; let* で展開してみる | |
(defun my-game-read () | |
(let* ((line (read-line)) | |
(parened (concatenate 'string "(" line ")")) | |
(cmd (read-from-string parened))) | |
(flet ((quote-it (x) | |
(list 'quote x))) | |
(cons (car cmd) (mapcar #'quote-it (cdr cmd)))))) | |
;;; loop 脳なので、すぐにこう書きたくなる。 | |
(defun my-game-read-2 () | |
(with-input-from-string (stream (read-line)) | |
(loop for first? = t then nil | |
for i = (read stream nil :eof) | |
until (eq i :eof) | |
collect (if first? | |
i | |
(list 'quote i))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment