Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The idea of ``squaring''

Name: Anonymous 2012-07-16 4:40

How is the idea of ``squaring'' expressed?

Name: Anonymous 2012-07-16 6:11

(defclass multipliable-list () ((xs :type 'list :initarg :xs)))
(defgeneric get-multipliable-list-product (x))
(defmethod get-multipliable-list-product ((x multipliable-list))
  (reduce #'* (slot-value x 'xs)))

(defclass i-squarable () ((x :type number :initarg :x)))
(defclass squarable-number (i-squarable) ())

(defgeneric make-squarable-number-from-number (x))
(defmethod make-squarable-number-from-number ((x number))
  (make-instance 'squarable-number :x x))

(defgeneric make-multipliable-list-from-squarable (x))
(defmethod make-multipliable-list-from-squarable ((x i-squarable))
  (let ((num (slot-value x 'x)))
    (make-instance 'multipliable-list :xs (list num num))))

(defun square (x)
  (get-multipliable-list-product (make-multipliable-list-from-squarable (make-squarable-number-from-number x))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List