X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/6ee1970906d33f0b1b2be20e2f8a4521a6ca514f..2c0aab07cc749aacc29c485f85537e0f0a3c9536:/src/pset-proto.lisp diff --git a/src/pset-proto.lisp b/src/pset-proto.lisp index e16e04c..2620585 100644 --- a/src/pset-proto.lisp +++ b/src/pset-proto.lisp @@ -86,52 +86,6 @@ :location (file-location location) :seenp seenp))) -(defun string-to-symbol - (string &key (package *package*) (swap-case t) (swap-hyphen t)) - "Convert STRING to a symbol in PACKAGE. - - Parse off a `PACKAGE:' prefix from STRING if necessary, to identify the - package; PACKAGE is used if there isn't a prefix. A doubled colon allows - access to internal symbols, and will intern if necessary. Note that - escape characters are /not/ processed; don't put colons in package names - if you want to use them from SOD property sets. - - The portions of the string are modified by `frob-identifier'; the - arguments SWAP-CASE and SWAP-HYPHEN are passed to `frob-identifier' to - control this process." - - (let* ((length (length string)) - (colon (position #\: string))) - (multiple-value-bind (start internalp) - (cond ((not colon) (values 0 t)) - ((and (< (1+ colon) length) - (char= (char string (1+ colon)) #\:)) - (values (+ colon 2) t)) - (t - (values (1+ colon) nil))) - (when colon - (let* ((package-name (if (zerop colon) "KEYWORD" - (frob-identifier (subseq string 0 colon) - :swap-case swap-case - :swap-hyphen swap-hyphen))) - (found (find-package package-name))) - (unless found - (error "Unknown package `~A'" package-name)) - (setf package found))) - (let ((name (frob-identifier (subseq string start) - :swap-case swap-case - :swap-hyphen swap-hyphen))) - (multiple-value-bind (symbol status) - (funcall (if internalp #'intern #'find-symbol) name package) - (cond ((or internalp (eq status :external)) - symbol) - ((not status) - (error "Symbol `~A' not found in package `~A'" - name (package-name package))) - (t - (error "Symbol `~A' not external in package `~A'" - name (package-name package))))))))) - (export 'coerce-property-value) (defgeneric coerce-property-value (value type wanted) (:documentation @@ -306,6 +260,7 @@ ;;;-------------------------------------------------------------------------- ;;; Utility macros. +(export 'default-slot-from-property) (defmacro default-slot-from-property ((instance slot &optional (slot-names t)) (pset property type @@ -317,7 +272,8 @@ We initialize SLOT in INSTANCE. In full: if PSET contains a property called NAME, then convert it to TYPE, bind the value to PVAR and evaluate CONVERT-FORMS -- these default to just using the property value. If - there's no property, and the slot is named in SLOT-NAMES and currently + there's no property, and DEFAULT-FORMS contains at least one non- + declaration form, and the slot is named in SLOT-NAMES and currently unbound, then evaluate DEFAULT-FORMS and use their value to compute the slot value." @@ -333,7 +289,8 @@ (setf (slot-value ,instance ,slot) (with-default-error-location (,floc) ,@(or convert-forms `(,pvar)))) - (default-slot (,instance ,slot ,slot-names) - ,@body))))))) + ,@(and body + `((default-slot (,instance ,slot ,slot-names) + ,@body))))))))) ;;;----- That's all, folks --------------------------------------------------