Commit 2716a4a1 authored by Liam M. Healy's avatar Liam M. Healy
Browse files

New macro if-defined, permit undefined conditionals

New macro if-defined permits defining conditionals where the test-form
clause will be NIL if the function is not yet defined, thereby
skipping the then-clause, which has function call that will be defined
when the test-form is. This replaces the hook special variable for
grid in #'nf.
parent 6279d898
;; Utility definitions
;; Liam Healy 2010-12-25 12:14:58EST utility.lisp
;; Time-stamp: <2011-08-24 17:06:36EDT utility.lisp>
;; Time-stamp: <2014-01-16 22:43:46EST utility.lisp>
;; Copyright 2011 Liam M. Healy, Paul Graham
;; Copyright 2011, 2014 Liam M. Healy, Paul Graham
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
......@@ -100,3 +100,10 @@
(if (listp tree)
(mapcar (alexandria:curry 'map-leaf function) tree)
(funcall function tree)))
;;; [[id:8ace8d99-72da-43a8-9f56-a82075de90ea][Additional branching when systems are loaded; if-defined]]
(defmacro if-defined (test-form then-form else-form)
"If the car of the test-form is fboundp and the result of applying to the rest of test-form is non-nil, then apply the car of then-form to (rest then-form). Otherwise, execute else-form. The test-form and then-form are s-expressions."
`(if (and (fboundp ',(first test-form)) (funcall ',(first test-form) ,@(rest test-form)))
(funcall ',(first then-form) ,@(rest then-form))
,else-form))
;; Format numerical output
;; Liam Healy Wed Dec 11 2002 - 16:37
;; Time-stamp: <2014-01-14 22:47:00EST format-output.lisp>
;; Time-stamp: <2014-01-16 22:06:11EST format-output.lisp>
;; Copyright 2011, 2013, 2014 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -70,9 +70,9 @@
(defgeneric nf (object &optional stream)
(:documentation "Format output for numerical objects. Default stream is *standard-output*.")
(:method ((object t) &optional (stream *standard-output*))
(if (and *nf-t-hook* (typep object (first *nf-t-hook*)))
(funcall (second *nf-t-hook*) object stream)
(princ object stream))))
(if-defined (grid::gridp object)
(grid::nf-grid object)
(princ object stream))))
(defun nf-string (object)
"Format output for numerical objects to a new string."
......
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