[cells-cvs] CVS kennysarc

ktilton ktilton at common-lisp.net
Sat Feb 2 23:30:56 UTC 2008


Update of /project/cells/cvsroot/kennysarc
In directory clnet:/tmp/cvs-serv27932

Modified Files:
	struct.arc 
Log Message:
better

--- /project/cells/cvsroot/kennysarc/struct.arc	2008/02/02 22:19:28	1.1
+++ /project/cells/cvsroot/kennysarc/struct.arc	2008/02/02 23:30:56	1.2
@@ -3,10 +3,12 @@
 (mac struct ((name (o pfx (string name "-"))) . slot-defs)
   (with (maker (coerce (+ "mk-" (string name)) 'sym)
           defmaker (coerce (+ "mk-def-" (string name)) 'sym)
-          fsd (map [if (acons _) _ (list _ nil)] slot-defs))
+          ;typdef (cons 'typ name)
+          )
     `(do
          (def ,defmaker ()
-           (listtab ',fsd))
+           ;(prn 'defmakersees ',(keep acons slot-defs))
+           (listtab ',(cons (list 'typ name) (keep acons slot-defs))))
 
          (def ,maker initargs
            (aif (keep [~find _ ',(map carif slot-defs)] (map car (pair initargs)))
@@ -17,17 +19,41 @@
 
          ,@(map (fn (sd)
                   `(def ,(coerce (+ (string pfx) (string sd)) 'sym) (self)
+                     (unless (is (self 'typ) ',name)
+                       (prn "This " self " is not a " ',name)
+                       (ero "Wrong struct for accessor")) ;; this was a wild guess and acts weird
                      (self ',sd))) (map carif slot-defs)))))
 
-(prn (macex '(struct (cell c-) awake rule (pulse 0))))
+;;; debug by viewing the macro-expansion...
 
-(struct (cell c-)
+;;; (prn (macex '(struct (cell c-) awake rule (pulse 0))))
+
+;;; now actually try it..
+
+(struct (cell c-) ;; the c- gets prefixed to all accessor names
  awake
  rule
- (pulse 0))
+ (pulse 0)) ;; that zero is a default value
+
+;;;(prn (mk-def-cell))
+
+(= c123 (mk-cell 'awake 1 'rule 2 'pulse 3))
 
-(prn (map [_ (mk-cell 'awake 1 'rule 2 'pulse 3)] (list c-awake c-rule c-pulse)))
+(prn "(1 2 3)? " (map [_ c123] (list c-awake c-rule c-pulse)))
+
+(prn "(1 2 0)? " (map [_ (mk-cell 'awake 1 'rule 2)] (list c-awake c-rule c-pulse)))
+
+(struct (cell2) ;; no prefix supplied means you auto-get cell2-
+  (pulse 0)
+  awake
+  rule
+  )
  
+(= c2 (mk-cell2 'awake 3 'rule 4))
 
+(prn "(3 4 0)? " (map [_ c2] (list cell2-awake cell2-rule cell2-pulse)))
             
-           
\ No newline at end of file
+(prn "please fail on wrong type...")
+
+(prn (c-pulse c2))
+




More information about the Cells-cvs mailing list