diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-25 19:57:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-25 19:57:46 -0800 |
commit | 668209ba08049f1be25d8e5fec282df659c88aab (patch) | |
tree | a40773ec0a40bd32e77bbd3b10130aac152a55f0 | |
parent | fd7e0a944b77d1cbba91e323cd0679bf0d00652b (diff) | |
download | txr-668209ba08049f1be25d8e5fec282df659c88aab.tar.gz txr-668209ba08049f1be25d8e5fec282df659c88aab.tar.bz2 txr-668209ba08049f1be25d8e5fec282df659c88aab.zip |
Better no such type diagnostic in defmeth.
* share/txr/stdlib/struct.tl (sys:defmeth): New function.
Reacts to find-struct-type returning nil.
(defmeth): Logic moved into function.
-rw-r--r-- | share/txr/stdlib/struct.tl | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl index 8eb4d35c..5165fd29 100644 --- a/share/txr/stdlib/struct.tl +++ b/share/txr/stdlib/struct.tl @@ -209,9 +209,12 @@ (defmacro umeth (slot) ^(umethod ',slot)) +(defun sys:defmeth (type-sym name fun) + (let ((type (find-struct-type type-sym))) + (if type + (static-slot-ensure type-sym name fun) + (throwf 'eval-error "~s: ~s isn't a struct type" 'defmeth type-sym)))) + (defmacro defmeth (type-sym name arglist . body) - ^(progn - (static-slot-ensure (find-struct-type ',type-sym) ',name - (lambda ,arglist - (block ,name ,*body))) - ',name)) + ^(sys:defmeth ',type-sym ',name (lambda ,arglist + (block ,name ,*body)))) |