(defun combinationp (x &optional on-error)
"Is the form X a combination of a head and arguments,
to be evaluated as function call, macro call, or special form?"
- (and (consp x)
- (if on-error
- (or (listp #|not bothering with proper-list-p|# x) (error-behavior on-error x))
- t)))
+ (declare (ignorable on-error)) ;; I don't want to either import or duplicate alexandria:proper-list-p
+ ;;(and (consp x) (if on-error (or (proper-list-p x) (error-behavior on-error x)) t))
+ (consp x))
+
(defun literalp (x)
"predicate that tells whether X is the source form for a literal expression."
(typep x '(or boolean number character array keyword)))
(in-package :fare-utils)
(def*fun join-strings (strings &key stream separator)
- (with-output-stream (stream)
+ (with-output (stream)
(loop
:with sep = (->string separator)
:for (string . more-strings) :on strings :do
(unless (zerop l)
(subseq string 0 (1- l)))))
-(def*fun string-prefix-p (prefix string)
- (let* ((x (string prefix))
- (y (string string))
- (lx (length x))
- (ly (length y)))
- (and (<= lx ly) (string= x y :end2 lx))))
-
-(def*fun string-suffix-p (string suffix)
- (let* ((x (string string))
- (y (string suffix))
- (lx (length x))
- (ly (length y)))
- (and (<= ly lx) (string= x y :start1 (- lx ly)))))
-
-(def*fun string-enclosed-p (prefix string suffix)
- (and (string-prefix-p prefix string)
- (string-suffix-p string suffix)))
-
(def*fun string-strip-prefix (prefix string)
(when (string-prefix-p prefix string)
(subseq string (1+ (length prefix)))))
(in-package :fare-utils)
-(def*generic call-with-output-stream (x fun)
- (:documentation
- "Calls FUN with an actual stream argument, behaving like FORMAT with respect to stream'ing:
-If OBJ is a stream, use it as the stream.
-If OBJ is NIL, use a STRING-OUTPUT-STREAM as the stream, and return the resulting string.
-If OBJ is T, use *STANDARD-OUTPUT* as the stream.
-If OBJ is a string with a fill-pointer, use it as a string-output-stream.
-Otherwise, signal an error.")
- (:method ((x null) fun)
- (with-output-to-string (s) (funcall fun s)))
- (:method ((x (eql t)) fun)
- (funcall fun *standard-output*) nil)
- #-genera
- (:method ((x stream) fun)
- (funcall fun x) nil)
- (:method ((x string) fun)
- (assert (fill-pointer x))
- (with-output-to-string (s x) (funcall fun s)))
- (:method (x fun)
- (declare (ignorable fun))
- (cond
- #+genera
- ((typep x 'stream) (funcall fun x) nil)
- (t (error "not a valid stream designator ~S" x)))))
-
-(def*macro with-output-stream ((x &optional (value x)) &body body)
- `(call-with-output-stream ,value #'(lambda (,x) ,@body)))
-
-(def*generic call-with-input-stream (x fun)
- (:documentation
- "Calls FUN with an actual stream argument, coercing behaving like READ with respect to stream'ing:
-If OBJ is a stream, use it as the stream.
-If OBJ is NIL, use a STRING-OUTPUT-STREAM as the stream, and return the resulting string.
-If OBJ is T, use *STANDARD-OUTPUT* as the stream.
-If OBJ is a string with a fill-pointer, use it as a string-output-stream.
-Otherwise, signal an error.")
- (:method ((x null) fun)
- (funcall fun *terminal-io*))
- (:method ((x (eql t)) fun)
- (funcall fun *standard-input*) nil)
- #-genera
- (:method ((x stream) fun)
- (funcall fun x) nil)
- (:method ((x string) fun)
- (with-input-from-string (s x) (funcall fun s)))
- (:method (x fun)
- (declare (ignorable fun))
- (cond
- #+genera
- ((typep x 'stream) (funcall fun x) nil)
- (t (error "not a valid stream designator ~S" x)))))
-
-(def*macro with-input-stream ((x &optional (value x)) &body body)
- `(call-with-input-stream ,value #'(lambda (,x) ,@body)))
-
(def*parameter *standard-readtable* (copy-readtable nil))
(def*parameter *safe-package* :cl)