Регистрация | Войти
Lisp — программируемый язык программирования
интерактивные строки с красивыми кавычками
Автор: Menschenkindlein - 2012-10-26T08:58:33.000000+04:00
(set-dispatch-macro-character #\# #\"
 (lambda (stream subchar arg)
   (declare (ignore subchar arg))
   (loop for char = (read-char stream)
         with waiting-sharp = nil
         with local-result
         with result doing
         (if waiting-sharp
             (case char
                   (#\# (push (coerce (nreverse local-result)
                                      'string
)

                              result
)

                        (push (list 'princ-to-string (read stream)) result)
                        (setf waiting-sharp nil local-result nil)
)

                   (#\" (setf waiting-sharp nil)
                        (push (coerce (nreverse local-result)
                                      'string
)

                              result
)

                        (return (append '(concatenate 'string)
                                        (nreverse result)
)
)
)

                   (otherwise (setf waiting-sharp nil)
                              (push #\# local-result)
                              (push char local-result)
)
)

             (if (char= char #\#)
                 (setf waiting-sharp t)
                 (push char local-result)
)
)
)
)
)
@2009-2013 lisper.ru