Megatest

Hex Artifact Content
Login

Artifact 225b8827e5b35ba20b5aa9f8d92c84a3af207a32:


0000: 0a 3b 3b 20 43 6f 70 79 72 69 67 68 74 20 32 30  .;; Copyright 20
0010: 30 36 2d 32 30 31 32 2c 20 4d 61 74 74 68 65 77  06-2012, Matthew
0020: 20 57 65 6c 6c 61 6e 64 2e 0a 3b 3b 20 0a 3b 3b   Welland..;; .;;
0030: 20 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69    This program i
0040: 73 20 6d 61 64 65 20 61 76 61 69 6c 61 62 6c 65  s made available
0050: 20 75 6e 64 65 72 20 74 68 65 20 47 4e 55 20 47   under the GNU G
0060: 50 4c 20 76 65 72 73 69 6f 6e 20 32 2e 30 20 6f  PL version 2.0 o
0070: 72 0a 3b 3b 20 20 67 72 65 61 74 65 72 2e 20 53  r.;;  greater. S
0080: 65 65 20 74 68 65 20 61 63 63 6f 6d 70 61 6e 79  ee the accompany
0090: 69 6e 67 20 66 69 6c 65 20 43 4f 50 59 49 4e 47  ing file COPYING
00a0: 20 66 6f 72 20 64 65 74 61 69 6c 73 2e 0a 3b 3b   for details..;;
00b0: 20 0a 3b 3b 20 20 54 68 69 73 20 70 72 6f 67 72   .;;  This progr
00c0: 61 6d 20 69 73 20 64 69 73 74 72 69 62 75 74 65  am is distribute
00d0: 64 20 57 49 54 48 4f 55 54 20 41 4e 59 20 57 41  d WITHOUT ANY WA
00e0: 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 74 20  RRANTY; without 
00f0: 65 76 65 6e 20 74 68 65 0a 3b 3b 20 20 69 6d 70  even the.;;  imp
0100: 6c 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66  lied warranty of
0110: 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 59   MERCHANTABILITY
0120: 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 20   or FITNESS FOR 
0130: 41 20 50 41 52 54 49 43 55 4c 41 52 0a 3b 3b 20  A PARTICULAR.;; 
0140: 20 50 55 52 50 4f 53 45 2e 0a 0a 0a 3b 3b 20 28   PURPOSE....;; (
0150: 64 65 66 69 6e 65 20 69 74 65 6d 64 61 74 20 27  define itemdat '
0160: 28 28 72 69 70 65 6e 65 73 73 20 20 20 20 22 67  ((ripeness    "g
0170: 72 65 65 6e 20 72 69 70 65 20 6f 76 65 72 72 69  reen ripe overri
0180: 70 65 22 29 0a 3b 3b 20 09 09 20 20 20 20 20 28  pe").;; ..     (
0190: 74 65 6d 70 65 72 61 74 75 72 65 20 22 63 6f 6f  temperature "coo
01a0: 6c 20 6d 65 64 69 75 6d 20 68 6f 74 22 29 0a 3b  l medium hot").;
01b0: 3b 20 09 09 20 20 20 20 20 28 73 65 61 73 6f 6e  ; ..     (season
01c0: 20 20 20 20 20 20 22 73 75 6d 6d 65 72 20 77 69        "summer wi
01d0: 6e 74 65 72 20 66 61 6c 6c 20 73 70 72 69 6e 67  nter fall spring
01e0: 22 29 29 29 0a 0a 28 64 65 63 6c 61 72 65 20 28  ")))..(declare (
01f0: 75 6e 69 74 20 69 74 65 6d 73 29 29 0a 28 64 65  unit items)).(de
0200: 63 6c 61 72 65 20 28 75 73 65 73 20 63 6f 6d 6d  clare (uses comm
0210: 6f 6e 29 29 0a 0a 28 69 6e 63 6c 75 64 65 20 22  on))..(include "
0220: 63 6f 6d 6d 6f 6e 5f 72 65 63 6f 72 64 73 2e 73  common_records.s
0230: 63 6d 22 29 0a 0a 3b 3b 20 50 75 74 73 20 6f 75  cm")..;; Puts ou
0240: 74 20 61 6c 6c 20 63 6f 6d 62 69 6e 61 74 69 6f  t all combinatio
0250: 6e 73 0a 28 64 65 66 69 6e 65 20 28 70 72 6f 63  ns.(define (proc
0260: 65 73 73 2d 69 74 65 6d 6c 69 73 74 20 68 69 65  ess-itemlist hie
0270: 72 64 65 70 74 68 20 63 75 72 72 69 74 65 6d 6b  rdepth curritemk
0280: 65 79 20 69 74 65 6d 6c 69 73 74 29 0a 20 20 28  ey itemlist).  (
0290: 6c 65 74 20 28 28 72 65 73 20 27 28 29 29 29 0a  let ((res '())).
02a0: 20 20 20 20 28 69 66 20 28 6e 6f 74 20 68 69 65      (if (not hie
02b0: 72 64 65 70 74 68 29 0a 09 28 73 65 74 21 20 68  rdepth)..(set! h
02c0: 69 65 72 64 65 70 74 68 20 28 6c 65 6e 67 74 68  ierdepth (length
02d0: 20 69 74 65 6d 6c 69 73 74 29 29 29 0a 20 20 20   itemlist))).   
02e0: 20 28 6c 65 74 20 6c 6f 6f 70 20 28 28 68 65 64   (let loop ((hed
02f0: 20 28 63 61 72 20 69 74 65 6d 6c 69 73 74 29 29   (car itemlist))
0300: 0a 09 20 20 20 20 20 20 20 28 74 61 6c 20 28 63  ..       (tal (c
0310: 64 72 20 69 74 65 6d 6c 69 73 74 29 29 29 0a 20  dr itemlist))). 
0320: 20 20 20 20 20 28 69 66 20 28 6e 75 6c 6c 3f 20       (if (null? 
0330: 74 61 6c 29 0a 09 20 20 28 66 6f 72 2d 65 61 63  tal)..  (for-eac
0340: 68 20 28 6c 61 6d 62 64 61 20 28 69 74 65 6d 29  h (lambda (item)
0350: 0a 09 09 20 20 20 20 20 20 28 69 66 20 28 3e 20  ...      (if (> 
0360: 28 6c 65 6e 67 74 68 20 63 75 72 72 69 74 65 6d  (length curritem
0370: 6b 65 79 29 20 28 2d 20 68 69 65 72 64 65 70 74  key) (- hierdept
0380: 68 20 32 29 29 0a 09 09 09 20 20 28 73 65 74 21  h 2))....  (set!
0390: 20 72 65 73 20 28 61 70 70 65 6e 64 20 72 65 73   res (append res
03a0: 20 28 6c 69 73 74 20 28 61 70 70 65 6e 64 20 63   (list (append c
03b0: 75 72 72 69 74 65 6d 6b 65 79 20 28 6c 69 73 74  urritemkey (list
03c0: 20 28 6c 69 73 74 20 28 63 61 72 20 68 65 64 29   (list (car hed)
03d0: 20 69 74 65 6d 29 29 29 29 29 29 29 29 0a 09 09   item))))))))...
03e0: 20 20 20 20 28 63 61 64 72 20 68 65 64 29 29 0a      (cadr hed)).
03f0: 09 20 20 28 62 65 67 69 6e 0a 09 20 20 20 20 28  .  (begin..    (
0400: 66 6f 72 2d 65 61 63 68 20 28 6c 61 6d 62 64 61  for-each (lambda
0410: 20 28 69 74 65 6d 29 0a 09 09 09 28 73 65 74 21   (item)....(set!
0420: 20 72 65 73 20 28 61 70 70 65 6e 64 20 72 65 73   res (append res
0430: 20 28 70 72 6f 63 65 73 73 2d 69 74 65 6d 6c 69   (process-itemli
0440: 73 74 20 68 69 65 72 64 65 70 74 68 20 28 61 70  st hierdepth (ap
0450: 70 65 6e 64 20 63 75 72 72 69 74 65 6d 6b 65 79  pend curritemkey
0460: 20 28 6c 69 73 74 20 28 6c 69 73 74 20 28 63 61   (list (list (ca
0470: 72 20 68 65 64 29 20 69 74 65 6d 29 29 29 20 74  r hed) item))) t
0480: 61 6c 29 29 29 29 0a 09 09 20 20 20 20 20 20 28  al))))...      (
0490: 63 61 64 72 20 68 65 64 29 29 0a 09 20 20 20 20  cadr hed))..    
04a0: 28 6c 6f 6f 70 20 28 63 61 72 20 74 61 6c 29 28  (loop (car tal)(
04b0: 63 64 72 20 74 61 6c 29 29 29 29 29 0a 20 20 20  cdr tal))))).   
04c0: 20 72 65 73 29 29 0a 0a 3b 3b 20 50 75 74 73 20   res))..;; Puts 
04d0: 6f 75 74 20 61 6c 6c 20 63 6f 6d 62 69 6e 61 74  out all combinat
04e0: 69 6f 6e 73 0a 28 64 65 66 69 6e 65 20 28 70 72  ions.(define (pr
04f0: 6f 63 65 73 73 2d 69 74 65 6d 6c 69 73 74 20 68  ocess-itemlist h
0500: 69 65 72 64 65 70 74 68 20 63 75 72 72 69 74 65  ierdepth currite
0510: 6d 6b 65 79 20 69 74 65 6d 6c 69 73 74 29 0a 20  mkey itemlist). 
0520: 20 28 6c 65 74 20 28 28 72 65 73 20 27 28 29 29   (let ((res '())
0530: 29 0a 20 20 20 20 28 69 66 20 28 6e 6f 74 20 68  ).    (if (not h
0540: 69 65 72 64 65 70 74 68 29 0a 09 28 73 65 74 21  ierdepth)..(set!
0550: 20 68 69 65 72 64 65 70 74 68 20 28 6c 65 6e 67   hierdepth (leng
0560: 74 68 20 69 74 65 6d 6c 69 73 74 29 29 29 0a 20  th itemlist))). 
0570: 20 20 20 28 6c 65 74 20 6c 6f 6f 70 20 28 28 68     (let loop ((h
0580: 65 64 20 28 63 61 72 20 69 74 65 6d 6c 69 73 74  ed (car itemlist
0590: 29 29 0a 09 20 20 20 20 20 20 20 28 74 61 6c 20  ))..       (tal 
05a0: 28 63 64 72 20 69 74 65 6d 6c 69 73 74 29 29 29  (cdr itemlist)))
05b0: 0a 20 20 20 20 20 20 28 69 66 20 28 6e 75 6c 6c  .      (if (null
05c0: 3f 20 74 61 6c 29 0a 09 20 20 28 66 6f 72 2d 65  ? tal)..  (for-e
05d0: 61 63 68 20 28 6c 61 6d 62 64 61 20 28 69 74 65  ach (lambda (ite
05e0: 6d 29 0a 09 09 20 20 20 20 20 20 28 69 66 20 28  m)...      (if (
05f0: 3e 20 28 6c 65 6e 67 74 68 20 63 75 72 72 69 74  > (length currit
0600: 65 6d 6b 65 79 29 20 28 2d 20 68 69 65 72 64 65  emkey) (- hierde
0610: 70 74 68 20 32 29 29 0a 09 09 09 20 20 28 73 65  pth 2))....  (se
0620: 74 21 20 72 65 73 20 28 61 70 70 65 6e 64 20 72  t! res (append r
0630: 65 73 20 28 6c 69 73 74 20 28 61 70 70 65 6e 64  es (list (append
0640: 20 63 75 72 72 69 74 65 6d 6b 65 79 20 28 6c 69   curritemkey (li
0650: 73 74 20 28 6c 69 73 74 20 28 63 61 72 20 68 65  st (list (car he
0660: 64 29 20 69 74 65 6d 29 29 29 29 29 29 29 29 0a  d) item)))))))).
0670: 09 09 20 20 20 20 28 63 61 64 72 20 68 65 64 29  ..    (cadr hed)
0680: 29 0a 09 20 20 28 62 65 67 69 6e 0a 09 20 20 20  )..  (begin..   
0690: 20 28 66 6f 72 2d 65 61 63 68 20 28 6c 61 6d 62   (for-each (lamb
06a0: 64 61 20 28 69 74 65 6d 29 0a 09 09 09 28 73 65  da (item)....(se
06b0: 74 21 20 72 65 73 20 28 61 70 70 65 6e 64 20 72  t! res (append r
06c0: 65 73 20 28 70 72 6f 63 65 73 73 2d 69 74 65 6d  es (process-item
06d0: 6c 69 73 74 20 68 69 65 72 64 65 70 74 68 20 28  list hierdepth (
06e0: 61 70 70 65 6e 64 20 63 75 72 72 69 74 65 6d 6b  append curritemk
06f0: 65 79 20 28 6c 69 73 74 20 28 6c 69 73 74 20 28  ey (list (list (
0700: 63 61 72 20 68 65 64 29 20 69 74 65 6d 29 29 29  car hed) item)))
0710: 20 74 61 6c 29 29 29 29 0a 09 09 20 20 20 20 20   tal))))...     
0720: 20 28 63 61 64 72 20 68 65 64 29 29 0a 09 20 20   (cadr hed))..  
0730: 20 20 28 6c 6f 6f 70 20 28 63 61 72 20 74 61 6c    (loop (car tal
0740: 29 28 63 64 72 20 74 61 6c 29 29 29 29 29 0a 20  )(cdr tal))))). 
0750: 20 20 20 72 65 73 29 29 0a 0a 3b 3b 20 28 69 74     res))..;; (it
0760: 65 6d 2d 61 73 73 6f 63 2d 3e 69 74 65 6d 2d 6c  em-assoc->item-l
0770: 69 73 74 20 27 28 28 22 41 4e 49 4d 41 4c 22 20  ist '(("ANIMAL" 
0780: 22 45 6c 65 70 68 61 6e 74 20 4c 69 6f 6e 22 29  "Elephant Lion")
0790: 28 22 53 45 41 53 4f 4e 22 20 22 53 70 72 69 6e  ("SEASON" "Sprin
07a0: 67 20 46 61 6c 6c 22 29 29 29 0a 3b 3b 20 20 20  g Fall"))).;;   
07b0: 3d 3e 20 28 28 28 22 41 4e 49 4d 41 4c 22 20 22  => ((("ANIMAL" "
07c0: 45 6c 65 70 68 61 6e 74 22 29 20 28 22 53 45 41  Elephant") ("SEA
07d0: 53 4f 4e 22 20 22 53 70 72 69 6e 67 22 29 29 20  SON" "Spring")) 
07e0: 0a 3b 3b 20 20 20 20 20 20 20 28 28 22 41 4e 49  .;;       (("ANI
07f0: 4d 41 4c 22 20 22 45 6c 65 70 68 61 6e 74 22 29  MAL" "Elephant")
0800: 20 28 22 53 45 41 53 4f 4e 22 20 22 46 61 6c 6c   ("SEASON" "Fall
0810: 22 29 29 20 0a 3b 3b 20 20 20 20 20 20 20 28 28  ")) .;;       ((
0820: 22 41 4e 49 4d 41 4c 22 20 22 4c 69 6f 6e 22 29  "ANIMAL" "Lion")
0830: 20 20 20 20 20 28 22 53 45 41 53 4f 4e 22 20 22       ("SEASON" "
0840: 53 70 72 69 6e 67 22 29 29 0a 3b 3b 20 20 20 20  Spring")).;;    
0850: 20 20 20 28 28 22 41 4e 49 4d 41 4c 22 20 22 4c     (("ANIMAL" "L
0860: 69 6f 6e 22 29 20 20 20 20 20 28 22 53 45 41 53  ion")     ("SEAS
0870: 4f 4e 22 20 22 46 61 6c 6c 22 29 29 29 0a 28 64  ON" "Fall"))).(d
0880: 65 66 69 6e 65 20 28 69 74 65 6d 2d 61 73 73 6f  efine (item-asso
0890: 63 2d 3e 69 74 65 6d 2d 6c 69 73 74 20 69 74 65  c->item-list ite
08a0: 6d 73 64 61 74 29 0a 20 20 28 69 66 20 28 61 6e  msdat).  (if (an
08b0: 64 20 69 74 65 6d 73 64 61 74 20 28 6e 6f 74 20  d itemsdat (not 
08c0: 28 6e 75 6c 6c 3f 20 69 74 65 6d 73 64 61 74 29  (null? itemsdat)
08d0: 29 29 0a 20 20 20 20 20 20 28 6c 65 74 20 28 28  )).      (let ((
08e0: 69 74 65 6d 6c 73 74 20 28 66 69 6c 74 65 72 20  itemlst (filter 
08f0: 28 6c 61 6d 62 64 61 20 28 78 29 0a 09 09 09 20  (lambda (x).... 
0900: 20 20 20 20 20 20 28 6c 69 73 74 3f 20 78 29 29        (list? x))
0910: 0a 09 09 09 20 20 20 20 20 28 6d 61 70 20 28 6c  ....     (map (l
0920: 61 6d 62 64 61 20 28 78 29 0a 09 09 09 09 20 20  ambda (x).....  
0930: 20 20 28 64 65 62 75 67 3a 70 72 69 6e 74 20 36    (debug:print 6
0940: 20 22 69 74 65 6d 2d 61 73 73 6f 63 2d 3e 69 74   "item-assoc->it
0950: 65 6d 2d 6c 69 73 74 20 78 3a 20 22 20 78 29 0a  em-list x: " x).
0960: 09 09 09 09 20 20 20 20 28 69 66 20 28 3c 20 28  ....    (if (< (
0970: 6c 65 6e 67 74 68 20 78 29 20 32 29 0a 09 09 09  length x) 2)....
0980: 09 09 28 62 65 67 69 6e 0a 09 09 09 09 09 20 20  ..(begin......  
0990: 28 64 65 62 75 67 3a 70 72 69 6e 74 20 30 20 22  (debug:print 0 "
09a0: 45 52 52 4f 52 3a 20 6d 61 6c 66 6f 72 6d 65 64  ERROR: malformed
09b0: 20 69 74 65 6d 73 20 73 70 65 63 20 22 20 28 73   items spec " (s
09c0: 74 72 69 6e 67 2d 69 6e 74 65 72 73 70 65 72 73  tring-interspers
09d0: 65 20 78 20 22 20 22 29 29 0a 09 09 09 09 09 20  e x " "))...... 
09e0: 20 28 6c 69 73 74 20 28 63 61 72 20 78 29 27 28   (list (car x)'(
09f0: 29 29 29 0a 09 09 09 09 09 28 6c 65 74 20 28 28  )))......(let ((
0a00: 6e 61 6d 65 20 28 63 61 72 20 78 29 29 0a 09 09  name (car x))...
0a10: 09 09 09 20 20 20 20 20 20 28 69 74 65 6d 73 20  ...      (items 
0a20: 28 63 61 64 72 20 78 29 29 29 0a 09 09 09 09 09  (cadr x)))......
0a30: 20 20 28 6c 69 73 74 20 6e 61 6d 65 20 28 73 74    (list name (st
0a40: 72 69 6e 67 2d 73 70 6c 69 74 20 69 74 65 6d 73  ring-split items
0a50: 29 29 29 29 29 0a 09 09 09 09 20 20 69 74 65 6d  ))))).....  item
0a60: 73 64 61 74 29 29 29 29 0a 09 28 6c 65 74 20 28  sdat))))..(let (
0a70: 28 64 65 62 75 67 6c 65 76 65 6c 20 35 29 29 0a  (debuglevel 5)).
0a80: 09 20 20 28 64 65 62 75 67 3a 70 72 69 6e 74 20  .  (debug:print 
0a90: 35 20 22 69 74 65 6d 2d 61 73 73 6f 63 2d 3e 69  5 "item-assoc->i
0aa0: 74 65 6d 2d 6c 69 73 74 3a 20 69 74 65 6d 73 64  tem-list: itemsd
0ab0: 61 74 20 3d 3e 20 69 74 65 6d 6c 73 74 20 22 29  at => itemlst ")
0ac0: 0a 09 20 20 28 69 66 20 28 64 65 62 75 67 3a 64  ..  (if (debug:d
0ad0: 65 62 75 67 2d 6d 6f 64 65 20 35 29 0a 09 20 20  ebug-mode 5)..  
0ae0: 20 20 20 20 28 62 65 67 69 6e 0a 09 09 28 70 70      (begin...(pp
0af0: 20 69 74 65 6d 73 64 61 74 29 0a 09 09 28 70 72   itemsdat)...(pr
0b00: 69 6e 74 20 22 20 3d 3e 20 22 29 0a 09 09 28 70  int " => ")...(p
0b10: 70 20 69 74 65 6d 6c 73 74 29 29 29 29 0a 09 28  p itemlst))))..(
0b20: 69 66 20 28 3e 20 28 6c 65 6e 67 74 68 20 69 74  if (> (length it
0b30: 65 6d 6c 73 74 29 20 30 29 0a 09 20 20 20 20 28  emlst) 0)..    (
0b40: 70 72 6f 63 65 73 73 2d 69 74 65 6d 6c 69 73 74  process-itemlist
0b50: 20 23 66 20 27 28 29 20 69 74 65 6d 6c 73 74 29   #f '() itemlst)
0b60: 0a 09 20 20 20 20 27 28 29 29 29 0a 20 20 20 20  ..    '())).    
0b70: 20 20 27 28 29 29 29 20 3b 3b 20 72 65 74 75 72    '())) ;; retur
0b80: 6e 20 61 20 6c 69 73 74 20 63 6f 6e 73 69 73 74  n a list consist
0b90: 69 6e 67 20 6f 6e 20 61 20 73 69 6e 67 6c 65 20  ing on a single 
0ba0: 6e 75 6c 6c 20 6c 69 73 74 20 66 6f 72 20 6e 6f  null list for no
0bb0: 6e 2d 69 74 65 6d 20 72 75 6e 73 0a 20 20 20 20  n-item runs.    
0bc0: 20 20 20 20 20 20 20 20 3b 3b 20 4e 6f 70 65 2c          ;; Nope,
0bd0: 20 6e 6f 74 20 6e 6f 77 2c 20 72 65 74 75 72 6e   not now, return
0be0: 20 6e 75 6c 6c 20 61 73 20 6f 66 20 36 2f 36 2f   null as of 6/6/
0bf0: 32 30 31 31 0a 0a 3b 3b 20 28 69 74 65 6d 2d 74  2011..;; (item-t
0c00: 61 62 6c 65 2d 3e 69 74 65 6d 2d 6c 69 73 74 20  able->item-list 
0c10: 27 28 28 22 41 4e 49 4d 41 4c 22 20 22 45 6c 65  '(("ANIMAL" "Ele
0c20: 70 68 61 6e 74 20 4c 69 6f 6e 22 29 28 22 53 45  phant Lion")("SE
0c30: 41 53 4f 4e 22 20 22 53 70 72 69 6e 67 20 57 69  ASON" "Spring Wi
0c40: 6e 74 65 72 22 29 29 29 0a 3b 3b 20 20 20 3d 3e  nter"))).;;   =>
0c50: 20 28 28 28 22 41 4e 49 4d 41 4c 22 20 22 45 6c   ((("ANIMAL" "El
0c60: 65 70 68 61 6e 74 22 29 28 22 53 45 41 53 4f 4e  ephant")("SEASON
0c70: 22 20 22 53 70 72 69 6e 67 22 29 29 0a 3b 3b 20  " "Spring")).;; 
0c80: 20 20 20 20 20 20 28 28 22 41 4e 49 4d 41 4c 22        (("ANIMAL"
0c90: 20 22 4c 69 6f 6e 22 29 20 20 20 20 28 22 53 45   "Lion")    ("SE
0ca0: 41 53 4f 4e 22 20 22 57 69 6e 74 65 72 22 29 29  ASON" "Winter"))
0cb0: 29 0a 28 64 65 66 69 6e 65 20 28 69 74 65 6d 2d  ).(define (item-
0cc0: 74 61 62 6c 65 2d 3e 69 74 65 6d 2d 6c 69 73 74  table->item-list
0cd0: 20 69 74 65 6d 74 61 62 6c 65 29 0a 20 20 28 6c   itemtable).  (l
0ce0: 65 74 20 28 28 6e 65 77 6c 73 74 20 28 6d 61 70  et ((newlst (map
0cf0: 20 28 6c 61 6d 62 64 61 20 28 78 29 0a 09 09 20   (lambda (x)... 
0d00: 20 20 20 20 20 20 28 69 66 20 28 3e 20 28 6c 65        (if (> (le
0d10: 6e 67 74 68 20 78 29 20 31 29 0a 09 09 09 20 20  ngth x) 1)....  
0d20: 20 28 6c 69 73 74 20 28 63 61 72 20 78 29 0a 09   (list (car x)..
0d30: 09 09 09 20 28 73 74 72 69 6e 67 2d 73 70 6c 69  ... (string-spli
0d40: 74 20 28 63 61 64 72 20 78 29 29 29 0a 09 09 09  t (cadr x)))....
0d50: 20 20 20 28 6c 69 73 74 20 78 20 27 28 29 29 29     (list x '()))
0d60: 29 0a 09 09 20 20 20 20 20 69 74 65 6d 74 61 62  )...     itemtab
0d70: 6c 65 29 29 0a 09 28 72 65 73 20 20 20 20 20 27  le))..(res     '
0d80: 28 29 29 29 20 3b 3b 20 61 20 6c 69 73 74 20 6f  ())) ;; a list o
0d90: 66 20 69 74 65 6d 73 0a 20 20 20 20 28 6c 65 74  f items.    (let
0da0: 20 6c 6f 6f 70 20 28 28 69 6e 64 78 20 20 20 20   loop ((indx    
0db0: 30 29 0a 09 20 20 20 20 20 20 20 28 69 74 65 6d  0)..       (item
0dc0: 20 20 20 27 28 29 29 20 3b 3b 20 61 6e 20 69 74     '()) ;; an it
0dd0: 65 6d 20 77 69 6c 6c 20 62 65 20 28 28 4b 45 59  em will be ((KEY
0de0: 4e 41 4d 45 31 20 56 41 4c 31 29 28 4b 45 59 4e  NAME1 VAL1)(KEYN
0df0: 41 4d 45 32 20 56 41 4c 32 29 20 2e 2e 2e 29 0a  AME2 VAL2) ...).
0e00: 09 20 20 20 20 20 20 20 28 65 6c 66 6c 61 67 20  .       (elflag 
0e10: 20 23 66 29 29 0a 20 20 20 20 20 20 28 66 6f 72   #f)).      (for
0e20: 2d 65 61 63 68 20 28 6c 61 6d 62 64 61 20 28 72  -each (lambda (r
0e30: 6f 77 29 0a 09 09 20 20 28 6c 65 74 20 28 28 72  ow)...  (let ((r
0e40: 6f 77 6e 61 6d 65 20 28 63 61 72 20 72 6f 77 29  owname (car row)
0e50: 29 0a 09 09 09 28 72 6f 77 64 61 74 20 20 28 63  )....(rowdat  (c
0e60: 61 64 72 20 72 6f 77 29 29 29 0a 09 09 20 20 20  adr row)))...   
0e70: 20 28 73 65 74 21 20 69 74 65 6d 20 28 61 70 70   (set! item (app
0e80: 65 6e 64 20 69 74 65 6d 20 0a 09 09 09 09 20 20  end item .....  
0e90: 20 20 20 20 20 28 6c 69 73 74 20 0a 09 09 09 09       (list .....
0ea0: 09 28 69 66 20 28 3c 20 69 6e 64 78 20 28 6c 65  .(if (< indx (le
0eb0: 6e 67 74 68 20 72 6f 77 64 61 74 29 29 0a 09 09  ngth rowdat))...
0ec0: 09 09 09 20 20 20 20 28 6c 65 74 20 28 28 6e 65  ...    (let ((ne
0ed0: 77 20 28 6c 69 73 74 20 72 6f 77 6e 61 6d 65 20  w (list rowname 
0ee0: 28 6c 69 73 74 2d 72 65 66 20 72 6f 77 64 61 74  (list-ref rowdat
0ef0: 20 69 6e 64 78 29 29 29 29 0a 09 09 09 09 09 20   indx))))...... 
0f00: 20 20 20 20 20 3b 3b 20 28 64 65 62 75 67 3a 70       ;; (debug:p
0f10: 72 69 6e 74 20 30 20 22 4e 65 77 3a 20 22 20 6e  rint 0 "New: " n
0f20: 65 77 29 0a 09 09 09 09 09 20 20 20 20 20 20 28  ew)......      (
0f30: 73 65 74 21 20 65 6c 66 6c 61 67 20 23 74 29 0a  set! elflag #t).
0f40: 09 09 09 09 09 20 20 20 20 20 20 6e 65 77 0a 09  .....      new..
0f50: 09 09 09 09 20 20 20 20 20 20 29 20 3b 3b 20 69  ....      ) ;; i
0f60: 2e 65 2e 20 68 61 64 20 61 74 20 6c 65 61 73 74  .e. had at least
0f70: 20 6f 6e 20 6c 65 67 69 74 20 76 61 6c 75 65 20   on legit value 
0f80: 74 6f 20 75 73 65 0a 09 09 09 09 09 20 20 20 20  to use......    
0f90: 28 6c 69 73 74 20 72 6f 77 6e 61 6d 65 20 22 2d  (list rowname "-
0fa0: 22 29 29 29 29 29 29 29 0a 09 09 6e 65 77 6c 73  ")))))))...newls
0fb0: 74 29 0a 20 20 20 20 20 20 28 69 66 20 65 6c 66  t).      (if elf
0fc0: 6c 61 67 0a 09 20 20 28 62 65 67 69 6e 0a 09 20  lag..  (begin.. 
0fd0: 20 20 20 28 73 65 74 21 20 72 65 73 20 28 61 70     (set! res (ap
0fe0: 70 65 6e 64 20 72 65 73 20 28 6c 69 73 74 20 69  pend res (list i
0ff0: 74 65 6d 29 29 29 0a 09 20 20 20 20 28 6c 6f 6f  tem)))..    (loo
1000: 70 20 28 2b 20 69 6e 64 78 20 31 29 0a 09 09 20  p (+ indx 1)... 
1010: 20 27 28 29 0a 09 09 20 20 23 66 29 29 29 0a 20   '()...  #f))). 
1020: 20 20 20 20 20 72 65 73 29 29 29 0a 20 20 20 20       res))).    
1030: 20 20 20 20 20 20 20 20 3b 3b 20 4e 6f 70 65 2c          ;; Nope,
1040: 20 6e 6f 74 20 6e 6f 77 2c 20 72 65 74 75 72 6e   not now, return
1050: 20 6e 75 6c 6c 20 61 73 20 6f 66 20 36 2f 36 2f   null as of 6/6/
1060: 32 30 31 31 0a 09 09 0a 28 64 65 66 69 6e 65 20  2011....(define 
1070: 28 69 74 65 6d 73 3a 63 68 65 63 6b 2d 76 61 6c  (items:check-val
1080: 69 64 2d 69 74 65 6d 73 20 63 6c 61 73 73 20 69  id-items class i
1090: 74 65 6d 29 0a 20 20 28 6c 65 74 20 28 28 76 61  tem).  (let ((va
10a0: 6c 69 64 2d 76 61 6c 75 65 73 20 28 6c 65 74 20  lid-values (let 
10b0: 28 28 73 20 28 63 6f 6e 66 69 67 2d 6c 6f 6f 6b  ((s (config-look
10c0: 75 70 20 2a 63 6f 6e 66 69 67 64 61 74 2a 20 22  up *configdat* "
10d0: 76 61 6c 69 64 76 61 6c 75 65 73 22 20 63 6c 61  validvalues" cla
10e0: 73 73 29 29 29 0a 09 09 09 28 69 66 20 73 20 28  ss)))....(if s (
10f0: 73 74 72 69 6e 67 2d 73 70 6c 69 74 20 73 29 20  string-split s) 
1100: 23 66 29 29 29 29 0a 20 20 20 20 28 69 66 20 76  #f)))).    (if v
1110: 61 6c 69 64 2d 76 61 6c 75 65 73 0a 09 28 69 66  alid-values..(if
1120: 20 28 6d 65 6d 62 65 72 20 69 74 65 6d 20 76 61   (member item va
1130: 6c 69 64 2d 76 61 6c 75 65 73 29 0a 09 20 20 20  lid-values)..   
1140: 20 69 74 65 6d 20 23 66 29 0a 09 69 74 65 6d 29   item #f)..item)
1150: 29 29 0a 0a 28 64 65 66 69 6e 65 20 28 69 74 65  ))..(define (ite
1160: 6d 73 3a 67 65 74 2d 69 74 65 6d 73 2d 66 72 6f  ms:get-items-fro
1170: 6d 2d 63 6f 6e 66 69 67 20 74 63 6f 6e 66 69 67  m-config tconfig
1180: 29 0a 20 20 28 6c 65 74 2a 20 28 3b 3b 20 64 62  ).  (let* (;; db
1190: 20 69 73 20 61 6c 77 61 79 73 20 61 74 20 2a 74   is always at *t
11a0: 6f 70 70 61 74 68 2a 2f 64 62 2f 6d 65 67 61 74  oppath*/db/megat
11b0: 65 73 74 2e 64 62 0a 09 20 28 69 74 65 6d 73 20  est.db.. (items 
11c0: 20 20 20 20 20 20 28 68 61 73 68 2d 74 61 62 6c        (hash-tabl
11d0: 65 2d 72 65 66 2f 64 65 66 61 75 6c 74 20 74 63  e-ref/default tc
11e0: 6f 6e 66 69 67 20 22 69 74 65 6d 73 22 20 27 28  onfig "items" '(
11f0: 29 29 29 0a 09 20 28 69 74 65 6d 73 74 61 62 6c  ))).. (itemstabl
1200: 65 20 20 28 68 61 73 68 2d 74 61 62 6c 65 2d 72  e  (hash-table-r
1210: 65 66 2f 64 65 66 61 75 6c 74 20 74 63 6f 6e 66  ef/default tconf
1220: 69 67 20 22 69 74 65 6d 73 74 61 62 6c 65 22 20  ig "itemstable" 
1230: 27 28 29 29 29 29 0a 20 20 20 20 28 64 65 62 75  '()))).    (debu
1240: 67 3a 70 72 69 6e 74 20 35 20 22 69 74 65 6d 73  g:print 5 "items
1250: 3a 20 22 20 69 74 65 6d 73 20 22 20 69 74 65 6d  : " items " item
1260: 73 74 61 62 6c 65 3a 20 22 20 69 74 65 6d 73 74  stable: " itemst
1270: 61 62 6c 65 29 0a 20 20 20 20 28 73 65 74 21 20  able).    (set! 
1280: 69 74 65 6d 73 20 28 6d 61 70 20 28 6c 61 6d 62  items (map (lamb
1290: 64 61 20 28 69 74 65 6d 29 0a 09 09 20 20 20 20  da (item)...    
12a0: 20 20 20 28 69 66 20 28 70 72 6f 63 65 64 75 72     (if (procedur
12b0: 65 3f 20 28 63 61 64 72 20 69 74 65 6d 29 29 0a  e? (cadr item)).
12c0: 09 09 09 20 20 20 28 6c 69 73 74 20 28 63 61 72  ...   (list (car
12d0: 20 69 74 65 6d 29 28 28 63 61 64 72 20 69 74 65   item)((cadr ite
12e0: 6d 29 29 29 0a 09 09 09 20 20 20 69 74 65 6d 29  m)))....   item)
12f0: 29 0a 09 09 20 20 20 20 20 69 74 65 6d 73 29 29  )...     items))
1300: 0a 20 20 20 20 28 73 65 74 21 20 69 74 65 6d 73  .    (set! items
1310: 74 61 62 6c 65 20 28 6d 61 70 20 28 6c 61 6d 62  table (map (lamb
1320: 64 61 20 28 69 74 65 6d 29 0a 09 09 09 20 20 20  da (item)....   
1330: 20 28 69 66 20 28 70 72 6f 63 65 64 75 72 65 3f   (if (procedure?
1340: 20 28 63 61 64 72 20 69 74 65 6d 29 29 0a 09 09   (cadr item))...
1350: 09 09 28 6c 69 73 74 20 28 63 61 72 20 69 74 65  ..(list (car ite
1360: 6d 29 28 28 63 61 64 72 20 69 74 65 6d 29 29 29  m)((cadr item)))
1370: 0a 09 09 09 09 69 74 65 6d 29 29 0a 09 09 09 20  .....item)).... 
1380: 20 69 74 65 6d 73 74 61 62 6c 65 29 29 0a 20 20   itemstable)).  
1390: 20 20 28 69 66 20 28 6f 72 20 28 6e 6f 74 20 28    (if (or (not (
13a0: 6e 75 6c 6c 3f 20 69 74 65 6d 73 29 29 28 6e 6f  null? items))(no
13b0: 74 20 28 6e 75 6c 6c 3f 20 69 74 65 6d 73 74 61  t (null? itemsta
13c0: 62 6c 65 29 29 29 0a 09 28 61 70 70 65 6e 64 20  ble)))..(append 
13d0: 28 69 74 65 6d 2d 61 73 73 6f 63 2d 3e 69 74 65  (item-assoc->ite
13e0: 6d 2d 6c 69 73 74 20 69 74 65 6d 73 29 0a 09 09  m-list items)...
13f0: 28 69 74 65 6d 2d 74 61 62 6c 65 2d 3e 69 74 65  (item-table->ite
1400: 6d 2d 6c 69 73 74 20 69 74 65 6d 73 74 61 62 6c  m-list itemstabl
1410: 65 29 29 0a 09 27 28 28 29 29 29 29 29 0a 0a 3b  e))..'(()))))..;
1420: 3b 20 28 70 70 20 28 69 74 65 6d 2d 61 73 73 6f  ; (pp (item-asso
1430: 63 2d 3e 69 74 65 6d 2d 6c 69 73 74 20 69 74 65  c->item-list ite
1440: 6d 64 61 74 29 29 0a 0a 0a 09 0a                 mdat)).....