From 668209ba08049f1be25d8e5fec282df659c88aab Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 25 Nov 2015 19:57:46 -0800 Subject: 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. --- share/txr/stdlib/struct.tl | 13 ++++++++----- 1 file 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)))) -- cgit v1.2.3