[armedbear-devel] Problem with error reporting
Blake McBride
blake at mcbride.name
Sun Jan 23 23:22:14 UTC 2011
Dear Ville,
Enclosed are the samples you requested. The file error.lisp can
produce either error depending on witch code you uncomment.
Obviously, the errors are intended. The error message is what is in
question. To use, load clos-utils.lisp first and then error.lisp.
I hope this is helpful.
Thanks for your help.
Blake McBride
On Sun, Jan 23, 2011 at 12:41 PM, Ville Voutilainen
<ville.voutilainen at gmail.com> wrote:
> On 23 January 2011 20:15, Ville Voutilainen <ville.voutilainen at gmail.com> wrote:
>> return null. That fixes the (time) example Blake posted, and does the
>> right thing for type-errors
>> that used to print unboundValue. I'll go through the rest of Blake's
>> reports, see that the others
>> are fixed and will commit the patch after that.
>> Thanks for the reports, fixing this soon.
>
> Blake, do you have simple snippets that cause the slot/method printouts?
> I was unable to cause such printouts with some simple slot/method cases I've
> tried, so I need some tests to check whether I've fixed it all.
>
-------------- next part --------------
CLOS Tutorial when used with the clos-utils.lisp package.
Written by Blake McBride (blake at mcbride.name)
This tutorial assumes you know OO concepts coming from the Smalltalk,
Objective-C, C++, Java, or C# world. It also assumes you have a
working knowledge of Common Lisp but little understanding of CLOS.
This tutorial assumes you have loaded clos-utils.lisp like:
(load "clos-utils")
1. Class creation.
CLOS supports multiple inheritance. The order of the super classes
specified determines the order that methods are searched. The way
to create a class is outlined as follows:
(defclass2 class-name
(super-class-list)
(class-variables)
(instance-variables))
For example:
(defclass2 myclass () (cv1) (iv1 iv2))
This creates a class named 'myclass' with one class variable (slot)
named 'cv1' and two instance variables (slots) named 'iv1' and 'iv2'.
A sub-class of myclass can be created as follows:
(defclass2 mysubclass (myclass) (cv2) (iv3))
This creates a class 'mysubclass' which is a sub-class of 'myclass',
adds a class variable (slot) named 'cv2', and an instance variable
(slot) named 'iv3'. Because of inheritance, instances of mysubclass
would three instance variables iv1, iv2 and iv3. Mysubclass has a
class variable 'cv2' and shares a class variable 'cv1' with the
myclass class.
2. Creating instances
Create a variable i1 to contain an instance of myclass:
(defparameter i1 (make-instance myclass))
Create a variable i2 to contain an instance of mysubclass:
(defparameter i2 (make-instance mysubclass))
3. Setting and getting instance variables
Set slot 'iv1' of instance 'i1' to 55:
(set-slot i1 iv1 55)
Get the value of slot 'iv1' of instance 'i1':
(get-slot i1 iv1)
4. Setting and getting class variables
Set slot 'cv1' of class 'myclass' to 32:
(set-slot myclass cv1 32)
Get slot 'cv1' from class 'myclass':
(get-slot myclass cv1)
5. Creating an instance method
The following creates an instance method named 'addiv' that takes two
arguments named 'ins' and 'val'. The 'ins' argument is expected to be
an instance of 'myclass' or one of its sub-classes. This method simply
adds val to the the value of the instances' instance variable 'iv1'.
(defmethod addiv ((ins myclass) val)
(+ (get-slot ins iv1) val))
The new method can be used as follows:
(addiv i1 72)
6. Creating a class method
The following creates a class method named 'addcv' that takes two
arguments named 'ins' and 'val'. The 'ins' argument is expected to be
the class object 'myclass' or one of its sub-classes. This method simply
adds val to the the value of the class' instance variable 'cv1'.
(defmethod addcv ((ins meta-myclass) val)
(+ (get-slot ins cv1) val))
The new method can be used as follows:
(addcv myclass 42)
7. Other facilities
Returns the class of an (class or instance) object
(class-of i1)
(class-of myclass)
Find a class object from its name:
(find-class 'myclass)
Get a class' name:
(class-name myclass)
Get the name of an object's class:
(type-of i1)
Access slots as local variables:
(with-slots (iv1 iv2) i1
(setq iv1 17)
(setq iv2 49))
CLOS standard way of accessing slots:
(slot-value i1 'iv1)
(setf (slot-value i1 'iv1) 32)
8. Create a class with default slot values:
(defclass2 newclass ()
((cv1 :initform 42))
((iv1 :initform 36)
(iv2 :initform 11)))
9. Create a class with named initial values
(defclass2 class2 () ()
((iv1 :initarg :val)))
To use do:
(make-instance class2 :val 66)
This will create a new instance with iv1 set to 66.
10. Instance initialization method
(defmethod allocate-instance :after ((class meta-class1) &key)
...)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clos-utils.lisp
Type: application/octet-stream
Size: 1907 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20110123/9eb55ff9/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: error.lisp
Type: application/octet-stream
Size: 357 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20110123/9eb55ff9/attachment-0001.obj>
More information about the armedbear-devel
mailing list