[movitz-cvs] CVS movitz/losp/muerte
ffjeld
ffjeld at common-lisp.net
Sun Jul 19 18:52:09 UTC 2009
Update of /project/movitz/cvsroot/movitz/losp/muerte
In directory cl-net:/tmp/cvs-serv16602
Modified Files:
complexes.lisp
Log Message:
Improved functions imagpart and realpart.
--- /project/movitz/cvsroot/movitz/losp/muerte/complexes.lisp 2008/07/09 20:17:46 1.3
+++ /project/movitz/cvsroot/movitz/losp/muerte/complexes.lisp 2009/07/19 18:52:08 1.4
@@ -6,7 +6,7 @@
;;;; Author: Frode Vatvedt Fjeld
;;;; Distribution: See the accompanying file COPYING.
;;;;
-;;;; $Id: complexes.lisp,v 1.3 2008/07/09 20:17:46 ffjeld Exp $
+;;;; $Id: complexes.lisp,v 1.4 2009/07/19 18:52:08 ffjeld Exp $
;;;;
;;;;------------------------------------------------------------------
@@ -17,8 +17,7 @@
(provide :muerte/complexes)
-(defstruct (complex (:constructor make-complex-number)
- (:conc-name #:||)
+(defstruct (complex (:constructor make-complex (realpart imagpart))
(:predicate complexp))
realpart
imagpart)
@@ -28,5 +27,23 @@
(check-type imagpart real)
(if (= 0 imagpart)
realpart
- (make-complex-number :realpart realpart
- :imagpart imagpart)))
+ (make-complex realpart imagpart)))
+
+(defmethod print-object ((x complex) stream)
+ (format stream "#c(~W ~W)"
+ (complex-realpart x)
+ (complex-imagpart x)))
+
+(defun realpart (x)
+ (etypecase x
+ (complex
+ (complex-realpart x))
+ (real
+ x)))
+
+(defun imagpart (x)
+ (etypecase x
+ (complex
+ (complex-imagpart x))
+ (real
+ 0)))
More information about the Movitz-cvs
mailing list