
(/VERSIONCHECK 2) 

(DEFUN |KAFILE;defstream| (|fn| |mode| $)
  (COND ((EQUAL |mode| "input") (RDEFINSTREAM (SPADCALL |fn| (QREFELT $ 11))))
        ((EQUAL |mode| "output")
         (RDEFOUTSTREAM (SPADCALL |fn| (QREFELT $ 11))))
        ('T
         (|error|
          (LIST "IO mode must be input or output"
                (SPADCALL |mode| (QREFELT $ 13))))))) 

(DEFUN |KAFILE;=;2$B;2| (|f1| |f2| $)
  (SPADCALL (QVELT |f1| 0) (QVELT |f2| 0) (QREFELT $ 15))) 

(DEFUN |KAFILE;coerce;$Of;3| (|f| $) (SPADCALL (QVELT |f| 0) (QREFELT $ 17))) 

(DEFUN |KAFILE;open;Fn$;4| (|fname| $)
  (SPADCALL |fname| "either" (QREFELT $ 19))) 

(DEFUN |KAFILE;open;FnS$;5| (|fname| |mode| $)
  (COND
   ((EQUAL |mode| "either")
    (COND
     ((SPADCALL |fname| (QREFELT $ 21))
      (SPADCALL |fname| "input" (QREFELT $ 19)))
     (#1='T
      (SPADCALL (SPADCALL |fname| "output" (QREFELT $ 19)) "input"
                (QREFELT $ 22)))))
   (#1# (VECTOR |fname| (|KAFILE;defstream| |fname| |mode| $) |mode|)))) 

(DEFUN |KAFILE;reopen!;$S$;6| (|f| |mode| $)
  (SEQ (SPADCALL |f| (QREFELT $ 23))
       (COND
        ((NULL (EQUAL |mode| "closed"))
         (SEQ (QSETVELT |f| 1 (|KAFILE;defstream| (QVELT |f| 0) |mode| $))
              (EXIT (QSETVELT |f| 2 |mode|)))))
       (EXIT |f|))) 

(DEFUN |KAFILE;close!;2$;7| (|f| $)
  (SEQ
   (COND
    ((NULL (EQUAL (QVELT |f| 2) "closed"))
     (SEQ (RSHUT (QVELT |f| 1)) (EXIT (QSETVELT |f| 2 "closed")))))
   (EXIT |f|))) 

(DEFUN |KAFILE;read!;$R;8| (|f| $)
  (PROG (|k| |ix| |ks|)
    (RETURN
     (SEQ
      (COND
       ((NULL (EQUAL (QVELT |f| 2) "input"))
        (|error|
         (LIST "File not in read state" (SPADCALL |f| (QREFELT $ 18)))))
       ('T
        (SEQ (LETT |ks| (RKEYIDS (QVELT |f| 0)) . #1=(|KAFILE;read!;$R;8|))
             (EXIT
              (COND
               ((NULL |ks|)
                (|error|
                 (LIST "Attempt to read empty file"
                       (SPADCALL |f| (QREFELT $ 18)))))
               ('T
                (SEQ (LETT |ix| (RANDOM (LENGTH |ks|)) . #1#)
                     (LETT |k| (PNAME (SPADCALL |ks| |ix| (QREFELT $ 27)))
                           . #1#)
                     (EXIT (CONS |k| (SPADRREAD |k| (QVELT |f| 1))))))))))))))) 

(DEFUN |KAFILE;write!;$2R;9| (|f| |pr| $)
  (SEQ
   (COND
    ((NULL (EQUAL (QVELT |f| 2) "output"))
     (|error| (LIST "File not in write state" (SPADCALL |f| (QREFELT $ 18)))))
    ('T (SEQ (SPADRWRITE (QCAR |pr|) (QCDR |pr|) (QVELT |f| 1)) (EXIT |pr|)))))) 

(PUT '|KAFILE;name;$Fn;10| '|SPADreplace| '(XLAM (|f|) (QVELT |f| 0))) 

(DEFUN |KAFILE;name;$Fn;10| (|f| $) (QVELT |f| 0)) 

(PUT '|KAFILE;iomode;$S;11| '|SPADreplace| '(XLAM (|f|) (QVELT |f| 2))) 

(DEFUN |KAFILE;iomode;$S;11| (|f| $) (QVELT |f| 2)) 

(DEFUN |KAFILE;empty;$;12| ($)
  (PROG (|fn|)
    (RETURN
     (SEQ
      (LETT |fn| (SPADCALL "" "kaf" "sdata" (QREFELT $ 33))
            |KAFILE;empty;$;12|)
      (EXIT (SPADCALL |fn| (QREFELT $ 20))))))) 

(DEFUN |KAFILE;keys;$L;13| (|f| $)
  (PROG (#1=#:G717 |n| #2=#:G716 |l|)
    (RETURN
     (SEQ (SPADCALL |f| (QREFELT $ 23))
          (LETT |l| (RKEYIDS (QVELT |f| 0)) . #3=(|KAFILE;keys;$L;13|))
          (EXIT
           (PROGN
            (LETT #2# NIL . #3#)
            (SEQ (LETT |n| NIL . #3#) (LETT #1# |l| . #3#) G190
                 (COND
                  ((OR (ATOM #1#) (PROGN (LETT |n| (CAR #1#) . #3#) NIL))
                   (GO G191)))
                 (SEQ (EXIT (LETT #2# (CONS (PNAME |n|) #2#) . #3#)))
                 (LETT #1# (CDR #1#) . #3#) (GO G190) G191
                 (EXIT (NREVERSE0 #2#))))))))) 

(DEFUN |KAFILE;#;$Nni;14| (|f| $) (LENGTH (SPADCALL |f| (QREFELT $ 36)))) 

(DEFUN |KAFILE;elt;$SEntry;15| (|f| |k| $)
  (SEQ (SPADCALL |f| "input" (QREFELT $ 22))
       (EXIT (SPADRREAD |k| (QVELT |f| 1))))) 

(DEFUN |KAFILE;setelt;$S2Entry;16| (|f| |k| |e| $)
  (SEQ (SPADCALL |f| "output" (QREFELT $ 22))
       (UNWIND-PROTECT (SPADCALL |f| (CONS |k| |e|) (QREFELT $ 30))
         (SPADCALL |f| (QREFELT $ 23)))
       (SPADCALL |f| (QREFELT $ 23)) (EXIT |e|))) 

(DEFUN |KAFILE;search;S$U;17| (|k| |f| $)
  (SEQ
   (COND
    ((NULL (SPADCALL |k| (SPADCALL |f| (QREFELT $ 36)) (QREFELT $ 41)))
     (CONS 1 "failed"))
    ('T
     (SEQ (SPADCALL |f| "input" (QREFELT $ 22))
          (EXIT (CONS 0 (SPADRREAD |k| (QVELT |f| 1))))))))) 

(DEFUN |KAFILE;remove!;S$U;18| (|k| |f| $)
  (PROG (|result|)
    (RETURN
     (SEQ
      (LETT |result| (SPADCALL |k| |f| (QREFELT $ 43)) |KAFILE;remove!;S$U;18|)
      (EXIT
       (COND ((QEQCAR |result| 1) |result|)
             ('T
              (SEQ (SPADCALL |f| (QREFELT $ 23))
                   (RDROPITEMS (NAMESTRING (QVELT |f| 0)) (LIST |k|))
                   (EXIT |result|))))))))) 

(DEFUN |KAFILE;pack!;2$;19| (|f| $)
  (SEQ (SPADCALL |f| (QREFELT $ 23)) (RPACKFILE (QVELT |f| 0)) (EXIT |f|))) 

(DEFUN |KeyedAccessFile| (#1=#:G774)
  (PROG ()
    (RETURN
     (PROG (#2=#:G775)
       (RETURN
        (COND
         ((LETT #2#
                (|lassocShiftWithFunction| (LIST (|devaluate| #1#))
                                           (HGET |$ConstructorCache|
                                                 '|KeyedAccessFile|)
                                           '|domainEqualList|)
                . #3=(|KeyedAccessFile|))
          (|CDRwithIncrement| #2#))
         ('T
          (UNWIND-PROTECT (PROG1 (|KeyedAccessFile;| #1#) (LETT #2# T . #3#))
            (COND
             ((NOT #2#) (HREM |$ConstructorCache| '|KeyedAccessFile|))))))))))) 

(DEFUN |KeyedAccessFile;| (|#1|)
  (PROG (#1=#:G773 |pv$| #2=#:G771 #3=#:G772 $ |dv$| DV$1)
    (RETURN
     (PROGN
      (LETT DV$1 (|devaluate| |#1|) . #4=(|KeyedAccessFile|))
      (LETT |dv$| (LIST '|KeyedAccessFile| DV$1) . #4#)
      (LETT $ (GETREFV 62) . #4#)
      (QSETREFV $ 0 |dv$|)
      (QSETREFV $ 3
                (LETT |pv$|
                      (|buildPredVector| 0 0
                                         (LIST
                                          (|HasCategory|
                                           (|Record| (|:| |key| (|String|))
                                                     (|:| |entry| |#1|))
                                           '(|ConvertibleTo| (|InputForm|)))
                                          (LETT #3#
                                                (|HasCategory| |#1|
                                                               '(|SetCategory|))
                                                . #4#)
                                          (AND #3#
                                               (|HasCategory| |#1|
                                                              (LIST '|Evalable|
                                                                    (|devaluate|
                                                                     |#1|))))
                                          (|HasCategory| (|String|)
                                                         '(|OrderedSet|))
                                          (LETT #2#
                                                (|HasCategory|
                                                 (|Record|
                                                  (|:| |key| (|String|))
                                                  (|:| |entry| |#1|))
                                                 '(|SetCategory|))
                                                . #4#)
                                          (AND #2#
                                               (|HasCategory|
                                                (|Record|
                                                 (|:| |key| (|String|))
                                                 (|:| |entry| |#1|))
                                                (LIST '|Evalable|
                                                      (LIST '|Record|
                                                            '(|:| |key|
                                                                  (|String|))
                                                            (LIST '|:| '|entry|
                                                                  (|devaluate|
                                                                   |#1|))))))))
                      . #4#))
      (|haddProp| |$ConstructorCache| '|KeyedAccessFile| (LIST DV$1)
                  (CONS 1 $))
      (|stuffDomainSlots| $)
      (QSETREFV $ 6 |#1|)
      (AND (|HasCategory| $ '(|shallowlyMutable|)) (|augmentPredVector| $ 64))
      (AND (LETT #1# (|HasCategory| $ '(|finiteAggregate|)) . #4#)
           (|augmentPredVector| $ 128))
      (AND #1# #3# (|augmentPredVector| $ 256))
      (AND #1# #2# (|augmentPredVector| $ 512))
      (QSETREFV $ 7
                (|Record| (|:| |car| (|SExpression|))
                          (|:| |cdr| (|SExpression|))))
      (QSETREFV $ 8
                (|Record| (|:| |fileName| (|FileName|))
                          (|:| |fileState| (|SExpression|))
                          (|:| |fileIOmode| (|String|))))
      $)))) 

(MAKEPROP '|KeyedAccessFile| '|infovec|
          (LIST
           '#(NIL NIL NIL NIL NIL NIL (|local| |#1|) '|Cons| '|Rep| (|String|)
              (|FileName|) (0 . |coerce|) (|OutputForm|) (5 . |coerce|)
              (|Boolean|) (10 . =) |KAFILE;=;2$B;2| (16 . |coerce|)
              |KAFILE;coerce;$Of;3| |KAFILE;open;FnS$;5| |KAFILE;open;Fn$;4|
              (21 . |exists?|) |KAFILE;reopen!;$S$;6| |KAFILE;close!;2$;7|
              (|Symbol|) (|Integer|) (|List| 24) (26 . |elt|)
              (|Record| (|:| |key| 9) (|:| |entry| 6)) |KAFILE;read!;$R;8|
              |KAFILE;write!;$2R;9| |KAFILE;name;$Fn;10| |KAFILE;iomode;$S;11|
              (32 . |new|) |KAFILE;empty;$;12| (|List| 9) |KAFILE;keys;$L;13|
              (|NonNegativeInteger|) |KAFILE;#;$Nni;14| |KAFILE;elt;$SEntry;15|
              |KAFILE;setelt;$S2Entry;16| (39 . |member?|)
              (|Union| 6 '"failed") |KAFILE;search;S$U;17|
              |KAFILE;remove!;S$U;18| |KAFILE;pack!;2$;19| (|List| 47)
              (|Equation| 28) (|List| 28) (|Mapping| 28 28 28) (|List| 6)
              (|List| 52) (|Equation| 6) (|InputForm|) (|Mapping| 14 28)
              (|Mapping| 14 6) (|Mapping| 28 28) (|Void|) (|Mapping| 6 6)
              (|Union| 28 '"failed") (|Mapping| 6 6 6) (|SingleInteger|))
           '#(~= 45 |write!| 51 |table| 57 |swap!| 66 |size?| 73 |setelt| 79
              |select!| 86 |select| 92 |search| 98 |sample| 104 |reopen!| 108
              |removeDuplicates| 114 |remove!| 119 |remove| 137 |reduce| 149
              |read!| 170 |qsetelt!| 175 |qelt| 182 |parts| 188 |pack!| 198
              |open| 203 |name| 214 |more?| 219 |minIndex| 225 |members| 230
              |member?| 240 |maxIndex| 252 |map!| 257 |map| 269 |less?| 288
              |latex| 294 |keys| 299 |key?| 304 |iomode| 310 |inspect| 315
              |insert!| 320 |indices| 326 |index?| 331 |hash| 337 |first| 342
              |find| 347 |fill!| 353 |extract!| 359 |every?| 364 |eval| 376
              |eq?| 428 |entry?| 434 |entries| 440 |empty?| 445 |empty| 450
              |elt| 454 |dictionary| 467 |count| 476 |copy| 500 |convert| 505
              |construct| 510 |coerce| 515 |close!| 520 |bag| 525 |any?| 530 =
              542 |#| 548)
           'NIL
           (CONS
            (|makeByteWordVec2| 6
                                '(0 0 0 0 0 0 0 0 0 0 0 0 0 6 3 0 0 0 0 0 0 6 1
                                  3))
            (CONS
             '#(|TableAggregate&| |KeyedDictionary&| |Dictionary&|
                |DictionaryOperations&| |IndexedAggregate&| |Collection&|
                |BagAggregate&| NIL |HomogeneousAggregate&|
                |HomogeneousAggregate&| |SetCategory&| |EltableAggregate&|
                |Aggregate&| |Evalable&| |Evalable&| |BasicType&| NIL NIL NIL
                NIL NIL |InnerEvalable&| NIL |InnerEvalable&|)
             (CONS
              '#((|TableAggregate| 9 6) (|KeyedDictionary| 9 6)
                 (|Dictionary| (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|DictionaryOperations|
                  (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|IndexedAggregate| 9 6)
                 (|Collection| (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|BagAggregate| (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|FileCategory| 10 (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|HomogeneousAggregate| 6)
                 (|HomogeneousAggregate|
                  (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|SetCategory|) (|EltableAggregate| 9 6) (|Aggregate|)
                 (|Evalable| (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|Evalable| 6) (|BasicType|) (|finiteAggregate|)
                 (|Eltable| 9 6) (|shallowlyMutable|) (|Type|)
                 (|CoercibleTo| 12)
                 (|InnerEvalable| (|Record| (|:| |key| 9) (|:| |entry| 6))
                                  (|Record| (|:| |key| 9) (|:| |entry| 6)))
                 (|ConvertibleTo| 53) (|InnerEvalable| 6 6))
              (|makeByteWordVec2| 61
                                  '(1 10 9 0 11 1 9 12 0 13 2 10 14 0 0 15 1 10
                                    12 0 17 1 10 14 0 21 2 26 24 0 25 27 3 10 0
                                    9 9 9 33 2 35 14 9 0 41 2 0 14 0 0 1 2 0 28
                                    0 28 30 0 0 0 1 1 0 0 48 1 3 7 57 0 9 9 1 2
                                    0 14 0 37 1 3 0 6 0 9 6 40 2 8 0 54 0 1 2 8
                                    0 54 0 1 2 0 42 9 0 43 0 0 0 1 2 0 0 0 9 22
                                    1 10 0 0 1 2 8 0 54 0 1 2 8 0 28 0 1 2 0 42
                                    9 0 44 2 10 0 28 0 1 2 8 0 54 0 1 4 10 28
                                    49 0 28 28 1 2 8 28 49 0 1 3 8 28 49 0 28 1
                                    1 0 28 0 29 3 7 6 0 9 6 1 2 0 6 0 9 1 1 8
                                    48 0 1 1 8 50 0 1 1 0 0 0 45 2 0 0 10 9 19
                                    1 0 0 10 20 1 0 10 0 31 2 0 14 0 37 1 1 4 9
                                    0 1 1 8 48 0 1 1 8 50 0 1 2 10 14 28 0 1 2
                                    9 14 6 0 1 1 4 9 0 1 2 7 0 56 0 1 2 7 0 58
                                    0 1 2 0 0 56 0 1 2 0 0 58 0 1 3 0 0 60 0 0
                                    1 2 0 14 0 37 1 1 0 9 0 1 1 0 35 0 36 2 0
                                    14 9 0 1 1 0 9 0 32 1 0 28 0 1 2 0 0 28 0 1
                                    1 0 35 0 1 2 0 14 9 0 1 1 0 61 0 1 1 4 6 0
                                    1 2 0 59 54 0 1 2 7 0 0 6 1 1 0 28 0 1 2 8
                                    14 54 0 1 2 8 14 55 0 1 2 6 0 0 46 1 3 6 0
                                    0 28 28 1 2 6 0 0 47 1 3 6 0 0 48 48 1 3 3
                                    0 0 50 50 1 3 3 0 0 6 6 1 2 3 0 0 51 1 2 3
                                    0 0 52 1 2 0 14 0 0 1 2 9 14 6 0 1 1 0 50 0
                                    1 1 0 14 0 1 0 0 0 34 3 0 6 0 9 6 1 2 0 6 0
                                    9 39 0 0 0 1 1 0 0 48 1 2 10 37 28 0 1 2 9
                                    37 6 0 1 2 8 37 54 0 1 2 8 37 55 0 1 1 0 0
                                    0 1 1 1 53 0 1 1 0 0 48 1 1 0 12 0 18 1 0 0
                                    0 23 1 0 0 48 1 2 8 14 54 0 1 2 8 14 55 0 1
                                    2 0 14 0 0 16 1 8 37 0 38)))))
           '|lookupComplete|)) 
