[Ecls-list] general funcallable instances
Brian Spilsbury
brian.spilsbury at gmail.com
Sat May 6 18:37:11 UTC 2006
This patch adds the ability to make any instance funcallable.
The reason for this is that the funcallable code is currently
hardcoded to do CLOS dispatch, and I need more general
funcallable support for some things that I'm doing.
This doesn't add a funcallable metaclass, but it shouldn't be
difficult to do so.
This works by having set-raw-funcallable dynamically add
or remove an extra slot at the end of the instance.
The funcall dispatcher then uses the last slot on an appropriately
marked instance as the function for that instance.
It isn't very elegant, but it should be invisible to existing code.
For example:
> (defstruct a b c d)
A
> (defvar y (make-a :b 1 :c 2 :d 3))
Y
> (si::set-raw-funcallable y (lambda () "Hello"))
#S(A :B 1 :C 2 :D 3)
> (funcall y)
"Hello"
> (si::set-raw-funcallable y nil)
#S(A :B 1 :C 2 :D 3)
> (funcall y)
#S(A :B 1 :C 2 :D 3) is not of type FUNCTION.
Broken at EVAL.
The code uses a magic number (2), which should be replaced with a
sensible constant, but I'm not sure what would be suitable.
Regards,
Brian.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 4434 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20060506/8e29cfde/attachment.obj>
More information about the ecl-devel
mailing list