;;; -*- Mode:LISP; Package:USER; Readtable:ZL; Base:10 -*-

;;;This works -- everything (nearly) specified, not overlapping:

(defstruct (db :conc-name (:callable-constructors t))
  ((a nil 255.)
   (b (byte 4. 4.) 2.)
   (c (byte 4. 0.) 1.)))

(defun makedb (&key (a 255.) (b 1.) (c 1.))
  (dpb c (byte 4. 0.)
       (dpb b (byte 4. 4.)
	    (dpb a (byte 24. 0.) 0.))))

(defun test (a b c)
  (format t "~&structure: #b~24,'0B ~:*~D" (aref (make-db :a a :b b :c c) 0))
  (format t "~&as defun:  #b~24,'0B ~:*~D" (makedb :a a :b b :c c)))

(defstruct (db1 (:type :vector) :conc-name (:callable-constructors t))
  ;;;Bug: Structure subslot doesn't initialize w/out byte spec!!!
  ((a nil 0.)
   (b (byte 8. 0.) 255.)			;8 bits, all "1"
   (c (byte 4. 4.))))				;4 bits, all "0"

(defun makedb1 (&key (a 0.) (b 255.) (c 0.))
  (dpb c (byte 4. 4.)
       (dpb b (byte 8. 0.)
	    (dpb a (byte 24. 0.) 0.))))

(defun test1 (a b c)
  (format t "~&structure: #b~24,'0B ~:*~D" (aref (make-db1 :a a :b b :c c) 0))
  (format t "~&as defun:  #b~24,'0B ~:*~D" (makedb1 :a a :b b :c c)))

;;;This blows out because WHOLE is initialized to NIL:
(make-db1)
;;;This gets wrong value (should be 15)
(make-db1 :a 0 :b 255. :c 0)
(make-db1 :a 0 :b 0. :c 1)