Create a polynomial object from a number using change-class
Posted
by charlieb
on Stack Overflow
See other posts from Stack Overflow
or by charlieb
Published on 2010-03-28T13:13:56Z
Indexed on
2010/03/28
14:33 UTC
Read the original article
Hit count: 453
I have written a polynomial class along the lines described in SICP 2.5.3 (except using defclass). I would like to be able to seamlessly add and multiply polynomials and regular numbers but I can't make change-class accept a number.
I tried to simplify the problem by changing class from an integer to a float:
(change-class 4 'float)
but that gave me the error:
There is no applicable method for the generic function
#<STANDARD-GENERIC-FUNCTION CHANGE-CLASS (7)>
when called with arguments
(4 #<BUILT-IN-CLASS FLOAT>).
[Condition of type SIMPLE-ERROR]
I get an error of the same form from (fyi):
(change-class 4 'polynomial)
I'm going to go ahead and implement a manual conversion but I would prefer to use the built-in clos facilities.
© Stack Overflow or respective owner