Commit 895f7864 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Define readtable; untested

parent c6dc3d78
;; Read timepoint specifications.
;; Liam Healy, Sat Feb 4 2006 - 12:17
;; Time-stamp: <2014-01-05 18:06:36EST read-time.lisp>
;; Time-stamp: <2014-10-04 22:09:02EDT read-time.lisp>
;; Copyright 2011, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -298,21 +298,20 @@
(read-timepoint string '(2 0 1 3 4 5)))))
|#
;;; Read timepoint with reader macro, e.g. #d1999-03-30T12:33:45.
;;; Is there any way to get this on additional listeners?
(set-dispatch-macro-character
#\# #\d
(lambda (stream subchar arg)
(declare (ignore subchar arg))
(let* ((string
(defun read-datime (stream subchar arg)
(declare (ignore subchar arg))
(let* ((string
(stream-to-string
stream
:terminate-if
(lambda (ch)
(not (or (alphanumericp ch)
(member ch '(#\: #\- #\.) :test #'char-equal)))))))
(unless *read-suppress*
(read-time string)))))
(unless *read-suppress*
(read-time string))))
;;; Read timepoint with reader macro, e.g. #d1999-03-30T12:33:45.
;;; Is there any way to get this on additional listeners?
;;; (set-dispatch-macro-character #\# #\d read-datime)
(defparameter *prehistoric* (read-timepoint "1900-01-01T00:00:00"))
;; Functions on grids
;; Liam Healy 2010-06-19 22:25:17EDT functions.lisp
;; Time-stamp: <2014-01-05 14:40:50EST functions.lisp>
;; Time-stamp: <2014-10-04 22:20:39EDT functions.lisp>
;; Copyright 2010, 2011, 2012, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -201,10 +201,7 @@
(defvar *row-separator* '^)
(export *row-separator*)
;;; Use #m to make the foreign-array
(set-dispatch-macro-character
#\# #\m
(lambda (stream subchar arg)
(defun read-grid (stream subchar arg)
(declare (ignore subchar))
(read-char stream)
(let ((list (read-delimited-list #\) stream)))
......@@ -217,8 +214,10 @@
:initial-contents
(if (find *row-separator* list)
(split-sequence:split-sequence *row-separator* list)
list))))))
list)))))
;;; Use #m to make the foreign-array
;;; (set-dispatch-macro-character #\# #\m read-grid)
;;;;****************************************************************************
;;;; Simple math functions
......
;; Define a new readtable
;; Liam Healy 2014-09-28 22:27:28EDT readtable.lisp
;; Time-stamp: <2014-10-04 21:56:36EDT readtable.lisp>
;; Copyright 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :antik)
(named-readtables:defreadtable antik
(:merge :standard)
(:macro-char #\# :dispatch)
(:dispatch-macro-char #\# #\_ #'read-physical-dimension-quantity)
(:dispatch-macro-char #\# #\d #'read-datime)
(:dispatch-macro-char #\# #\m #'grid:read-grid))
;; Physical dimension system definition
;; Liam Healy 2012-02-20 10:14:49EST physical-dimension.asd
;; Time-stamp: <2014-01-13 22:55:52EST physical-dimension.asd>
;; Time-stamp: <2014-10-04 22:08:01EDT physical-dimension.asd>
;; Copyright 2012, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -32,7 +32,8 @@
((:module init
:serial t
:components
((:file "pd-shadow-symbols")))
((:file "readtable")
(:file "pd-shadow-symbols")))
(:module physical-quantities
:serial t
:components
......
;; Objects that represent physical measurements.
;; Liam Healy Wed Mar 6 2002 - 09:04
;; Time-stamp: <2014-01-14 21:20:38EST physical-quantities.lisp>
;; Time-stamp: <2014-10-04 21:54:50EDT physical-quantities.lisp>
;; Copyright 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -317,22 +317,23 @@
(defun scalar-units-p (units)
(ignore-errors (parse-units units)))
(defun read-physical-dimension-quantity (stream subchar arg)
"Read the physical dimension quantity from the stream."
(declare (ignore subchar arg))
(let ((*zero-is-dimensionless* nil)
numerical-value units)
;; Tell the reader to read the things
(setf numerical-value (stream-to-string stream :terminator #\_)
units (read stream t nil t))
;; Make the PDQ if reading is not suppressed
(unless *read-suppress*
(make-pq
(read-from-string numerical-value)
units
(scalar-units-p units)))))
;;; Use #_ for physical dimension quantities, e.g. #_90_degree
(set-dispatch-macro-character
#\# #\_
(lambda (stream subchar arg)
(declare (ignore subchar arg))
(let ((*zero-is-dimensionless* nil)
numerical-value units)
;; Tell the reader to read the things
(setf numerical-value (stream-to-string stream :terminator #\_)
units (read stream t nil t))
;; Make the PDQ if reading is not suppressed
(unless *read-suppress*
(make-pq
(read-from-string numerical-value)
units
(scalar-units-p units))))))
;;; (set-dispatch-macro-character #\# #\_ read-physical-dimension-quantity)
(defmethod creation-form ((pq physical-quantity))
(creation-form-readably
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment