git.iko.soy/rowtype-yoga/purescm
on bytevector help sign in
Vendor SRFI 214 and SRFI 125 (#135)
commitf90c2ab7ed2d3b69ff32a28c9109739e61e040a5 authorJustin Garcia <purefunctor@gmail.com> dateWed 17 May 2023, 20:37 (3 years ago) parentcce5227
72 files changed+6203−23
README.md+27 src/PureScript/Backend/Chez/Convert.purs+1−1 src/PureScript/Backend/Chez/Runtime.purs+2−2 test-snapshots/src/snapshots-output/Snapshot.ArrayIndex.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Branch.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Comparison.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Constructor.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.ConstructorAccessor.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Effect.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.EffectRef.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Function.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Import.Impl.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Import.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Let.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Literals.Char.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Literals.Record.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Literals.String.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Literals.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.PrimUndefined.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.Prime.ss+1−1 test-snapshots/src/snapshots-output/Snapshot.UncurriedFunction.ss+1−1 test/Main.purs+5−2 test/Utils.purs+10 vendor/purs/runtime/srfi/:0.sls+11 vendor/purs/runtime/srfi/:0/cond-expand.guile.sls+9 vendor/purs/runtime/srfi/:0/cond-expand.sls+44 vendor/purs/runtime/srfi/:1.sls+34 vendor/purs/runtime/srfi/:1/lists.sls+1594 vendor/purs/runtime/srfi/:125.sls+27 vendor/purs/runtime/srfi/:125/hashtables.sls+378 vendor/purs/runtime/srfi/:126.sls+23 vendor/purs/runtime/srfi/:126/helpers/helpers.chezscheme.sls+111 vendor/purs/runtime/srfi/:126/helpers/helpers.sls+72 vendor/purs/runtime/srfi/:126/r6rs-hashtables.sls+354 vendor/purs/runtime/srfi/:128.sls+19 vendor/purs/runtime/srfi/:128/comparators.sls+468 vendor/purs/runtime/srfi/:133.sls+17 vendor/purs/runtime/srfi/:133/vectors.sls+885 vendor/purs/runtime/srfi/:133/vectors.sls3a132.sls+6 vendor/purs/runtime/srfi/:158.sls+25 vendor/purs/runtime/srfi/:158/generators-and-accumulators.sls+457 vendor/purs/runtime/srfi/:214.sls+35 vendor/purs/runtime/srfi/:214/impl.sls+546 vendor/purs/runtime/srfi/:214/parameters.sls+39 vendor/purs/runtime/srfi/:23.sls+11 vendor/purs/runtime/srfi/:23/error.sls+13 vendor/purs/runtime/srfi/:23/error/tricks.sls+43 vendor/purs/runtime/srfi/:26.sls+11 vendor/purs/runtime/srfi/:26/cut.sls+102 vendor/purs/runtime/srfi/:39.sls+11 vendor/purs/runtime/srfi/:39/parameters.chezscheme.sls+24 vendor/purs/runtime/srfi/:39/parameters.ikarus.sls+12 vendor/purs/runtime/srfi/:39/parameters.ironscheme.sls+14 vendor/purs/runtime/srfi/:39/parameters.mzscheme.sls+12 vendor/purs/runtime/srfi/:39/parameters.sls+35 vendor/purs/runtime/srfi/:39/parameters.ypsilon.sls+12 vendor/purs/runtime/srfi/:8.sls+11 vendor/purs/runtime/srfi/:8/receive.sls+18 vendor/purs/runtime/srfi/:99.sls+14 vendor/purs/runtime/srfi/:99/records.sls+35 vendor/purs/runtime/srfi/:99/records/helper.sls+30 vendor/purs/runtime/srfi/:99/records/inspection.larceny.sls+10 vendor/purs/runtime/srfi/:99/records/inspection.sls+60 vendor/purs/runtime/srfi/:99/records/procedural.larceny.sls+10 vendor/purs/runtime/srfi/:99/records/procedural.sls+108 vendor/purs/runtime/srfi/:99/records/syntactic.larceny.sls+9 vendor/purs/runtime/srfi/:99/records/syntactic.sls+208 vendor/purs/runtime/srfi/private/OS-id-features.sls+22 vendor/purs/runtime/srfi/private/include.chezscheme.sls+3 vendor/purs/runtime/srfi/private/platform-features.chezscheme.sls+34 vendor/purs/runtime/srfi/private/registry-names.sls+66 vendor/purs/runtime/srfi/private/registry.sls+48
README.md+27
@@ -1,5 +1,32 @@
11# purs-backend-chez
22
3+## Vendored Dependencies
4+
5+In order to represent `Array` and record types in `purescm`, the backend has a runtime dependency on implementations of SRFI 214 (Flexvectors) and SRFI 125 (Intermediate hash tables). This is due in part to how [vectors](https://cisco.github.io/ChezScheme/csug9.5/objects.html#./objects:h5) are more like "arrays" than "array lists" and [hashtables](https://cisco.github.io/ChezScheme/csug9.5/objects.html#./objects:h12)' canonical accessor, `hashtable-ref`, takes a `default` value rather than raising an exception.
6+
7+We vendor [chez-srfi](https://github.com/arcfide/chez-srfi) using the following steps:
8+
9+1. Clone `chez-srfi` at the project root.
10+
11+2. Navigate to `chez-srfi` and run `./install.chezscheme.sps ../vendor`. This should produce an `srfi` folder inside of `vendor`.
12+
13+3. Copy the desired SRFIs from `vendor/srfi` into `vendor/purs/runtime/srfi`. Make sure to also copy the SRFIs and other scheme files (e.g. the ones in the `private` folder) that they depend on. The [library-requirements](https://cisco.github.io/ChezScheme/csug9.5/libraries.html#./libraries:h7) function can aid in this process.
14+
15+4. Modify the copied scheme files such that the library names align with the folder structure. [`sd`](https://github.com/chmln/sd) makes this easy!
16+```sh
17+sd "\(srfi " "(purs runtime srfi " vendor/purs/**/*.sls
18+```
19+
20+5. To verify, simply invoke the Scheme REPL:
21+```scheme
22+$ scheme --libdirs ./vendor:
23+Chez Scheme Version 9.5.8
24+Copyright 1984-2022 Cisco Systems, Inc.
25+
26+> (import (purs runtime srfi :125))
27+>
28+```
29+
330## Snapshots
431
532To run snapshots, run `npm run test`.
src/PureScript/Backend/Chez/Convert.purs+1−1
@@ -79,7 +79,7 @@ codegenModule { name, bindings, imports, foreign: foreign_ } =
7979 libChezSchemePrefix
8080 , ImportSet $ ImportPrefix
8181 ( ImportLibrary
82− { identifiers: NEA.cons' "_Chez_Runtime" [ moduleLib ], version: Nothing }
82+ { identifiers: NEA.cons' "purs" [ "runtime", moduleLib ], version: Nothing }
8383 )
8484 runtimePrefix
8585 ] <> pursImports <> foreignImport
src/PureScript/Backend/Chez/Runtime.purs+2−2
@@ -10,7 +10,7 @@ import Data.Array.NonEmpty.Internal (NonEmptyArray(..))
1010import Data.Maybe (Maybe(..))
1111import Data.Traversable (sequence)
1212import Data.Tuple (Tuple(..))
13−import PureScript.Backend.Chez.Constants (libChezSchemePrefix, scmPrefixed)
13+import PureScript.Backend.Chez.Constants (libChezSchemePrefix, moduleLib, scmPrefixed)
1414import PureScript.Backend.Chez.Syntax (ChezDefinition(..), ChezExport(..), ChezExpr, ChezImport(..), ChezImportSet(..), ChezLibrary)
1515import PureScript.Backend.Chez.Syntax as S
1616
@@ -54,7 +54,7 @@ runtimeModule = do
5454 { "#!chezscheme": true
5555 , "#!r6rs": true
5656 , name:
57− { identifiers: NEA.cons' "_Chez_Runtime" [ "lib" ]
57+ { identifiers: NEA.cons' "purs" [ "runtime", moduleLib ]
5858 , version: []
5959 }
6060 , exports
test-snapshots/src/snapshots-output/Snapshot.ArrayIndex.ss+1−1
@@ -6,7 +6,7 @@
66 testAccessorGetIndex)
77 (import
88 (prefix (chezscheme) scm:)
9− (prefix (_Chez_Runtime lib) rt:))
9+ (prefix (purs runtime lib) rt:))
1010
1111 (scm:define testAccessorGetIndex
1212 (scm:lambda (v0)
test-snapshots/src/snapshots-output/Snapshot.Branch.ss+1−1
@@ -9,7 +9,7 @@
99 i)
1010 (import
1111 (prefix (chezscheme) scm:)
12− (prefix (_Chez_Runtime lib) rt:))
12+ (prefix (purs runtime lib) rt:))
1313
1414 (scm:define i
1515 (scm:lambda (v0)
test-snapshots/src/snapshots-output/Snapshot.Comparison.ss+1−1
@@ -10,7 +10,7 @@
1010 stringComparison)
1111 (import
1212 (prefix (chezscheme) scm:)
13− (prefix (_Chez_Runtime lib) rt:))
13+ (prefix (purs runtime lib) rt:))
1414
1515 (scm:define stringComparison
1616 (scm:lambda (x0)
test-snapshots/src/snapshots-output/Snapshot.Constructor.ss+1−1
@@ -28,7 +28,7 @@
2828 Stop2?)
2929 (import
3030 (prefix (chezscheme) scm:)
31− (prefix (_Chez_Runtime lib) rt:))
31+ (prefix (purs runtime lib) rt:))
3232
3333 (scm:define Nil
3434 (scm:quote Nil))
test-snapshots/src/snapshots-output/Snapshot.ConstructorAccessor.ss+1−1
@@ -33,7 +33,7 @@
3333 z)
3434 (import
3535 (prefix (chezscheme) scm:)
36− (prefix (_Chez_Runtime lib) rt:))
36+ (prefix (purs runtime lib) rt:))
3737
3838 (scm:define-record-type (First$ First First?)
3939 (scm:fields (scm:immutable value0 First-value0)))
test-snapshots/src/snapshots-output/Snapshot.Effect.ss+1−1
@@ -9,7 +9,7 @@
99 main)
1010 (import
1111 (prefix (chezscheme) scm:)
12− (prefix (_Chez_Runtime lib) rt:)
12+ (prefix (purs runtime lib) rt:)
1313 (prefix (Data.Unit lib) Data.Unit.))
1414
1515 (scm:define dontInlineMe
test-snapshots/src/snapshots-output/Snapshot.EffectRef.ss+1−1
@@ -10,7 +10,7 @@
1010 positionZero)
1111 (import
1212 (prefix (chezscheme) scm:)
13− (prefix (_Chez_Runtime lib) rt:)
13+ (prefix (purs runtime lib) rt:)
1414 (prefix (Test.Assert lib) Test.Assert.))
1515
1616 (scm:define positionZero
test-snapshots/src/snapshots-output/Snapshot.Function.ss+1−1
@@ -7,7 +7,7 @@
77 g)
88 (import
99 (prefix (chezscheme) scm:)
10− (prefix (_Chez_Runtime lib) rt:))
10+ (prefix (purs runtime lib) rt:))
1111
1212 (scm:define f
1313 (scm:lambda (x0)
test-snapshots/src/snapshots-output/Snapshot.Import.Impl.ss+1−1
@@ -7,7 +7,7 @@
77 fortyTwo)
88 (import
99 (prefix (chezscheme) scm:)
10− (prefix (_Chez_Runtime lib) rt:)
10+ (prefix (purs runtime lib) rt:)
1111 (Snapshot.Import.Impl foreign))
1212
1313 (scm:define fortyTwo
test-snapshots/src/snapshots-output/Snapshot.Import.ss+1−1
@@ -6,7 +6,7 @@
66 fortyThree)
77 (import
88 (prefix (chezscheme) scm:)
9− (prefix (_Chez_Runtime lib) rt:)
9+ (prefix (purs runtime lib) rt:)
1010 (prefix (Snapshot.Import.Impl lib) Snapshot.Import.Impl.))
1111
1212 (scm:define fortyThree
test-snapshots/src/snapshots-output/Snapshot.Let.ss+1−1
@@ -9,7 +9,7 @@
99 letRecursive)
1010 (import
1111 (prefix (chezscheme) scm:)
12− (prefix (_Chez_Runtime lib) rt:))
12+ (prefix (purs runtime lib) rt:))
1313
1414 (scm:define letRecursive
1515 (scm:lambda (x0)
test-snapshots/src/snapshots-output/Snapshot.Literals.Char.ss+1−1
@@ -27,7 +27,7 @@
2727 vtab)
2828 (import
2929 (prefix (chezscheme) scm:)
30− (prefix (_Chez_Runtime lib) rt:))
30+ (prefix (purs runtime lib) rt:))
3131
3232 (scm:define vtab
3333 #\vtab)
test-snapshots/src/snapshots-output/Snapshot.Literals.Record.ss+1−1
@@ -6,7 +6,7 @@
66 recordAccess)
77 (import
88 (prefix (chezscheme) scm:)
9− (prefix (_Chez_Runtime lib) rt:))
9+ (prefix (purs runtime lib) rt:))
1010
1111 (scm:define recordAccess
1212 (scm:lambda (v0)
test-snapshots/src/snapshots-output/Snapshot.Literals.String.ss+1−1
@@ -25,7 +25,7 @@
2525 unicode7)
2626 (import
2727 (prefix (chezscheme) scm:)
28− (prefix (_Chez_Runtime lib) rt:))
28+ (prefix (purs runtime lib) rt:))
2929
3030 (scm:define unicode7
3131 "Foo \b\b\b\b Bar")
test-snapshots/src/snapshots-output/Snapshot.Literals.ss+1−1
@@ -15,7 +15,7 @@
1515 string)
1616 (import
1717 (prefix (chezscheme) scm:)
18− (prefix (_Chez_Runtime lib) rt:))
18+ (prefix (purs runtime lib) rt:))
1919
2020 (scm:define string
2121 "string")
test-snapshots/src/snapshots-output/Snapshot.PrimUndefined.ss+1−1
@@ -7,7 +7,7 @@
77 testCase)
88 (import
99 (prefix (chezscheme) scm:)
10− (prefix (_Chez_Runtime lib) rt:)
10+ (prefix (purs runtime lib) rt:)
1111 (prefix (Data.Ring lib) Data.Ring.)
1212 (prefix (Test.Assert lib) Test.Assert.))
1313
test-snapshots/src/snapshots-output/Snapshot.Prime.ss+1−1
@@ -37,7 +37,7 @@
3737 useNormal)
3838 (import
3939 (prefix (chezscheme) scm:)
40− (prefix (_Chez_Runtime lib) rt:))
40+ (prefix (purs runtime lib) rt:))
4141
4242 (scm:define NCtor
4343 (scm:lambda (x0)
test-snapshots/src/snapshots-output/Snapshot.UncurriedFunction.ss+1−1
@@ -14,7 +14,7 @@
1414 test4b)
1515 (import
1616 (prefix (chezscheme) scm:)
17− (prefix (_Chez_Runtime lib) rt:)
17+ (prefix (purs runtime lib) rt:)
1818 (prefix (Data.Function.Uncurried lib) Data.Function.Uncurried.)
1919 (prefix (Effect.Console lib) Effect.Console.)
2020 (prefix (Test.Assert lib) Test.Assert.))
test/Main.purs+5−2
@@ -51,7 +51,7 @@ import PureScript.Backend.Optimizer.CoreFn (Comment(..), Module(..), ModuleName(
5151import PureScript.Backend.Optimizer.Directives (parseDirectiveFile)
5252import PureScript.Backend.Optimizer.Directives.Defaults (defaultDirectives)
5353import PureScript.Backend.Optimizer.Semantics.Foreign (coreForeignSemantics)
54−import Test.Utils (bufferToUTF8, canRunMain, copyFile, coreFnModulesFromOutput, execWithStdin, loadModuleMain, mkdirp, spawnFromParent)
54+import Test.Utils (bufferToUTF8, canRunMain, copyFile, coreFnModulesFromOutput, cpr, execWithStdin, loadModuleMain, mkdirp, spawnFromParent)
5555
5656type TestArgs =
5757 { accept :: Boolean
@@ -84,6 +84,8 @@ main = do
8484
8585runSnapshotTests :: TestArgs -> Aff Unit
8686runSnapshotTests { accept, filter } = do
87+ currentDirectory <- liftEffect Process.cwd
88+ let vendorDirectory = Path.concat [ currentDirectory, "vendor", "purs" ]
8789 liftEffect $ Process.chdir $ Path.concat [ "test-snapshots" ]
8890 spawnFromParent "spago" [ "build", "--purs-args", "-g corefn" ]
8991 snapshotDir <- liftEffect Process.cwd
@@ -96,11 +98,12 @@ runSnapshotTests { accept, filter } = do
9698 mkdirp snapshotsOut
9799 mkdirp testOut
98100 -- RUNTIME
99− let runtimePath = Path.concat [ testOut, "_Chez_Runtime" ]
101+ let runtimePath = Path.concat [ testOut, "purs", "runtime" ]
100102 mkdirp runtimePath
101103 let runtimeFilePath = Path.concat [ runtimePath, moduleLib <> schemeExt ]
102104 let runtimeContents = Dodo.print plainText Dodo.twoSpaces $ P.printLibrary $ runtimeModule
103105 FS.writeTextFile UTF8 runtimeFilePath runtimeContents
106+ cpr vendorDirectory testOut
104107 coreFnModulesFromOutput "output" filter >>= case _ of
105108 Left errors -> do
106109 for_ errors \(Tuple filePath err) -> do
test/Utils.purs+10
@@ -28,6 +28,7 @@ import Data.Set.NonEmpty as NonEmptySet
2828import Data.Tuple (Tuple(..))
2929import Effect.Aff (Aff, effectCanceler, error, makeAff, throwError)
3030import Effect.Class (liftEffect)
31+import Effect.Class.Console as Console
3132import Node.Buffer (Buffer, freeze)
3233import Node.Buffer.Immutable as ImmutableBuffer
3334import Node.ChildProcess (ExecResult, Exit(..), defaultExecOptions, defaultSpawnOptions, inherit)
@@ -75,6 +76,15 @@ bufferToUTF8 = liftEffect <<< map (ImmutableBuffer.toString UTF8) <<< freeze
7576mkdirp :: FilePath -> Aff Unit
7677mkdirp path = FS.mkdir' path { recursive: true, mode: mkPerms Perms.all Perms.all Perms.all }
7778
79+cpr :: FilePath -> FilePath -> Aff Unit
80+cpr from to = do
81+ spawned <- execa "cp" [ "-r", from, to ] identity
82+ spawned.result >>= case _ of
83+ Left e ->
84+ Console.error e.message
85+ Right _ ->
86+ pure unit
87+
7888loadModuleMain
7989 :: { libdir :: FilePath
8090 , scheme :: String
vendor/purs/runtime/srfi/:0.slsnew file+11
@@ -0,0 +1,11 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a0.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :0)
10+ (export cond-expand)
11+ (import (purs runtime srfi :0 cond-expand)))
vendor/purs/runtime/srfi/:0/cond-expand.guile.slsnew file+9
@@ -0,0 +1,9 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a0/cond-expand.guile.sls
7+(library (srfi srfi-0)
8+ (export cond-expand)
9+ (import (only (guile) cond-expand)))
vendor/purs/runtime/srfi/:0/cond-expand.slsnew file+44
@@ -0,0 +1,44 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a0/cond-expand.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :0 cond-expand)
11+ (export cond-expand)
12+ (import
13+ (rnrs)
14+ (for (only (purs runtime srfi private registry) expand-time-features)
15+ expand))
16+ (define-syntax cond-expand
17+ (lambda (stx)
18+ (syntax-case stx (and or not else)
19+ [(_) (syntax-violation #f "unfulfilled cond-expand" stx)]
20+ [(_ (else body ...)) #'(begin body ...)]
21+ [(_ ((and) body ...) more-clauses ...) #'(begin body ...)]
22+ [(_ ((and req1 req2 ...) body ...) more-clauses ...)
23+ #'(cond-expand
24+ (req1
25+ (cond-expand ((and req2 ...) body ...) more-clauses ...))
26+ more-clauses
27+ ...)]
28+ [(_ ((or) body ...) more-clauses ...)
29+ #'(cond-expand more-clauses ...)]
30+ [(_ ((or req1 req2 ...) body ...) more-clauses ...)
31+ #'(cond-expand
32+ (req1 (begin body ...))
33+ (else
34+ (cond-expand ((or req2 ...) body ...) more-clauses ...)))]
35+ [(_ ((not req) body ...) more-clauses ...)
36+ #'(cond-expand
37+ (req (cond-expand more-clauses ...))
38+ (else body ...))]
39+ [(_ (feature-id body ...) more-clauses ...)
40+ (if (member
41+ (syntax->datum #'feature-id)
42+ expand-time-features)
43+ #'(begin body ...)
44+ #'(cond-expand more-clauses ...))]))))
vendor/purs/runtime/srfi/:1.slsnew file+34
@@ -0,0 +1,34 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a1.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :1)
10+ (export alist-cons alist-copy alist-delete alist-delete! any
11+ append append! append-map append-map! append-reverse
12+ append-reverse! assoc assq assv break break! caaaar caaadr
13+ caaar caadar caaddr caadr caar cadaar cadadr cadar caddar
14+ cadddr caddr cadr car car+cdr cdaaar cdaadr cdaar cdadar
15+ cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr
16+ cddr cdr circular-list circular-list? concatenate
17+ concatenate! cons cons* count delete delete!
18+ delete-duplicates delete-duplicates! dotted-list? drop
19+ drop-right drop-right! drop-while eighth every fifth filter
20+ filter! filter-map find find-tail first fold fold-right
21+ for-each fourth iota last last-pair length length+ list
22+ list-copy list-index list-ref list-tabulate list=
23+ lset-adjoin lset-diff+intersection lset-diff+intersection!
24+ lset-difference lset-difference! lset-intersection
25+ lset-intersection! lset-union lset-union! lset-xor lset-xor!
26+ lset<= lset= make-list map map! map-in-order member memq
27+ memv ninth not-pair? null-list? null? pair-fold
28+ pair-fold-right pair-for-each pair? partition partition!
29+ proper-list? reduce reduce-right remove remove! reverse
30+ reverse! second set-car! set-cdr! seventh sixth span span!
31+ split-at split-at! take take! take-right take-while
32+ take-while! tenth third unfold unfold-right unzip1 unzip2
33+ unzip3 unzip4 unzip5 xcons zip)
34+ (import (purs runtime srfi :1 lists)))
vendor/purs/runtime/srfi/:1/lists.slsnew file+1594
@@ -0,0 +1,1594 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a1/lists.sls
7+#!r6rs
8+;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+;;;;;; File header: %3a1/srfi-1-reference.scm
11+;;; SRFI-1 list-processing library -*- Scheme -*-
12+;;; Reference implementation
13+;;;
14+;;; Copyright (c) 1998, 1999 by Olin Shivers. You may do as you please with
15+;;; this code as long as you do not remove this copyright notice or
16+;;; hold me liable for its use. Please send bug reports to shivers@ai.mit.edu.
17+;;; -Olin
18+(library (purs runtime srfi :1 lists)
19+ (export xcons make-list list-tabulate list-copy proper-list?
20+ circular-list? dotted-list? not-pair? null-list? list=
21+ circular-list length+ iota first second third fourth fifth
22+ sixth seventh eighth ninth tenth car+cdr take drop
23+ take-right drop-right take! drop-right! split-at split-at!
24+ last last-pair zip unzip1 unzip2 unzip3 unzip4 unzip5 count
25+ append! append-reverse append-reverse! concatenate
26+ concatenate! unfold fold pair-fold reduce unfold-right
27+ pair-fold-right reduce-right append-map append-map! map!
28+ pair-for-each filter-map map-in-order filter! partition!
29+ remove! find-tail any every list-index take-while drop-while
30+ take-while! span break span! break! delete delete!
31+ alist-cons alist-copy delete-duplicates delete-duplicates!
32+ alist-delete alist-delete! reverse! lset<= lset= lset-adjoin
33+ lset-union lset-intersection lset-difference lset-xor
34+ lset-diff+intersection lset-union! lset-intersection!
35+ lset-difference! lset-xor! lset-diff+intersection! append
36+ assq assv caaaar caaadr caaar caadar caaddr caadr caar
37+ cadaar cadadr cadar caddar cadddr caddr cadr car cdaaar
38+ cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar
39+ cdddar cddddr cdddr cddr cdr cons cons* length list list-ref
40+ memq memv null? pair? reverse set-car! set-cdr! assoc filter
41+ find fold-right for-each map member partition remove)
42+ (import
43+ (rename
44+ (except (rnrs) find filter fold-right map partition remove)
45+ (assoc r6rs:assoc)
46+ (for-each r6rs:for-each)
47+ (member r6rs:member))
48+ (rnrs mutable-pairs) (purs runtime srfi :8 receive)
49+ (purs runtime srfi :23 error tricks) (for (purs runtime srfi private vanish) expand)
50+ (purs runtime srfi private check-arg) (purs runtime srfi private include))
51+ (let-syntax ([define (vanish-define define (cons*))])
52+ (SRFI-23-error->R6RS
53+ "(library (purs runtime srfi :1 lists))"
54+ (begin
55+ (define (xcons d a) (cons a d))
56+ (define make-list
57+ (case-lambda
58+ [(len) (make-list len #f)]
59+ [(len elt)
60+ (check-arg index? len make-list)
61+ (do ([i len (fx- i 1)] [ans '() (cons elt ans)])
62+ ((fx<=? i 0) ans))]))
63+ (define (list-tabulate len proc)
64+ (check-arg index? len list-tabulate)
65+ (check-arg procedure? proc list-tabulate)
66+ (do ([i (fx- len 1) (fx- i 1)]
67+ [ans '() (cons (proc i) ans)])
68+ ((fx<? i 0) ans)))
69+ (define cons*
70+ (case-lambda
71+ [(first) first]
72+ [(first second) (cons first second)]
73+ [(first second third . rest)
74+ (cons
75+ first
76+ (cons
77+ second
78+ (let recur ([x third] [rest rest])
79+ (if (pair? rest)
80+ (cons x (recur (car rest) (cdr rest)))
81+ x))))]))
82+ (define (list-copy lis)
83+ (let recur ([lis lis])
84+ (if (pair? lis) (cons (car lis) (recur (cdr lis))) lis)))
85+ (define iota
86+ (case-lambda
87+ [(count) (iota count 0 1)]
88+ [(count start) (iota count start 1)]
89+ [(count start step)
90+ (check-arg index? count iota)
91+ (check-arg number? start iota)
92+ (check-arg number? step iota)
93+ (let loop ([cur start] [n 0])
94+ (if (fx=? n count)
95+ '()
96+ (cons cur (loop (fx+ cur step) (fx+ 1 n)))))]))
97+ (define (circular-list val1 . vals)
98+ (let ([ans (cons val1 vals)])
99+ (set-cdr! (last-pair ans) ans)
100+ ans))
101+ (define (proper-list? x)
102+ (let lp ([x x] [lag x])
103+ (if (pair? x)
104+ (let ([x (cdr x)])
105+ (if (pair? x)
106+ (let ([x (cdr x)] [lag (cdr lag)])
107+ (and (not (eq? x lag)) (lp x lag)))
108+ (null? x)))
109+ (null? x))))
110+ (define (dotted-list? x)
111+ (let lp ([x x] [lag x])
112+ (if (pair? x)
113+ (let ([x (cdr x)])
114+ (if (pair? x)
115+ (let ([x (cdr x)] [lag (cdr lag)])
116+ (and (not (eq? x lag)) (lp x lag)))
117+ (not (null? x))))
118+ (not (null? x)))))
119+ (define (circular-list? x)
120+ (let lp ([x x] [lag x])
121+ (and (pair? x)
122+ (let ([x (cdr x)])
123+ (and (pair? x)
124+ (let ([x (cdr x)] [lag (cdr lag)])
125+ (or (eq? x lag) (lp x lag))))))))
126+ (define (not-pair? x) (not (pair? x)))
127+ (define (null-list? l)
128+ (cond
129+ [(pair? l) #f]
130+ [(null? l) #t]
131+ [else (error "null-list?: argument out of domain" l)]))
132+ (define list=
133+ (case-lambda
134+ [(elt=) #t]
135+ [(elt= list-a) #t]
136+ [(elt= list-a list-b)
137+ (or (eq? list-a list-b)
138+ (let loop ([list-a list-a] [list-b list-b])
139+ (if (null-list? list-a)
140+ (null-list? list-b)
141+ (and (not (null-list? list-b))
142+ (elt= (car list-a) (car list-b))
143+ (loop (cdr list-a) (cdr list-b))))))]
144+ [(elt= list-a list-b list-c . lists)
145+ (and (list= elt= list-a list-b)
146+ (list= elt= list-b list-c)
147+ (or (null? lists)
148+ (let loop ([list-a list-c] [lists lists])
149+ (let ([list-b (car lists)] [others (cdr lists)])
150+ (and (list= elt= list-a list-b)
151+ (or (null? others)
152+ (loop list-b others)))))))]))
153+ (define (length+ x)
154+ (let loop ([x x] [len 0])
155+ (if (null? x)
156+ len
157+ (if (fx>? len 20)
158+ (let lp ([x (cdr x)] [lag x] [len (fx+ len 1)])
159+ (if (pair? x)
160+ (let ([x (cdr x)] [len (fx+ len 1)])
161+ (if (pair? x)
162+ (let ([x (cdr x)]
163+ [lag (cdr lag)]
164+ [len (fx+ len 1)])
165+ (and (not (eq? x lag)) (lp x lag len)))
166+ len))
167+ len))
168+ (loop (cdr x) (fx+ len 1))))))
169+ (define (zip list1 . more-lists)
170+ (apply map list list1 more-lists))
171+ (define first car)
172+ (define second cadr)
173+ (define third caddr)
174+ (define fourth cadddr)
175+ (define (fifth x) (car (cddddr x)))
176+ (define (sixth x) (cadr (cddddr x)))
177+ (define (seventh x) (caddr (cddddr x)))
178+ (define (eighth x) (cadddr (cddddr x)))
179+ (define (ninth x) (car (cddddr (cddddr x))))
180+ (define (tenth x) (cadr (cddddr (cddddr x))))
181+ (define (car+cdr pair) (values (car pair) (cdr pair)))
182+ (define (take lis k)
183+ (check-arg fixnum? k take)
184+ (let recur ([lis lis] [k k])
185+ (if (zero? k)
186+ '()
187+ (cons (car lis) (recur (cdr lis) (- k 1))))))
188+ (define (drop lis k)
189+ (check-arg fixnum? k drop)
190+ (let iter ([lis lis] [k k])
191+ (if (zero? k) lis (iter (cdr lis) (- k 1)))))
192+ (define (take! lis k)
193+ (check-arg fixnum? k take!)
194+ (if (zero? k)
195+ '()
196+ (begin (set-cdr! (drop lis (- k 1)) '()) lis)))
197+ (define (take-right lis k)
198+ (check-arg fixnum? k take-right)
199+ (let lp ([lag lis] [lead (drop lis k)])
200+ (if (pair? lead) (lp (cdr lag) (cdr lead)) lag)))
201+ (define (drop-right lis k)
202+ (check-arg fixnum? k drop-right)
203+ (let recur ([lag lis] [lead (drop lis k)])
204+ (if (pair? lead)
205+ (cons (car lag) (recur (cdr lag) (cdr lead)))
206+ '())))
207+ (define (drop-right! lis k)
208+ (check-arg fixnum? k drop-right!)
209+ (let ([lead (drop lis k)])
210+ (if (pair? lead)
211+ (let lp ([lag lis] [lead (cdr lead)])
212+ (if (pair? lead)
213+ (lp (cdr lag) (cdr lead))
214+ (begin (set-cdr! lag '()) lis)))
215+ '())))
216+ (define (split-at x k)
217+ (check-arg fixnum? k split-at)
218+ (let recur ([lis x] [k k])
219+ (if (zero? k)
220+ (values '() lis)
221+ (receive
222+ (prefix suffix)
223+ (recur (cdr lis) (- k 1))
224+ (values (cons (car lis) prefix) suffix)))))
225+ (define (split-at! x k)
226+ (check-arg fixnum? k split-at!)
227+ (if (zero? k)
228+ (values '() x)
229+ (let* ([prev (drop x (- k 1))] [suffix (cdr prev)])
230+ (set-cdr! prev '())
231+ (values x suffix))))
232+ (define (last lis) (car (last-pair lis)))
233+ (define (last-pair lis)
234+ (check-arg pair? lis last-pair)
235+ (let lp ([lis lis])
236+ (let ([tail (cdr lis)]) (if (pair? tail) (lp tail) lis))))
237+ (define (unzip1 lis) (map car lis))
238+ (define (unzip2 lis)
239+ (let recur ([lis lis])
240+ (if (null-list? lis)
241+ (values lis lis)
242+ (let ([elt (car lis)])
243+ (receive
244+ (a b)
245+ (recur (cdr lis))
246+ (values (cons (car elt) a) (cons (cadr elt) b)))))))
247+ (define (unzip3 lis)
248+ (let recur ([lis lis])
249+ (if (null-list? lis)
250+ (values lis lis lis)
251+ (let ([elt (car lis)])
252+ (receive
253+ (a b c)
254+ (recur (cdr lis))
255+ (values
256+ (cons (car elt) a)
257+ (cons (cadr elt) b)
258+ (cons (caddr elt) c)))))))
259+ (define (unzip4 lis)
260+ (let recur ([lis lis])
261+ (if (null-list? lis)
262+ (values lis lis lis lis)
263+ (let ([elt (car lis)])
264+ (receive
265+ (a b c d)
266+ (recur (cdr lis))
267+ (values
268+ (cons (car elt) a)
269+ (cons (cadr elt) b)
270+ (cons (caddr elt) c)
271+ (cons (cadddr elt) d)))))))
272+ (define (unzip5 lis)
273+ (let recur ([lis lis])
274+ (if (null-list? lis)
275+ (values lis lis lis lis lis)
276+ (let ([elt (car lis)])
277+ (receive
278+ (a b c d e)
279+ (recur (cdr lis))
280+ (values (cons (car elt) a) (cons (cadr elt) b)
281+ (cons (caddr elt) c) (cons (cadddr elt) d)
282+ (cons (car (cddddr elt)) e)))))))
283+ (define append!
284+ (case-lambda
285+ [() '()]
286+ [(lis1) lis1]
287+ [(lis1 lis2)
288+ (cond
289+ [(null? lis2) lis1]
290+ [(null? lis1) lis2]
291+ [else (set-cdr! (last-pair lis1) lis2) lis1])]
292+ [(lis1 lis2 lis3 . lists)
293+ (let ([append-2! (lambda (lis1 lis2)
294+ (set-cdr! (last-pair lis1) lis2)
295+ lis1)]
296+ [lists (delete '() lists)])
297+ (if (null? lists)
298+ (if (null? lis3)
299+ (append! lis1 lis2)
300+ (let* ([lis (if (null? lis2)
301+ lis3
302+ (append-2! lis2 lis3))]
303+ [lis (if (null? lis1)
304+ lis
305+ (append-2! lis1 lis))])
306+ lis))
307+ (let* ([lis (let loop ([lis (car lists)]
308+ [lists (cdr lists)])
309+ (if (null? lists)
310+ lis
311+ (append-2!
312+ lis
313+ (loop (car lists) (cdr lists)))))]
314+ [lis (if (null? lis3) lis (append-2! lis3 lis))]
315+ [lis (if (null? lis2) lis (append-2! lis2 lis))]
316+ [lis (if (null? lis1) lis (append-2! lis1 lis))])
317+ lis)))]))
318+ (define (append-reverse rev-head tail)
319+ (let lp ([rev-head rev-head] [tail tail])
320+ (if (null-list? rev-head)
321+ tail
322+ (lp (cdr rev-head) (cons (car rev-head) tail)))))
323+ (define (append-reverse! rev-head tail)
324+ (let lp ([rev-head rev-head] [tail tail])
325+ (if (null-list? rev-head)
326+ tail
327+ (let ([next-rev (cdr rev-head)])
328+ (set-cdr! rev-head tail)
329+ (lp next-rev rev-head)))))
330+ (define (concatenate lists) (reduce-right append '() lists))
331+ (define (concatenate! lists)
332+ (reduce-right append! '() lists))
333+ (define (%cdrs lists)
334+ (let f ([ls lists])
335+ (if (pair? ls)
336+ (let ([x (car ls)])
337+ (if (null? x) '() (cons (cdr x) (f (cdr ls)))))
338+ '())))
339+ (define (%cars+ lists last-elt)
340+ (let recur ([lists lists])
341+ (if (pair? lists)
342+ (cons (caar lists) (recur (cdr lists)))
343+ (list last-elt))))
344+ (define (%cars+cdrs lists)
345+ (let f ([ls lists])
346+ (if (pair? ls)
347+ (let ([x (car ls)])
348+ (if (null-list? x)
349+ (values '() '())
350+ (receive
351+ (cars cdrs)
352+ (f (cdr ls))
353+ (values (cons (car x) cars) (cons (cdr x) cdrs)))))
354+ (values '() '()))))
355+ (define (%cars+cdrs+ lists cars-final)
356+ (let f ([ls lists])
357+ (if (pair? ls)
358+ (let ([x (car ls)])
359+ (if (null-list? x)
360+ (values '() '())
361+ (receive
362+ (cars cdrs)
363+ (f (cdr ls))
364+ (values (cons (car x) cars) (cons (cdr x) cdrs)))))
365+ (values (list cars-final) '()))))
366+ (define (%cars+cdrs/no-test lists)
367+ (let recur ([lists lists])
368+ (if (pair? lists)
369+ (receive
370+ (list other-lists)
371+ (car+cdr lists)
372+ (receive
373+ (a d)
374+ (car+cdr list)
375+ (receive
376+ (cars cdrs)
377+ (recur other-lists)
378+ (values (cons a cars) (cons d cdrs)))))
379+ (values '() '()))))
380+ (define count
381+ (case-lambda
382+ [(pred list1)
383+ (check-arg procedure? pred count)
384+ (let lp ([lis list1] [i 0])
385+ (if (null-list? lis)
386+ i
387+ (lp (cdr lis) (if (pred (car lis)) (fx+ i 1) i))))]
388+ [(pred list1 . lists)
389+ (check-arg procedure? pred count)
390+ (let lp ([list1 list1] [lists lists] [i 0])
391+ (if (null-list? list1)
392+ i
393+ (receive
394+ (as ds)
395+ (%cars+cdrs lists)
396+ (if (null? as)
397+ i
398+ (lp (cdr list1)
399+ ds
400+ (if (apply pred (car list1) as)
401+ (fx+ i 1)
402+ i))))))]))
403+ (define unfold-right
404+ (case-lambda
405+ [(p f g seed) (unfold-right p f g seed '())]
406+ [(p f g seed tail)
407+ (check-arg procedure? p unfold-right)
408+ (check-arg procedure? f unfold-right)
409+ (check-arg procedure? g unfold-right)
410+ (let lp ([seed seed] [ans tail])
411+ (if (p seed) ans (lp (g seed) (cons (f seed) ans))))]))
412+ (define unfold
413+ (case-lambda
414+ [(p f g seed)
415+ (check-arg procedure? p unfold)
416+ (check-arg procedure? f unfold)
417+ (check-arg procedure? g unfold)
418+ (let recur ([seed seed])
419+ (if (p seed) '() (cons (f seed) (recur (g seed)))))]
420+ [(p f g seed tail-gen)
421+ (check-arg procedure? p unfold)
422+ (check-arg procedure? f unfold)
423+ (check-arg procedure? g unfold)
424+ (let recur ([seed seed])
425+ (if (p seed)
426+ (tail-gen seed)
427+ (cons (f seed) (recur (g seed)))))]))
428+ (define fold
429+ (case-lambda
430+ [(kons knil lis1)
431+ (check-arg procedure? kons fold)
432+ (let lp ([lis lis1] [ans knil])
433+ (if (null-list? lis)
434+ ans
435+ (lp (cdr lis) (kons (car lis) ans))))]
436+ [(kons knil lis1 lis2)
437+ (check-arg procedure? kons fold)
438+ (let lp ([lis1 lis1] [lis2 lis2] [ans knil])
439+ (if (or (null-list? lis1) (null-list? lis2))
440+ ans
441+ (lp (cdr lis1)
442+ (cdr lis2)
443+ (kons (car lis1) (car lis2) ans))))]
444+ [(kons knil . lists)
445+ (check-arg procedure? kons fold)
446+ (let lp ([lists lists] [ans knil])
447+ (receive
448+ (cars+ans cdrs)
449+ (%cars+cdrs+ lists ans)
450+ (if (null? cars+ans)
451+ ans
452+ (lp cdrs (apply kons cars+ans)))))]))
453+ (define fold-right
454+ (case-lambda
455+ [(kons knil lis1)
456+ (check-arg procedure? kons fold-right)
457+ (let recur ([lis lis1])
458+ (if (null-list? lis)
459+ knil
460+ (kons (car lis) (recur (cdr lis)))))]
461+ [(kons knil lis1 lis2)
462+ (check-arg procedure? kons fold-right)
463+ (let recur ([lis1 lis1] [lis2 lis2])
464+ (if (or (null-list? lis1) (null-list? lis2))
465+ knil
466+ (kons
467+ (car lis1)
468+ (car lis2)
469+ (recur (cdr lis1) (cdr lis2)))))]
470+ [(kons knil . lists)
471+ (check-arg procedure? kons fold-right)
472+ (let recur ([lists lists])
473+ (let ([cdrs (%cdrs lists)])
474+ (if (null? cdrs)
475+ knil
476+ (apply kons (%cars+ lists (recur cdrs))))))]))
477+ (define pair-fold-right
478+ (case-lambda
479+ [(f zero lis1)
480+ (check-arg procedure? f pair-fold-right)
481+ (let recur ([lis lis1])
482+ (if (null-list? lis) zero (f lis (recur (cdr lis)))))]
483+ [(f zero lis1 lis2 . lists)
484+ (check-arg procedure? f pair-fold-right)
485+ (let recur ([lis1 lis1] [lis2 lis2] [lists lists])
486+ (if (or (null-list? lis1) (null-list? lis2))
487+ zero
488+ (let ([cdrs (%cdrs lists)])
489+ (if (null? cdrs)
490+ zero
491+ (apply
492+ f
493+ lis1
494+ lis2
495+ (append!
496+ lists
497+ (list
498+ (recur (cdr lis1) (cdr lis2) cdrs))))))))]))
499+ (define pair-fold
500+ (case-lambda
501+ [(f zero lis1)
502+ (check-arg procedure? f pair-fold)
503+ (let lp ([lis lis1] [ans zero])
504+ (if (null? lis)
505+ ans
506+ (let ([tail (cdr lis)]) (lp tail (f lis ans)))))]
507+ [(f zero lis1 lis2 . lists)
508+ (check-arg procedure? f pair-fold)
509+ (let lp ([lis1 lis1] [lis2 lis2] [lists lists] [ans zero])
510+ (if (or (null-list? lis1) (null-list? lis2))
511+ ans
512+ (let ([tails (%cdrs lists)])
513+ (if (null? tails)
514+ ans
515+ (lp (cdr lis1)
516+ (cdr lis2)
517+ tails
518+ (apply
519+ f
520+ lis1
521+ lis2
522+ (append! lists (list ans))))))))]))
523+ (define (reduce f ridentity lis)
524+ (check-arg procedure? f reduce)
525+ (if (null-list? lis)
526+ ridentity
527+ (fold f (car lis) (cdr lis))))
528+ (define (reduce-right f ridentity lis)
529+ (check-arg procedure? f reduce-right)
530+ (if (null-list? lis)
531+ ridentity
532+ (let recur ([head (car lis)] [lis (cdr lis)])
533+ (if (pair? lis)
534+ (f head (recur (car lis) (cdr lis)))
535+ head))))
536+ (define append-map
537+ (case-lambda
538+ [(f lis1) (really-append-map append-map append f lis1)]
539+ [(f lis1 lis2)
540+ (really-append-map append-map append f lis1 lis2)]
541+ [(f lis1 lis2 . lists)
542+ (really-append-map append-map append f lis1 lis2 lists)]))
543+ (define append-map!
544+ (case-lambda
545+ [(f lis1) (really-append-map append-map! append! f lis1)]
546+ [(f lis1 lis2)
547+ (really-append-map append-map! append! f lis1 lis2)]
548+ [(f lis1 lis2 . lists)
549+ (really-append-map append-map! append! f lis1 lis2 lists)]))
550+ (define really-append-map
551+ (case-lambda
552+ [(who appender f lis1)
553+ (check-arg procedure? f who)
554+ (if (null-list? lis1)
555+ '()
556+ (let recur ([elt (car lis1)] [rest (cdr lis1)])
557+ (let ([vals (f elt)])
558+ (if (null-list? rest)
559+ vals
560+ (appender vals (recur (car rest) (cdr rest)))))))]
561+ [(who appender f lis1 lis2)
562+ (check-arg procedure? f who)
563+ (if (or (null-list? lis1) (null-list? lis2))
564+ '()
565+ (let recur ([lis1 lis1] [lis2 lis2])
566+ (let ([vals (f (car lis1) (car lis2))]
567+ [lis1 (cdr lis1)]
568+ [lis2 (cdr lis2)])
569+ (if (or (null-list? lis1) (null-list? lis2))
570+ vals
571+ (appender vals (recur lis1 lis2))))))]
572+ [(who appender f lis1 lis2 lists)
573+ (check-arg procedure? f who)
574+ (if (or (null-list? lis1) (null-list? lis2))
575+ '()
576+ (receive
577+ (cars cdrs)
578+ (%cars+cdrs lists)
579+ (if (null? cars)
580+ '()
581+ (let recur ([lis1 lis1]
582+ [lis2 lis2]
583+ [cars cars]
584+ [cdrs cdrs])
585+ (let ([vals (apply f (car lis1) (car lis2) cars)]
586+ [lis1 (cdr lis1)]
587+ [lis2 (cdr lis2)])
588+ (if (or (null-list? lis1) (null-list? lis2))
589+ vals
590+ (receive
591+ (cars2 cdrs2)
592+ (%cars+cdrs cdrs)
593+ (if (null? cars2)
594+ vals
595+ (appender
596+ vals
597+ (recur
598+ lis1
599+ lis2
600+ cars2
601+ cdrs2))))))))))]))
602+ (define pair-for-each
603+ (case-lambda
604+ [(proc lis1)
605+ (check-arg procedure? proc pair-for-each)
606+ (let lp ([lis lis1])
607+ (if (not (null-list? lis))
608+ (let ([tail (cdr lis)]) (proc lis) (lp tail))))]
609+ [(proc lis1 lis2 . lists)
610+ (check-arg procedure? proc pair-for-each)
611+ (let lp ([lis1 lis1] [lis2 lis2] [lists lists])
612+ (if (and (pair? lis1) (pair? lis2))
613+ (let ([tails (%cdrs lists)])
614+ (if (pair? tails)
615+ (begin
616+ (apply proc lis1 lis2 lists)
617+ (lp (cdr lis1) (cdr lis2) tails))))))]))
618+ (define map!
619+ (case-lambda
620+ [(f lis1)
621+ (check-arg procedure? f map!)
622+ (let lp ([lis1 lis1])
623+ (when (not (null-list? lis1))
624+ (set-car! lis1 (f (car lis1)))
625+ (lp (cdr lis1))))
626+ lis1]
627+ [(f lis1 lis2)
628+ (check-arg procedure? f map!)
629+ (let lp ([lis1 lis1] [lis2 lis2])
630+ (when (not (null-list? lis1))
631+ (set-car! lis1 (f (car lis1) (car lis2)))
632+ (lp (cdr lis1) (cdr lis2))))
633+ lis1]
634+ [(f lis1 lis2 lis3 . lists)
635+ (check-arg procedure? f map!)
636+ (let lp ([lis1 lis1] [lis2 lis2] [lis3 lis3] [lists lists])
637+ (when (not (null-list? lis1))
638+ (receive
639+ (heads tails)
640+ (%cars+cdrs/no-test lists)
641+ (set-car!
642+ lis1
643+ (apply f (car lis1) (car lis2) (car lis3) heads))
644+ (lp (cdr lis1) (cdr lis2) (cdr lis3) tails))))
645+ lis1]))
646+ (define filter-map
647+ (case-lambda
648+ [(f lis1)
649+ (check-arg procedure? f filter-map)
650+ (let recur ([lis lis1])
651+ (if (null-list? lis)
652+ '()
653+ (let ([tail (recur (cdr lis))])
654+ (cond
655+ [(f (car lis)) => (lambda (x) (cons x tail))]
656+ [else tail]))))]
657+ [(f lis1 . lists)
658+ (check-arg procedure? f filter-map)
659+ (let recur ([lis1 lis1] [lists lists])
660+ (if (null-list? lis1)
661+ '()
662+ (receive
663+ (cars cdrs)
664+ (%cars+cdrs lists)
665+ (if (pair? cars)
666+ (cond
667+ [(apply f (car lis1) cars) =>
668+ (lambda (x) (cons x (recur (cdr lis1) cdrs)))]
669+ [else (recur (cdr lis1) cdrs)])
670+ '()))))]))
671+ (define map-in-order
672+ (case-lambda
673+ [(f lis1)
674+ (check-arg procedure? f map-in-order)
675+ (let recur ([lis lis1])
676+ (if (null-list? lis)
677+ lis
678+ (let ([tail (cdr lis)] [x (f (car lis))])
679+ (cons x (recur tail)))))]
680+ [(f lis1 lis2)
681+ (check-arg procedure? f map-in-order)
682+ (let recur ([lis1 lis1] [lis2 lis2])
683+ (if (and (pair? lis1) (pair? lis2))
684+ (let ([x (f (car lis1) (car lis2))])
685+ (cons x (recur (cdr lis1) (cdr lis2))))
686+ '()))]
687+ [(f lis1 lis2 . lists)
688+ (check-arg procedure? f map-in-order)
689+ (let recur ([lis1 lis1] [lis2 lis2] [lists lists])
690+ (receive
691+ (cars cdrs)
692+ (%cars+cdrs lists)
693+ (if (and (pair? lis1) (pair? lis2) (pair? cars))
694+ (let ([x (apply f (car lis1) (car lis2) cars)])
695+ (cons x (recur (cdr lis1) (cdr lis2) cdrs)))
696+ '())))]))
697+ (define map map-in-order)
698+ (define for-each
699+ (case-lambda
700+ [(f lis1) (r6rs:for-each f lis1)]
701+ [(f lis1 lis2)
702+ (check-arg procedure? f for-each)
703+ (let recur ([lis1 lis1] [lis2 lis2])
704+ (unless (or (null-list? lis1) (null-list? lis2))
705+ (f (car lis1) (car lis2))
706+ (recur (cdr lis1) (cdr lis2))))]
707+ [(f lis1 lis2 . lists)
708+ (check-arg procedure? f for-each)
709+ (let recur ([lis1 lis1] [lis2 lis2] [lists lists])
710+ (unless (or (null-list? lis1) (null-list? lis2))
711+ (receive
712+ (cars cdrs)
713+ (%cars+cdrs lists)
714+ (when (pair? cars)
715+ (apply f (car lis1) (car lis2) cars)
716+ (recur (cdr lis1) (cdr lis2) cdrs)))))]))
717+ (define (filter pred lis)
718+ (check-arg procedure? pred filter)
719+ (let recur ([lis lis])
720+ (if (null-list? lis)
721+ lis
722+ (let ([head (car lis)] [tail (cdr lis)])
723+ (if (pred head)
724+ (let ([new-tail (recur tail)])
725+ (if (eq? tail new-tail) lis (cons head new-tail)))
726+ (recur tail))))))
727+ (define (filter! pred lis)
728+ (check-arg procedure? pred filter!)
729+ (let lp ([ans lis])
730+ (cond
731+ [(null-list? ans) ans]
732+ [(not (pred (car ans))) (lp (cdr ans))]
733+ [else
734+ (letrec ([scan-in (lambda (prev lis)
735+ (if (pair? lis)
736+ (if (pred (car lis))
737+ (scan-in lis (cdr lis))
738+ (scan-out prev (cdr lis)))))]
739+ [scan-out (lambda (prev lis)
740+ (let lp ([lis lis])
741+ (if (pair? lis)
742+ (if (pred (car lis))
743+ (begin
744+ (set-cdr! prev lis)
745+ (scan-in lis (cdr lis)))
746+ (lp (cdr lis)))
747+ (set-cdr! prev lis))))])
748+ (scan-in ans (cdr ans))
749+ ans)])))
750+ (define (partition pred lis)
751+ (check-arg procedure? pred partition)
752+ (let recur ([lis lis])
753+ (if (null-list? lis)
754+ (values lis lis)
755+ (let ([elt (car lis)] [tail (cdr lis)])
756+ (receive
757+ (in out)
758+ (recur tail)
759+ (if (pred elt)
760+ (values (if (pair? out) (cons elt in) lis) out)
761+ (values
762+ in
763+ (if (pair? in) (cons elt out) lis))))))))
764+ (define (partition! pred lis)
765+ (check-arg procedure? pred partition!)
766+ (if (null-list? lis)
767+ (values lis lis)
768+ (letrec ([scan-in (lambda (in-prev out-prev lis)
769+ (let lp ([in-prev in-prev] [lis lis])
770+ (if (pair? lis)
771+ (if (pred (car lis))
772+ (lp lis (cdr lis))
773+ (begin
774+ (set-cdr! out-prev lis)
775+ (scan-out
776+ in-prev
777+ lis
778+ (cdr lis))))
779+ (set-cdr! out-prev lis))))]
780+ [scan-out (lambda (in-prev out-prev lis)
781+ (let lp ([out-prev out-prev] [lis lis])
782+ (if (pair? lis)
783+ (if (pred (car lis))
784+ (begin
785+ (set-cdr! in-prev lis)
786+ (scan-in
787+ lis
788+ out-prev
789+ (cdr lis)))
790+ (lp lis (cdr lis)))
791+ (set-cdr! in-prev lis))))])
792+ (if (pred (car lis))
793+ (let lp ([prev-l lis] [l (cdr lis)])
794+ (cond
795+ [(not (pair? l)) (values lis l)]
796+ [(pred (car l)) (lp l (cdr l))]
797+ [else (scan-out prev-l l (cdr l)) (values lis l)]))
798+ (let lp ([prev-l lis] [l (cdr lis)])
799+ (cond
800+ [(not (pair? l)) (values l lis)]
801+ [(pred (car l))
802+ (scan-in l prev-l (cdr l))
803+ (values l lis)]
804+ [else (lp l (cdr l))]))))))
805+ (define (remove pred lis)
806+ (check-arg procedure? pred remove)
807+ (let recur ([lis lis])
808+ (if (null-list? lis)
809+ lis
810+ (let ([head (car lis)] [tail (cdr lis)])
811+ (if (not (pred head))
812+ (let ([new-tail (recur tail)])
813+ (if (eq? tail new-tail) lis (cons head new-tail)))
814+ (recur tail))))))
815+ (define (remove! pred lis)
816+ (check-arg procedure? pred remove!)
817+ (let lp ([ans lis])
818+ (cond
819+ [(null-list? ans) ans]
820+ [(pred (car ans)) (lp (cdr ans))]
821+ [else
822+ (letrec ([scan-in (lambda (prev lis)
823+ (if (pair? lis)
824+ (if (not (pred (car lis)))
825+ (scan-in lis (cdr lis))
826+ (scan-out prev (cdr lis)))))]
827+ [scan-out (lambda (prev lis)
828+ (let lp ([lis lis])
829+ (if (pair? lis)
830+ (if (not (pred (car lis)))
831+ (begin
832+ (set-cdr! prev lis)
833+ (scan-in lis (cdr lis)))
834+ (lp (cdr lis)))
835+ (set-cdr! prev lis))))])
836+ (scan-in ans (cdr ans))
837+ ans)])))
838+ (define delete
839+ (case-lambda
840+ [(x lis) (delete x lis equal?)]
841+ [(x lis elt=)
842+ (let recur ([lis lis])
843+ (if (null-list? lis)
844+ lis
845+ (let ([head (car lis)] [tail (cdr lis)])
846+ (if (not (elt= x head))
847+ (let ([new-tail (recur tail)])
848+ (if (eq? tail new-tail)
849+ lis
850+ (cons head new-tail)))
851+ (recur tail)))))]))
852+ (define delete!
853+ (case-lambda
854+ [(x lis) (delete! x lis equal?)]
855+ [(x lis elt=)
856+ (let lp ([ans lis])
857+ (cond
858+ [(null-list? ans) ans]
859+ [(elt= x (car ans)) (lp (cdr ans))]
860+ [else
861+ (letrec ([scan-in (lambda (prev lis)
862+ (if (pair? lis)
863+ (if (not (elt= x (car lis)))
864+ (scan-in lis (cdr lis))
865+ (scan-out prev (cdr lis)))))]
866+ [scan-out (lambda (prev lis)
867+ (let lp ([lis lis])
868+ (if (pair? lis)
869+ (if (not (elt= x (car lis)))
870+ (begin
871+ (set-cdr! prev lis)
872+ (scan-in lis (cdr lis)))
873+ (lp (cdr lis)))
874+ (set-cdr! prev lis))))])
875+ (scan-in ans (cdr ans))
876+ ans)]))]))
877+ (define member
878+ (case-lambda
879+ [(x lis) (r6rs:member x lis)]
880+ [(x lis elt=)
881+ (let lp ([lis lis])
882+ (and (not (null-list? lis))
883+ (if (elt= x (car lis)) lis (lp (cdr lis)))))]))
884+ (define delete-duplicates
885+ (case-lambda
886+ [(lis) (delete-duplicates lis equal?)]
887+ [(lis elt=)
888+ (check-arg procedure? elt= delete-duplicates)
889+ (let recur ([lis lis])
890+ (if (null-list? lis)
891+ lis
892+ (let* ([x (car lis)]
893+ [tail (cdr lis)]
894+ [new-tail (recur (delete x tail elt=))])
895+ (if (eq? tail new-tail) lis (cons x new-tail)))))]))
896+ (define delete-duplicates!
897+ (case-lambda
898+ [(lis) (delete-duplicates! lis equal?)]
899+ [(lis elt=)
900+ (check-arg procedure? elt= delete-duplicates!)
901+ (let recur ([lis lis])
902+ (if (null-list? lis)
903+ lis
904+ (let* ([x (car lis)]
905+ [tail (cdr lis)]
906+ [new-tail (recur (delete! x tail elt=))])
907+ (if (not (eq? tail new-tail)) (set-cdr! lis new-tail))
908+ lis)))]))
909+ (define assoc
910+ (case-lambda
911+ [(x lis) (r6rs:assoc x lis)]
912+ [(x lis elt=)
913+ (let loop ([lis lis])
914+ (if (pair? lis)
915+ (let ([entry (car lis)])
916+ (if (elt= x (car entry)) entry (loop (cdr lis))))
917+ #f))]))
918+ (define (alist-cons key datum alist)
919+ (cons (cons key datum) alist))
920+ (define (alist-copy alist)
921+ (map (lambda (elt) (cons (car elt) (cdr elt))) alist))
922+ (define alist-delete
923+ (case-lambda
924+ [(key alist)
925+ (remove (lambda (elt) (equal? key (car elt))) alist)]
926+ [(key alist elt=)
927+ (remove (lambda (elt) (elt= key (car elt))) alist)]))
928+ (define alist-delete!
929+ (case-lambda
930+ [(key alist)
931+ (remove! (lambda (elt) (equal? key (car elt))) alist)]
932+ [(key alist elt=)
933+ (remove! (lambda (elt) (elt= key (car elt))) alist)]))
934+ (define (find pred lis)
935+ (check-arg procedure? pred find)
936+ (let loop ([lis lis])
937+ (if (pair? lis)
938+ (let ([head (car lis)])
939+ (if (pred head) head (loop (cdr lis))))
940+ #f)))
941+ (define (find-tail pred lis)
942+ (check-arg procedure? pred find-tail)
943+ (let lp ([lis lis])
944+ (and (not (null-list? lis))
945+ (if (pred (car lis)) lis (lp (cdr lis))))))
946+ (define (take-while pred lis)
947+ (check-arg procedure? pred take-while)
948+ (let recur ([lis lis])
949+ (if (null-list? lis)
950+ '()
951+ (let ([x (car lis)])
952+ (if (pred x) (cons x (recur (cdr lis))) '())))))
953+ (define (drop-while pred lis)
954+ (check-arg procedure? pred drop-while)
955+ (let lp ([lis lis])
956+ (if (null-list? lis)
957+ '()
958+ (if (pred (car lis)) (lp (cdr lis)) lis))))
959+ (define (take-while! pred lis)
960+ (check-arg procedure? pred take-while!)
961+ (if (or (null-list? lis) (not (pred (car lis))))
962+ '()
963+ (begin
964+ (let lp ([prev lis] [rest (cdr lis)])
965+ (if (pair? rest)
966+ (let ([x (car rest)])
967+ (if (pred x)
968+ (lp rest (cdr rest))
969+ (set-cdr! prev '())))))
970+ lis)))
971+ (define (span pred lis)
972+ (check-arg procedure? pred span)
973+ (let recur ([lis lis])
974+ (if (null-list? lis)
975+ (values '() '())
976+ (let ([x (car lis)])
977+ (if (pred x)
978+ (receive
979+ (prefix suffix)
980+ (recur (cdr lis))
981+ (values (cons x prefix) suffix))
982+ (values '() lis))))))
983+ (define (span! pred lis)
984+ (check-arg procedure? pred span!)
985+ (if (or (null-list? lis) (not (pred (car lis))))
986+ (values '() lis)
987+ (let ([suffix (let lp ([prev lis] [rest (cdr lis)])
988+ (if (null-list? rest)
989+ rest
990+ (let ([x (car rest)])
991+ (if (pred x)
992+ (lp rest (cdr rest))
993+ (begin
994+ (set-cdr! prev '())
995+ rest)))))])
996+ (values lis suffix))))
997+ (define (break pred lis)
998+ (check-arg procedure? pred break)
999+ (let recur ([lis lis])
1000+ (if (null-list? lis)
1001+ (values '() '())
1002+ (let ([x (car lis)])
1003+ (if (not (pred x))
1004+ (receive
1005+ (prefix suffix)
1006+ (recur (cdr lis))
1007+ (values (cons x prefix) suffix))
1008+ (values '() lis))))))
1009+ (define (break! pred lis)
1010+ (check-arg procedure? pred break!)
1011+ (if (or (null-list? lis) (pred (car lis)))
1012+ (values '() lis)
1013+ (let ([suffix (let lp ([prev lis] [rest (cdr lis)])
1014+ (if (null-list? rest)
1015+ rest
1016+ (let ([x (car rest)])
1017+ (if (not (pred x))
1018+ (lp rest (cdr rest))
1019+ (begin
1020+ (set-cdr! prev '())
1021+ rest)))))])
1022+ (values lis suffix))))
1023+ (define any
1024+ (case-lambda
1025+ [(pred lis1)
1026+ (check-arg procedure? pred any)
1027+ (and (not (null-list? lis1))
1028+ (let loop ([head (car lis1)] [tail (cdr lis1)])
1029+ (if (null-list? tail)
1030+ (pred head)
1031+ (or (pred head) (loop (car tail) (cdr tail))))))]
1032+ [(pred lis1 lis2)
1033+ (check-arg procedure? pred any)
1034+ (and (not (null-list? lis1))
1035+ (not (null-list? lis2))
1036+ (let loop ([head1 (car lis1)]
1037+ [tail1 (cdr lis1)]
1038+ [head2 (car lis2)]
1039+ [tail2 (cdr lis2)])
1040+ (if (or (null-list? tail1) (null-list? tail2))
1041+ (pred head1 head2)
1042+ (or (pred head1 head2)
1043+ (loop
1044+ (car tail1)
1045+ (cdr tail1)
1046+ (car tail2)
1047+ (cdr tail2))))))]
1048+ [(pred lis1 lis2 . lists)
1049+ (check-arg procedure? pred any)
1050+ (and (not (null-list? lis1))
1051+ (not (null-list? lis2))
1052+ (receive
1053+ (heads tails)
1054+ (%cars+cdrs lists)
1055+ (and (pair? heads)
1056+ (let loop ([head1 (car lis1)]
1057+ [tail1 (cdr lis1)]
1058+ [head2 (car lis2)]
1059+ [tail2 (cdr lis2)]
1060+ [heads heads]
1061+ [tails tails])
1062+ (if (or (null-list? tail1) (null-list? tail2))
1063+ (apply pred head1 head2 heads)
1064+ (receive
1065+ (next-heads next-tails)
1066+ (%cars+cdrs tails)
1067+ (if (null? next-tails)
1068+ (apply pred head1 head2 heads)
1069+ (or (apply pred head1 head2 heads)
1070+ (loop (car tail1) (cdr tail1)
1071+ (car tail2) (cdr tail2)
1072+ next-heads
1073+ next-tails)))))))))]))
1074+ (define every
1075+ (case-lambda
1076+ [(pred lis1)
1077+ (check-arg procedure? pred every)
1078+ (or (null-list? lis1)
1079+ (let loop ([head (car lis1)] [tail (cdr lis1)])
1080+ (if (null-list? tail)
1081+ (pred head)
1082+ (and (pred head) (loop (car tail) (cdr tail))))))]
1083+ [(pred lis1 lis2)
1084+ (check-arg procedure? pred every)
1085+ (or (null-list? lis1)
1086+ (null-list? lis2)
1087+ (let loop ([head1 (car lis1)]
1088+ [tail1 (cdr lis1)]
1089+ [head2 (car lis2)]
1090+ [tail2 (cdr lis2)])
1091+ (if (or (null-list? tail1) (null-list? tail2))
1092+ (pred head1 head2)
1093+ (and (pred head1 head2)
1094+ (loop
1095+ (car tail1)
1096+ (cdr tail1)
1097+ (car tail2)
1098+ (cdr tail2))))))]
1099+ [(pred lis1 lis2 . lists)
1100+ (check-arg procedure? pred every)
1101+ (or (null-list? lis1)
1102+ (null-list? lis2)
1103+ (receive
1104+ (heads tails)
1105+ (%cars+cdrs lists)
1106+ (or (not (pair? heads))
1107+ (let loop ([head1 (car lis1)]
1108+ [tail1 (cdr lis1)]
1109+ [head2 (car lis2)]
1110+ [tail2 (cdr lis2)]
1111+ [heads heads]
1112+ [tails tails])
1113+ (if (or (null-list? tail1) (null-list? tail2))
1114+ (apply pred head1 head2 heads)
1115+ (receive
1116+ (next-heads next-tails)
1117+ (%cars+cdrs tails)
1118+ (if (null? next-tails)
1119+ (apply pred head1 head2 heads)
1120+ (and (apply pred head1 head2 heads)
1121+ (loop (car tail1) (cdr tail1)
1122+ (car tail2) (cdr tail2)
1123+ next-heads next-tails)))))))))]))
1124+ (define list-index
1125+ (case-lambda
1126+ [(pred lis1)
1127+ (check-arg procedure? pred list-index)
1128+ (let loop ([lis lis1] [n 0])
1129+ (and (not (null-list? lis))
1130+ (if (pred (car lis)) n (loop (cdr lis) (fx+ n 1)))))]
1131+ [(pred lis1 lis2)
1132+ (check-arg procedure? pred list-index)
1133+ (let loop ([lis1 lis1] [lis2 lis2] [n 0])
1134+ (and (not (or (null-list? lis1) (null-list? lis2)))
1135+ (if (pred (car lis1) (car lis2))
1136+ n
1137+ (loop (cdr lis1) (cdr lis2) (fx+ n 1)))))]
1138+ [(pred lis1 lis2 lis3 . lists)
1139+ (check-arg procedure? pred list-index)
1140+ (let loop ([lis1 lis1]
1141+ [lis2 lis2]
1142+ [lis3 lis3]
1143+ [lists lists]
1144+ [n 0])
1145+ (and (not (or (null-list? lis1)
1146+ (null-list? lis2)
1147+ (null-list? lis3)))
1148+ (receive
1149+ (heads tails)
1150+ (%cars+cdrs lists)
1151+ (and (not (null? heads))
1152+ (if (apply pred (car lis1) (car lis2) (car lis3)
1153+ heads)
1154+ n
1155+ (loop (cdr lis1) (cdr lis2) (cdr lis3) tails
1156+ (fx+ n 1)))))))]))
1157+ (define (reverse! lis)
1158+ (let lp ([lis lis] [ans '()])
1159+ (if (null-list? lis)
1160+ ans
1161+ (let ([tail (cdr lis)])
1162+ (set-cdr! lis ans)
1163+ (lp tail lis)))))
1164+ (define (%lset2<= = lis1 lis2)
1165+ (every (lambda (x) (member x lis2 =)) lis1))
1166+ (define lset<=
1167+ (case-lambda
1168+ [(=) (check-arg procedure? = lset<=) #t]
1169+ [(= lis1) (check-arg procedure? = lset<=) #t]
1170+ [(= lis1 lis2)
1171+ (check-arg procedure? = lset<=)
1172+ (or (eq? lis1 lis2) (%lset2<= = lis1 lis2))]
1173+ [(= lis1 lis2 lis3 . lists)
1174+ (check-arg procedure? = lset<=)
1175+ (and (or (eq? lis1 lis2) (%lset2<= = lis1 lis2))
1176+ (or (eq? lis2 lis3) (%lset2<= = lis2 lis3))
1177+ (or (null? lists)
1178+ (let loop ([lis1 lis3]
1179+ [lis2 (car lists)]
1180+ [lists (cdr lists)])
1181+ (and (or (eq? lis1 lis2) (%lset2<= = lis1 lis2))
1182+ (or (null? lists)
1183+ (loop
1184+ lis2
1185+ (car lists)
1186+ (cdr lists)))))))]))
1187+ (define lset=
1188+ (case-lambda
1189+ [(=) (check-arg procedure? = lset=) #t]
1190+ [(= lis1) (check-arg procedure? = lset=) #t]
1191+ [(= lis1 lis2)
1192+ (check-arg procedure? = lset=)
1193+ (or (eq? lis1 lis2)
1194+ (and (%lset2<= = lis1 lis2) (%lset2<= = lis2 lis1)))]
1195+ [(= lis1 lis2 lis3 . lists)
1196+ (check-arg procedure? = lset=)
1197+ (and (or (eq? lis1 lis2)
1198+ (and (%lset2<= = lis1 lis2) (%lset2<= = lis2 lis1)))
1199+ (or (eq? lis2 lis3)
1200+ (and (%lset2<= = lis2 lis3) (%lset2<= = lis3 lis2)))
1201+ (or (null? lists)
1202+ (let loop ([lis1 lis3]
1203+ [lis2 (car lists)]
1204+ [lists (cdr lists)])
1205+ (and (or (eq? lis1 lis2)
1206+ (and (%lset2<= = lis1 lis2)
1207+ (%lset2<= = lis2 lis1)))
1208+ (or (null? lists)
1209+ (loop
1210+ lis2
1211+ (car lists)
1212+ (cdr lists)))))))]))
1213+ (define lset-adjoin
1214+ (case-lambda
1215+ [(= lis) lis]
1216+ [(= lis elt)
1217+ (check-arg procedure? = lset-adjoin)
1218+ (if (member elt lis) lis (cons elt lis))]
1219+ [(= lis elt1 elt2)
1220+ (check-arg procedure? = lset-adjoin)
1221+ (let* ([lis (if (member elt1 lis) lis (cons elt1 lis))]
1222+ [lis (if (member elt2 lis) lis (cons elt2 lis))])
1223+ lis)]
1224+ [(= lis elt1 elt2 elt3 . elts)
1225+ (check-arg procedure? = lset-adjoin)
1226+ (let* ([lis (if (member elt1 lis) lis (cons elt1 lis))]
1227+ [lis (if (member elt2 lis) lis (cons elt2 lis))]
1228+ [lis (if (member elt3 lis) lis (cons elt3 lis))])
1229+ (if (null? elts)
1230+ lis
1231+ (fold
1232+ (lambda (elt ans)
1233+ (if (member elt ans =) ans (cons elt ans)))
1234+ lis
1235+ elts)))]))
1236+ (define lset-union
1237+ (let ([lset-union-2 (lambda (= lis1 lis2)
1238+ (cond
1239+ [(null? lis1) lis2]
1240+ [(null? lis2) lis1]
1241+ [(eq? lis1 lis2) lis1]
1242+ [else
1243+ (fold
1244+ (lambda (elt ans)
1245+ (if (member elt ans =)
1246+ ans
1247+ (cons elt ans)))
1248+ lis1
1249+ lis2)]))])
1250+ (case-lambda
1251+ [(=) (check-arg procedure? = lset-union) '()]
1252+ [(= lis1) (check-arg procedure? = lset-union) lis1]
1253+ [(= lis1 lis2)
1254+ (check-arg procedure? = lset-union)
1255+ (lset-union-2 = lis1 lis2)]
1256+ [(= lis1 lis2 lis3 . lists)
1257+ (check-arg procedure? = lset-union)
1258+ (let* ([lis (lset-union-2 = lis1 lis2)]
1259+ [lis (lset-union-2 = lis lis3)])
1260+ (if (null? lists)
1261+ lis
1262+ (fold
1263+ (lambda (lis2 lis1) (lset-union-2 = lis1 lis2))
1264+ lis
1265+ lists)))])))
1266+ (define lset-union!
1267+ (let ([lset-union-2! (lambda (= lis1 lis2)
1268+ (cond
1269+ [(null? lis1) lis2]
1270+ [(null? lis2) lis1]
1271+ [(eq? lis1 lis2) lis1]
1272+ [else
1273+ (pair-fold
1274+ (lambda (pair ans)
1275+ (let ([elt (car pair)])
1276+ (if (member elt ans =)
1277+ ans
1278+ (begin
1279+ (set-cdr! pair ans)
1280+ pair))))
1281+ lis1
1282+ lis2)]))])
1283+ (case-lambda
1284+ [(=) (check-arg procedure? = lset-union!) '()]
1285+ [(= lis1) (check-arg procedure? = lset-union!) lis1]
1286+ [(= lis1 lis2)
1287+ (check-arg procedure? = lset-union!)
1288+ (lset-union-2! = lis1 lis2)]
1289+ [(= lis1 lis2 lis3 . lists)
1290+ (check-arg procedure? = lset-union!)
1291+ (let* ([lis (lset-union-2! = lis1 lis2)]
1292+ [lis (lset-union-2! = lis lis3)])
1293+ (if (null? lists)
1294+ lis
1295+ (fold
1296+ (lambda (lis1 lis2) (lset-union-2! = lis1 lis2))
1297+ lis
1298+ lists)))])))
1299+ (define lset-intersection
1300+ (case-lambda
1301+ [(= lis1) (check-arg procedure? = lset-intersection) lis1]
1302+ [(= lis1 lis2)
1303+ (check-arg procedure? = lset-intersection)
1304+ (cond
1305+ [(or (null-list? lis1) (eq? lis1 lis2)) lis1]
1306+ [(null-list? lis2) lis2]
1307+ [else (filter (lambda (x) (member x lis2 =)) lis1)])]
1308+ [(= lis1 lis2 lis3 . lists)
1309+ (check-arg procedure? = lset-intersection)
1310+ (cond
1311+ [(or (null-list? lis1)
1312+ (null-list? lis2)
1313+ (null-list? lis3)
1314+ (any null-list? lists))
1315+ '()]
1316+ [(eq? lis2 lis1)
1317+ (if (eq? lis3 lis1)
1318+ (apply lset-intersection = lis1 lists)
1319+ (apply lset-intersection = lis1 lis3 lists))]
1320+ [(or (eq? lis3 lis1) (eq? lis3 lis2))
1321+ (apply lset-intersection = lis1 lis2 lists)]
1322+ [else
1323+ (let* ([lists (remove
1324+ (lambda (lis)
1325+ (or (eq? lis lis1)
1326+ (eq? lis lis2)
1327+ (eq? lis lis3)))
1328+ lists)])
1329+ (filter
1330+ (lambda (x)
1331+ (and (member x lis2 =)
1332+ (member x lis3 =)
1333+ (every (lambda (lis) (member x lis =)) lists)))
1334+ lis1))])]))
1335+ (define lset-intersection!
1336+ (case-lambda
1337+ [(= lis1) (check-arg procedure? = lset-intersection!) lis1]
1338+ [(= lis1 lis2)
1339+ (check-arg procedure? = lset-intersection!)
1340+ (cond
1341+ [(or (null-list? lis2) (eq? lis1 lis2)) lis1]
1342+ [(null-list? lis1) lis2]
1343+ [else (filter! (lambda (x) (member x lis2 =)) lis1)])]
1344+ [(= lis1 lis2 lis3 . lists)
1345+ (check-arg procedure? = lset-intersection!)
1346+ (cond
1347+ [(or (null-list? lis1)
1348+ (null-list? lis2)
1349+ (null-list? lis3)
1350+ (any null-list? lists))
1351+ '()]
1352+ [(eq? lis2 lis1)
1353+ (if (eq? lis3 lis1)
1354+ (apply lset-intersection! = lis1 lists)
1355+ (apply lset-intersection! = lis1 lis3 lists))]
1356+ [(or (eq? lis3 lis1) (eq? lis3 lis2))
1357+ (apply lset-intersection! = lis1 lis2 lists)]
1358+ [else
1359+ (let ([lists (remove
1360+ (lambda (lis)
1361+ (or (eq? lis lis1)
1362+ (eq? lis lis2)
1363+ (eq? lis lis3)))
1364+ lists)])
1365+ (filter!
1366+ (lambda (x)
1367+ (and (member x lis2 =)
1368+ (member x lis3 =)
1369+ (every (lambda (lis) (member x lis =)) lists)))
1370+ lis1))])]))
1371+ (define lset-difference
1372+ (case-lambda
1373+ [(= lis1) (check-arg procedure? = lset-difference) lis1]
1374+ [(= lis1 lis2)
1375+ (check-arg procedure? = lset-difference)
1376+ (cond
1377+ [(null-list? lis2) lis1]
1378+ [(or (null-list? lis1) (eq? lis1 lis2)) '()]
1379+ [else (filter (lambda (x) (not (member x lis2 =))) lis1)])]
1380+ [(= lis1 lis2 lis3 . lists)
1381+ (check-arg procedure? = lset-difference)
1382+ (cond
1383+ [(or (null-list? lis1)
1384+ (eq? lis1 lis2)
1385+ (eq? lis1 lis3)
1386+ (memq lis1 lists))
1387+ '()]
1388+ [(null? lis2)
1389+ (if (null? lis3)
1390+ (apply lset-difference lis1 lists)
1391+ (apply lset-difference lis1 lis3 lists))]
1392+ [(or (null? lis3) (eq? lis3 lis2))
1393+ (apply lset-difference lis1 lis2 lists)]
1394+ [else
1395+ (let ([lists (remove
1396+ (lambda (lis)
1397+ (or (null? lis)
1398+ (eq? lis lis2)
1399+ (eq? lis lis3)))
1400+ lists)])
1401+ (filter
1402+ (lambda (x)
1403+ (and (not (member x lis2 =))
1404+ (not (member x lis3 =))
1405+ (every
1406+ (lambda (lis) (not (member x lis =)))
1407+ lists)))
1408+ lis1))])]))
1409+ (define lset-difference!
1410+ (case-lambda
1411+ [(= lis1) (check-arg procedure? = lset-difference!) lis1]
1412+ [(= lis1 lis2)
1413+ (check-arg procedure? = lset-difference!)
1414+ (cond
1415+ [(null-list? lis2) lis1]
1416+ [(or (null-list? lis1) (eq? lis1 lis2)) '()]
1417+ [else (filter! (lambda (x) (not (member x lis2 =))) lis1)])]
1418+ [(= lis1 lis2 lis3 . lists)
1419+ (check-arg procedure? = lset-difference!)
1420+ (cond
1421+ [(or (null-list? lis1)
1422+ (eq? lis1 lis2)
1423+ (eq? lis1 lis3)
1424+ (memq lis1 lists))
1425+ '()]
1426+ [(null? lis2)
1427+ (if (null? lis3)
1428+ (apply lset-difference lis1 lists)
1429+ (apply lset-difference lis1 lis3 lists))]
1430+ [(or (null? lis3) (eq? lis3 lis2))
1431+ (apply lset-difference lis1 lis2 lists)]
1432+ [else
1433+ (let ([lists (remove
1434+ (lambda (lis)
1435+ (or (null? lis)
1436+ (eq? lis lis2)
1437+ (eq? lis lis3)))
1438+ lists)])
1439+ (filter!
1440+ (lambda (x)
1441+ (and (not (member x lis2 =))
1442+ (every
1443+ (lambda (lis) (not (member x lis =)))
1444+ lists)))
1445+ lis1))])]))
1446+ (define lset-xor
1447+ (let ([lset-xor-2 (lambda (= b a)
1448+ (receive
1449+ (a-b a-int-b)
1450+ (lset-diff+intersection = a b)
1451+ (cond
1452+ [(null? a-b) (lset-difference = b a)]
1453+ [(null? a-int-b) (append b a)]
1454+ [else
1455+ (fold
1456+ (lambda (xb ans)
1457+ (if (member xb a-int-b =)
1458+ ans
1459+ (cons xb ans)))
1460+ a-b
1461+ b)])))])
1462+ (case-lambda
1463+ [(=) (check-arg procedure? = lset-xor) '()]
1464+ [(= a) (check-arg procedure? = lset-xor) a]
1465+ [(= a b)
1466+ (check-arg procedure? = lset-xor)
1467+ (lset-xor-2 = b a)]
1468+ [(= a b c . lists)
1469+ (check-arg procedure? = lset-xor)
1470+ (let* ([lis (lset-xor-2 = b a)] [lis (lset-xor-2 = c lis)])
1471+ (if (null? lists)
1472+ lis
1473+ (fold
1474+ (lambda (b a) (lset-xor-2 = b a))
1475+ lis
1476+ lists)))])))
1477+ (define lset-xor!
1478+ (let ([lset-xor-2! (lambda (= b a)
1479+ (receive
1480+ (a-b a-int-b)
1481+ (lset-diff+intersection! = a b)
1482+ (cond
1483+ [(null? a-b) (lset-difference! = b a)]
1484+ [(null? a-int-b) (append! b a)]
1485+ [else
1486+ (pair-fold
1487+ (lambda (b-pair ans)
1488+ (if (member (car b-pair) a-int-b =)
1489+ ans
1490+ (begin
1491+ (set-cdr! b-pair ans)
1492+ b-pair)))
1493+ a-b
1494+ b)])))])
1495+ (case-lambda
1496+ [(=) (check-arg procedure? = lset-xor!) '()]
1497+ [(= a) (check-arg procedure? = lset-xor!) a]
1498+ [(= a b)
1499+ (check-arg procedure? = lset-xor!)
1500+ (lset-xor-2! = b a)]
1501+ [(= a b c . lists)
1502+ (check-arg procedure? = lset-xor!)
1503+ (let* ([lis (lset-xor-2! = b a)]
1504+ [lis (lset-xor-2! = c lis)])
1505+ (if (null? lists)
1506+ lis
1507+ (fold
1508+ (lambda (b a) (lset-xor-2! = b a))
1509+ lis
1510+ lists)))])))
1511+ (define lset-diff+intersection
1512+ (case-lambda
1513+ [(= lis1)
1514+ (check-arg procedure? = lset-diff+intersection)
1515+ (values lis1 '())]
1516+ [(= lis1 lis2)
1517+ (check-arg procedure? = lset-diff+intersection)
1518+ (cond
1519+ [(or (null-list? lis1) (eq? lis1 lis2)) (values '() lis1)]
1520+ [(null-list? lis2) (values lis1 '())]
1521+ [else
1522+ (partition
1523+ (lambda (elt) (not (member elt lis2 =)))
1524+ lis1)])]
1525+ [(= lis1 lis2 lis3 . lists)
1526+ (check-arg procedure? = lset-diff+intersection)
1527+ (cond
1528+ [(or (null-list? lis1)
1529+ (eq? lis1 lis2)
1530+ (eq? lis1 lis3)
1531+ (memq lis1 lists))
1532+ (values '() lis1)]
1533+ [(null-list? lis2)
1534+ (if (null-list? lis3)
1535+ (apply lset-diff+intersection = lis1 lists)
1536+ (apply lset-diff+intersection = lis1 lis3 lists))]
1537+ [(or (null-list? lis3) (eq? lis3 lis2))
1538+ (apply lset-diff+intersection = lis1 lis2 lists)]
1539+ [else
1540+ (let ([lists (remove
1541+ (lambda (lis)
1542+ (or (null? lis)
1543+ (eq? lis lis2)
1544+ (eq? lis lis3)))
1545+ lists)])
1546+ (partition
1547+ (lambda (elt)
1548+ (not (or (member elt lis2 =)
1549+ (member elt lis3 =)
1550+ (any (lambda (lis) (member elt lis =))
1551+ lists))))
1552+ lis1))])]))
1553+ (define lset-diff+intersection!
1554+ (case-lambda
1555+ [(= lis1)
1556+ (check-arg procedure? = lset-diff+intersection!)
1557+ (values lis1 '())]
1558+ [(= lis1 lis2)
1559+ (check-arg procedure? = lset-diff+intersection!)
1560+ (cond
1561+ [(or (null-list? lis1) (eq? lis1 lis2)) (values '() lis1)]
1562+ [(null-list? lis2) (values lis1 '())]
1563+ [else
1564+ (partition!
1565+ (lambda (elt) (not (member elt lis2 =)))
1566+ lis1)])]
1567+ [(= lis1 lis2 lis3 . lists)
1568+ (check-arg procedure? = lset-diff+intersection!)
1569+ (cond
1570+ [(or (null-list? lis1)
1571+ (eq? lis1 lis2)
1572+ (eq? lis1 lis3)
1573+ (memq lis1 lists))
1574+ (values '() lis1)]
1575+ [(null-list? lis2)
1576+ (if (null-list? lis3)
1577+ (apply lset-diff+intersection! = lis1 lists)
1578+ (apply lset-diff+intersection! = lis1 lis3 lists))]
1579+ [(or (null-list? lis3) (eq? lis3 lis2))
1580+ (apply lset-diff+intersection = lis1 lis2 lists)]
1581+ [else
1582+ (let ([lists (remove
1583+ (lambda (lis)
1584+ (or (null? lis)
1585+ (eq? lis lis2)
1586+ (eq? lis lis3)))
1587+ lists)])
1588+ (partition!
1589+ (lambda (elt)
1590+ (not (or (member elt lis2 =)
1591+ (member elt lis3 =)
1592+ (any (lambda (lis) (member elt lis =))
1593+ lists))))
1594+ lis1))])]))))))
vendor/purs/runtime/srfi/:125.slsnew file+27
@@ -0,0 +1,27 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a125.sls
7+(library (purs runtime srfi :125)
8+ (export make-hash-table hash-table hash-table-unfold
9+ alist->hash-table hash-table? hash-table-contains?
10+ hash-table-empty? hash-table=? hash-table-mutable?
11+ hash-table-ref hash-table-ref/default hash-table-set!
12+ hash-table-delete! hash-table-intern! hash-table-update!
13+ hash-table-update!/default hash-table-pop! hash-table-clear!
14+ hash-table-size hash-table-keys hash-table-values
15+ hash-table-entries hash-table-find hash-table-count
16+ hash-table-map hash-table-for-each hash-table-map!
17+ hash-table-map->list hash-table-fold hash-table-prune!
18+ hash-table-copy hash-table-empty-copy hash-table->alist
19+ hash-table-union! hash-table-intersection!
20+ hash-table-difference! hash-table-xor! deprecated:hash
21+ deprecated:string-hash deprecated:string-ci-hash
22+ deprecated:hash-by-identity
23+ deprecated:hash-table-equivalence-function
24+ deprecated:hash-table-hash-function
25+ deprecated:hash-table-exists? deprecated:hash-table-walk
26+ deprecated:hash-table-merge!)
27+ (import (purs runtime srfi :125 hashtables)))
vendor/purs/runtime/srfi/:125/hashtables.slsnew file+378
@@ -0,0 +1,378 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a125/hashtables.sls
7+;;;;;; File header: %3a125/125.body.scm
8+;;; Copyright 2015 William D Clinger.
9+;;;
10+;;; Permission to copy this software, in whole or in part, to use this
11+;;; software for any lawful purpose, and to redistribute this software
12+;;; is granted subject to the restriction that all copies made of this
13+;;; software must include this copyright and permission notice in full.
14+;;;
15+;;; I also request that you send me a copy of any improvements that you
16+;;; make to this software so that they may be incorporated within it to
17+;;; the benefit of the Scheme community.
18+;;;
19+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20+(library (purs runtime srfi :125 hashtables)
21+ (export make-hash-table hash-table hash-table-unfold
22+ alist->hash-table hash-table? hash-table-contains?
23+ hash-table-empty? hash-table=? hash-table-mutable?
24+ hash-table-ref hash-table-ref/default hash-table-set!
25+ hash-table-delete! hash-table-intern! hash-table-update!
26+ hash-table-update!/default hash-table-pop! hash-table-clear!
27+ hash-table-size hash-table-keys hash-table-values
28+ hash-table-entries hash-table-find hash-table-count
29+ hash-table-map hash-table-for-each hash-table-map!
30+ hash-table-map->list hash-table-fold hash-table-prune!
31+ hash-table-copy hash-table-empty-copy hash-table->alist
32+ hash-table-union! hash-table-intersection!
33+ hash-table-difference! hash-table-xor! deprecated:hash
34+ deprecated:string-hash deprecated:string-ci-hash
35+ deprecated:hash-by-identity
36+ deprecated:hash-table-equivalence-function
37+ deprecated:hash-table-hash-function
38+ deprecated:hash-table-exists? deprecated:hash-table-walk
39+ deprecated:hash-table-merge!)
40+ (import
41+ (except (rnrs) make-hashtable hashtable-clear! hashtable-copy
42+ hashtable-ref hashtable-update! make-eq-hashtable
43+ make-eqv-hashtable)
44+ (purs runtime srfi private include)
45+ (rename (purs runtime srfi :126) (hashtable? hash-table?)
46+ (hashtable-contains? hash-table-contains?)
47+ (hashtable-empty? hash-table-empty?)
48+ (hashtable-intern! hash-table-intern!)
49+ (hashtable-clear! hash-table-clear!)
50+ (hashtable-copy hash-table-copy)
51+ (hashtable-size hash-table-size)
52+ (hashtable-pop! hash-table-pop!)
53+ (hashtable-merge! hash-table-merge!)
54+ (hashtable-hash-function hash-table-hash-function)
55+ (hashtable-equivalence-function
56+ hash-table-equivalence-function))
57+ (except (purs runtime srfi :128) hash-salt string-hash string-ci-hash
58+ symbol-hash))
59+ (begin
60+ (define (issue-deprecated-warnings?) #t)
61+ (define (issue-warning-deprecated
62+ name-of-deprecated-misfeature)
63+ (if (not (memq
64+ name-of-deprecated-misfeature
65+ already-warned))
66+ (begin
67+ (set! already-warned
68+ (cons name-of-deprecated-misfeature already-warned))
69+ (if (issue-deprecated-warnings?)
70+ (let ([out (current-error-port)])
71+ (display "WARNING: " out)
72+ (display name-of-deprecated-misfeature out)
73+ (newline out)
74+ (display " is deprecated by SRFI 125. See" out)
75+ (newline out)
76+ (display " " out)
77+ (display url:deprecated out)
78+ (newline out))))))
79+ (define url:deprecated
80+ "http://srfi.schemers.org/srfi-125/srfi-125.html")
81+ (define already-warned '())
82+ (define %enforce-comparator-type-tests #t)
83+ (define (%comparator-hash-function comparator)
84+ (let ([okay? (comparator-type-test-predicate comparator)]
85+ [hash-function (comparator-hash-function comparator)])
86+ (if %enforce-comparator-type-tests
87+ (lambda (x . rest)
88+ (cond
89+ [(not (okay? x))
90+ (error #f
91+ "key rejected by hash-table comparator"
92+ x
93+ comparator)]
94+ [(null? rest) (hash-function x)]
95+ [else (apply hash-function x rest)]))
96+ hash-function)))
97+ (define %not-found (list '%not-found))
98+ (define %not-found-irritant (list 'not-found))
99+ (define %not-found-message "hash-table key not found")
100+ (define (%check-optional-arguments procname args)
101+ (if (memq 'thread-safe args)
102+ (error (string-append
103+ (symbol->string procname)
104+ ": unsupported optional argument(s)")
105+ args)))
106+ (define (%get-hash-table-weakness args)
107+ (cond
108+ [(memq 'ephemeral-values args)
109+ (if (or (memq 'ephemeral-keys args) (memq 'weak-keys args))
110+ 'ephemeral-key-and-value
111+ 'ephemeral-value)]
112+ [(memq 'ephemeral-keys args)
113+ (if (memq 'weak-values args)
114+ 'ephemeral-key-and-value
115+ 'ephemeral-key)]
116+ [(memq 'weak-keys args)
117+ (if (memq 'weak-values args) 'weak-key-and-value 'weak-key)]
118+ [(memq 'weak-values args) 'weak-value]
119+ [else #f]))
120+ (define (%get-hash-table-capacity args) (find fixnum? args))
121+ (define (hash-table-every proc ht)
122+ (call-with-values
123+ (lambda () (hashtable-entries ht))
124+ (lambda (keys vals)
125+ (let ([size (vector-length keys)])
126+ (let loop ([i 0])
127+ (or (fx>=? i size)
128+ (let* ([key (vector-ref keys i)]
129+ [val (vector-ref vals i)])
130+ (and (proc key val) (loop (fx+ i 1))))))))))
131+ (define (make-hash-table comparator/equiv . rest)
132+ (if (comparator? comparator/equiv)
133+ (let ([equiv (comparator-equality-predicate
134+ comparator/equiv)]
135+ [hash-function (%comparator-hash-function
136+ comparator/equiv)])
137+ (%make-hash-table equiv hash-function rest))
138+ (let* ([equiv comparator/equiv]
139+ [hash-function (if (and (not (null? rest))
140+ (procedure? (car rest)))
141+ (car rest)
142+ #f)]
143+ [rest (if hash-function (cdr rest) rest)])
144+ (issue-warning-deprecated 'srfi-69-style:make-hash-table)
145+ (%make-hash-table equiv hash-function rest))))
146+ (define (%make-hash-table equiv hash-function opts)
147+ (%check-optional-arguments 'make-hash-table opts)
148+ (let ([weakness (%get-hash-table-weakness opts)]
149+ [capacity (%get-hash-table-capacity opts)])
150+ (cond
151+ [(equal? equiv eq?) (make-eq-hashtable capacity weakness)]
152+ [(equal? equiv eqv?) (make-eqv-hashtable capacity weakness)]
153+ [hash-function
154+ (make-hashtable hash-function equiv capacity weakness)]
155+ [(equal? equiv equal?)
156+ (make-hashtable equal-hash equiv capacity weakness)]
157+ [(equal? equiv string=?)
158+ (make-hashtable string-hash equiv capacity weakness)]
159+ [(equal? equiv string-ci=?)
160+ (make-hashtable string-ci-hash equiv capacity weakness)]
161+ [(equal? equiv symbol=?)
162+ (make-hashtable symbol-hash equiv capacity weakness)]
163+ [else
164+ (error "make-hash-table: unable to infer hash function"
165+ equiv)])))
166+ (define (hash-table comparator . rest)
167+ (let ([ht (apply make-hash-table comparator rest)])
168+ (let loop ([kvs rest])
169+ (cond
170+ [(null? kvs) #f]
171+ [(null? (cdr kvs))
172+ (error #f "hash-table: wrong number of arguments")]
173+ [(hashtable-contains? ht (car kvs))
174+ (error "hash-table: two equivalent keys were provided"
175+ (car kvs))]
176+ [else
177+ (hashtable-set! ht (car kvs) (cadr kvs))
178+ (loop (cddr kvs))]))
179+ (hash-table-copy ht #f)))
180+ (define (hash-table-unfold stop? mapper successor seed
181+ comparator . rest)
182+ (let ([ht (apply make-hash-table comparator rest)])
183+ (let loop ([seed seed])
184+ (if (stop? seed)
185+ ht
186+ (call-with-values
187+ (lambda () (mapper seed))
188+ (lambda (key val)
189+ (hash-table-set! ht key val)
190+ (loop (successor seed))))))))
191+ (define (alist->hash-table alist comparator/equiv . rest)
192+ (if (and (not (null? rest)) (procedure? (car rest)))
193+ (issue-warning-deprecated 'srfi-69-style:alist->hash-table))
194+ (let ([ht (apply make-hash-table comparator/equiv rest)]
195+ [entries (reverse alist)])
196+ (for-each
197+ (lambda (entry)
198+ (hash-table-set! ht (car entry) (cdr entry)))
199+ entries)
200+ ht))
201+ (define (hash-table=? value-comparator ht1 ht2)
202+ (let ([val=? (comparator-equality-predicate
203+ value-comparator)]
204+ [n1 (hash-table-size ht1)]
205+ [n2 (hash-table-size ht2)])
206+ (and (= n1 n2)
207+ (eq? (hashtable-equivalence-function ht1)
208+ (hashtable-equivalence-function ht2))
209+ (hash-table-every
210+ (lambda (key val1)
211+ (and (hash-table-contains? ht2 key)
212+ (val=? val1 (hashtable-ref ht2 key 'ignored))))
213+ ht1))))
214+ (define (hash-table-mutable? ht) (hashtable-mutable? ht))
215+ (define hash-table-ref
216+ (case-lambda
217+ [(ht key) (hashtable-ref ht key)]
218+ [(ht key failure)
219+ (let ([val (hashtable-ref ht key %not-found)])
220+ (if (eq? val %not-found) (failure) val))]
221+ [(ht key failure success)
222+ (let ([val (hashtable-ref ht key %not-found)])
223+ (if (eq? val %not-found) (failure) (success val)))]))
224+ (define (hash-table-ref/default ht key default)
225+ (hashtable-ref ht key default))
226+ (define hash-table-set!
227+ (case-lambda
228+ [(ht) #f]
229+ [(ht key val) (hashtable-set! ht key val)]
230+ [(ht key1 val1 key2 val2 . others)
231+ (hashtable-set! ht key1 val1)
232+ (hashtable-set! ht key2 val2)
233+ (apply hash-table-set! ht others)]))
234+ (define (hash-table-delete! ht . keys)
235+ (let ([count 0])
236+ (for-each
237+ (lambda (key)
238+ (when (hashtable-contains? ht key)
239+ (set! count (fx+ 1 count))
240+ (hashtable-delete! ht key)))
241+ keys)
242+ count))
243+ (define hash-table-update!
244+ (case-lambda
245+ [(ht key updater) (hashtable-update! ht key updater)]
246+ [(ht key updater failure)
247+ (let ([updater* (lambda (val)
248+ (if (eq? %not-found val)
249+ (updater (failure))
250+ (updater val)))])
251+ (hashtable-update! ht key updater* %not-found))]
252+ [(ht key updater failure success)
253+ (let* ([updater* (lambda (val)
254+ (if (eq? %not-found val)
255+ (updater (failure))
256+ (success (updater val))))])
257+ (hashtable-update! ht key updater* %not-found))]))
258+ (define (hash-table-update!/default ht key updater default)
259+ (hashtable-update! ht key updater default))
260+ (define (hash-table-keys ht)
261+ (vector->list (hashtable-keys ht)))
262+ (define (hash-table-values ht)
263+ (vector->list (hashtable-values ht)))
264+ (define (hash-table-entries ht)
265+ (call-with-values
266+ (lambda () (hashtable-entries ht))
267+ (lambda (keys vals)
268+ (values (vector->list keys) (vector->list vals)))))
269+ (define (hash-table-find proc ht failure)
270+ (call-with-values
271+ (lambda () (hashtable-entries ht))
272+ (lambda (keys vals)
273+ (let ([size (vector-length keys)])
274+ (let loop ([i 0])
275+ (if (fx>=? i size)
276+ (failure)
277+ (let* ([key (vector-ref keys i)]
278+ [val (vector-ref vals i)]
279+ [x (proc key val)])
280+ (or x (loop (fx+ i 1))))))))))
281+ (define (hash-table-count pred ht)
282+ (let ([count 0])
283+ (call-with-values
284+ (lambda () (hashtable-entries ht))
285+ (lambda (keys vals)
286+ (vector-for-each
287+ (lambda (key val)
288+ (if (pred key val) (set! count (fx+ count 1))))
289+ keys
290+ vals)))
291+ count))
292+ (define (hash-table-map proc comparator ht)
293+ (let ([result (make-hash-table comparator)])
294+ (hash-table-for-each
295+ (lambda (key val) (hash-table-set! result key (proc val)))
296+ ht)
297+ result))
298+ (define (hash-table-map->list proc ht)
299+ (call-with-values
300+ (lambda () (hash-table-entries ht))
301+ (lambda (keys vals) (map proc keys vals))))
302+ (define (hash-table-for-each proc ht)
303+ (hashtable-walk ht proc))
304+ (define (hash-table-map! proc ht)
305+ (hashtable-update-all! ht proc))
306+ (define (hash-table-fold proc init ht)
307+ (if (hashtable? proc)
308+ (deprecated:hash-table-fold proc init ht)
309+ (hashtable-sum ht init proc)))
310+ (define (hash-table-prune! proc ht)
311+ (hashtable-prune! ht proc))
312+ (define (hash-table-empty-copy ht)
313+ (let* ([ht2 (hash-table-copy ht #t)]
314+ [ignored (hash-table-clear! ht2)])
315+ ht2))
316+ (define (hash-table->alist ht)
317+ (call-with-values
318+ (lambda () (hash-table-entries ht))
319+ (lambda (keys vals) (map cons keys vals))))
320+ (define (hash-table-union! ht1 ht2)
321+ (hash-table-for-each
322+ (lambda (key2 val2)
323+ (if (not (hashtable-contains? ht1 key2))
324+ (hashtable-set! ht1 key2 val2)))
325+ ht2)
326+ ht1)
327+ (define (hash-table-intersection! ht1 ht2)
328+ (hash-table-for-each
329+ (lambda (key1 val1)
330+ (if (not (hashtable-contains? ht2 key1))
331+ (hashtable-delete! ht1 key1)))
332+ ht1)
333+ ht1)
334+ (define (hash-table-difference! ht1 ht2)
335+ (hash-table-for-each
336+ (lambda (key1 val1)
337+ (if (hashtable-contains? ht2 key1)
338+ (hashtable-delete! ht1 key1)))
339+ ht1)
340+ ht1)
341+ (define (hash-table-xor! ht1 ht2)
342+ (hash-table-for-each
343+ (lambda (key2 val2)
344+ (if (hashtable-contains? ht1 key2)
345+ (hashtable-delete! ht1 key2)
346+ (hashtable-set! ht1 key2 val2)))
347+ ht2)
348+ ht1)
349+ (define (deprecated:hash obj . rest)
350+ (issue-warning-deprecated 'hash)
351+ (default-hash obj))
352+ (define (deprecated:string-hash obj . rest)
353+ (issue-warning-deprecated 'srfi-125:string-hash)
354+ (string-hash obj))
355+ (define (deprecated:string-ci-hash obj . rest)
356+ (issue-warning-deprecated 'srfi-125:string-ci-hash)
357+ (string-ci-hash obj))
358+ (define (deprecated:hash-by-identity obj . rest)
359+ (issue-warning-deprecated 'hash-by-identity)
360+ (deprecated:hash obj))
361+ (define (deprecated:hash-table-equivalence-function ht)
362+ (issue-warning-deprecated 'hash-table-equivalence-function)
363+ (hashtable-equivalence-function ht))
364+ (define (deprecated:hash-table-hash-function ht)
365+ (issue-warning-deprecated 'hash-table-hash-function)
366+ (hashtable-hash-function ht))
367+ (define (deprecated:hash-table-exists? ht key)
368+ (issue-warning-deprecated 'hash-table-exists?)
369+ (hash-table-contains? ht key))
370+ (define (deprecated:hash-table-walk ht proc)
371+ (issue-warning-deprecated 'hash-table-walk)
372+ (hash-table-for-each proc ht))
373+ (define (deprecated:hash-table-fold ht proc seed)
374+ (issue-warning-deprecated 'srfi-69-style:hash-table-fold)
375+ (hash-table-fold proc seed ht))
376+ (define (deprecated:hash-table-merge! ht1 ht2)
377+ (issue-warning-deprecated 'hash-table-merge!)
378+ (hash-table-union! ht1 ht2))))
vendor/purs/runtime/srfi/:126.slsnew file+23
@@ -0,0 +1,23 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a126.sls
7+(library (purs runtime srfi :126)
8+ (export make-eq-hashtable make-eqv-hashtable make-hashtable
9+ alist->eq-hashtable alist->eqv-hashtable alist->hashtable
10+ weakness hashtable? hashtable-size hashtable-ref
11+ hashtable-set! hashtable-delete! hashtable-contains?
12+ hashtable-lookup hashtable-update! hashtable-intern!
13+ hashtable-copy hashtable-clear! hashtable-empty-copy
14+ hashtable-keys hashtable-values hashtable-entries
15+ hashtable-key-list hashtable-value-list
16+ hashtable-entry-lists hashtable-walk hashtable-update-all!
17+ hashtable-prune! hashtable-merge! hashtable-sum
18+ hashtable-map->lset hashtable-find hashtable-empty?
19+ hashtable-pop! hashtable-inc! hashtable-dec!
20+ hashtable-equivalence-function hashtable-hash-function
21+ hashtable-weakness hashtable-mutable? hash-salt equal-hash
22+ string-hash string-ci-hash symbol-hash)
23+ (import (purs runtime srfi :126 r6rs-hashtables)))
vendor/purs/runtime/srfi/:126/helpers/helpers.chezscheme.slsnew file+111
@@ -0,0 +1,111 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a126/helpers/helpers.chezscheme.sls
7+(library (purs runtime srfi :126 helpers helpers)
8+ (export make-weak-eq-hashtable-procedure
9+ weak-eq-hashtables-supported
10+ make-weak-eqv-hashtable-procedure
11+ weak-eqv-hashtables-supported make-weak-hashtable-procedure
12+ weak-hashtables-supported
13+ make-ephemeral-eq-hashtable-procedure
14+ ephemeral-eq-hashtables-supported
15+ make-ephemeral-eqv-hashtable-procedure
16+ ephemeral-eqv-hashtables-supported
17+ make-ephemeral-hashtable-procedure
18+ ephemeral-hashtables-supported hashtable-values
19+ hashtable-weakness hashtable-cell-support hashtable-cell
20+ hashtable-cell-key hashtable-cell-value
21+ set-hashtable-cell-value! get-environment-variable
22+ random-integer)
23+ (import
24+ (rename (chezscheme) (getenv get-environment-variable)))
25+ (define (make-weak-eq-hashtable-procedure weakness)
26+ (if (eq? weakness 'weak-key)
27+ make-weak-eq-hashtable
28+ (error 'make-weak-eq-hashtable
29+ "weakness not supported"
30+ weakness)))
31+ (define-syntax weak-eq-hashtables-supported
32+ (syntax-rules ()
33+ [(weak-eq-hashtables-supported) '(weak-key)]))
34+ (define (make-weak-eqv-hashtable-procedure weakness)
35+ (if (eq? weakness 'weak-key)
36+ make-weak-eqv-hashtable
37+ (error 'make-weak-eqv-hashtable
38+ "weakness not supported"
39+ weakness)))
40+ (define-syntax weak-eqv-hashtables-supported
41+ (syntax-rules ()
42+ [(weak-eqv-hashtables-supported) '(weak-key)]))
43+ (define (make-weak-hashtable-procedure weakness)
44+ (error 'make-weak-hashtable
45+ "weak hashtables not supported"))
46+ (define-syntax weak-hashtables-supported
47+ (syntax-rules () [(weak-hashtables-supported) '()]))
48+ (meta-cond
49+ [(let-values ([(major minor sub-minor)
50+ (scheme-version-number)])
51+ (or (> major 9) (and (= major 9) (>= minor 5))))
52+ (define (make-ephemeral-eq-hashtable-procedure weakness)
53+ (if (eq? weakness 'ephemeral-key)
54+ make-ephemeron-eq-hashtable
55+ (error 'make-ephemeral-eq-hashtable
56+ "weakness not supported"
57+ weakness)))
58+ (define-syntax ephemeral-eq-hashtables-supported
59+ (syntax-rules ()
60+ [(ephemeral-eq-hashtables-supported) '(ephemeral-key)]))
61+ (define (make-ephemeral-eqv-hashtable-procedure weakness)
62+ (if (eq? weakness 'ephemeral-key)
63+ make-ephemeron-eqv-hashtable
64+ (error 'make-ephemeral-eqv-hashtable
65+ "weakness not supported"
66+ weakness)))
67+ (define-syntax ephemeral-eqv-hashtables-supported
68+ (syntax-rules ()
69+ [(ephemeral-eqv-hashtables-supported) '(ephemeral-key)]))
70+ (define (make-ephemeral-hashtable-procedure weakness)
71+ (error 'make-ephemeral-hashtable
72+ "weakness not supported"
73+ weakness))
74+ (define-syntax ephemeral-hashtables-supported
75+ (syntax-rules ()
76+ [(ephemeral-hashtables-supported) '(ephemeral-key)]))
77+ (define (hashtable-weakness hashtable)
78+ (cond
79+ [(hashtable-weak? hashtable) 'weak-key]
80+ [(hashtable-ephemeron? hashtable) 'ephemeral-key]
81+ [else #f]))]
82+ [else
83+ (define (make-ephemeral-eq-hashtable-procedure weakness)
84+ (error 'make-ephemeral-hashtable
85+ "ephemeral eq hashtables not supported"))
86+ (define-syntax ephemeral-eq-hashtables-supported
87+ (syntax-rules () [(ephemeral-eq-hashtables-supported) '()]))
88+ (define (make-ephemeral-eqv-hashtable-procedure weakness)
89+ (error 'make-ephemeral-hashtable
90+ "ephemeral eqv hashtables not supported"))
91+ (define-syntax ephemeral-eqv-hashtables-supported
92+ (syntax-rules ()
93+ [(ephemeral-eqv-hashtables-supported) '()]))
94+ (define (make-ephemeral-hashtable-procedure weakness)
95+ (error 'make-ephemeral-hashtable
96+ "ephemeral hashtables not supported"))
97+ (define-syntax ephemeral-hashtables-supported
98+ (syntax-rules () [(ephemeral-hashtables-supported) '()]))
99+ (define (hashtable-weakness hashtable)
100+ (cond [(hashtable-weak? hashtable) 'weak-key] [else #f]))])
101+ (define-syntax hashtable-cell-support
102+ (syntax-rules () [(hashtable-cell-support) #t]))
103+ (define hashtable-cell-key car)
104+ (define hashtable-cell-value cdr)
105+ (define set-hashtable-cell-value! set-cdr!)
106+ (define (random-integer seed)
107+ (fxmod
108+ (fxxor
109+ (random seed)
110+ (fx* 3 (fxdiv (random (time-nanosecond (current-time))) 4)))
111+ seed)))
vendor/purs/runtime/srfi/:126/helpers/helpers.slsnew file+72
@@ -0,0 +1,72 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a126/helpers/helpers.sls
7+(library (purs runtime srfi :126 helpers helpers)
8+ (export make-weak-eq-hashtable-procedure
9+ weak-eq-hashtables-supported
10+ make-weak-eqv-hashtable-procedure
11+ weak-eqv-hashtables-supported make-weak-hashtable-procedure
12+ weak-hashtables-supported
13+ make-ephemeral-eq-hashtable-procedure
14+ ephemeral-eq-hashtables-supported
15+ make-ephemeral-eqv-hashtable-procedure
16+ ephemeral-eqv-hashtables-supported
17+ make-ephemeral-hashtable-procedure
18+ ephemeral-hashtables-supported hashtable-values
19+ hashtable-weakness hashtable-cell-support hashtable-cell
20+ hashtable-cell-key hashtable-cell-value
21+ set-hashtable-cell-value! get-environment-variable
22+ random-integer)
23+ (import
24+ (rnrs)
25+ (purs runtime srfi :39)
26+ (only (purs runtime srfi :27) random-integer)
27+ (only (purs runtime srfi :98) get-environment-variable))
28+ (define (make-weak-eq-hashtable-procedure weakness)
29+ (error 'make-weak-eq-hashtable
30+ "weak eq hashtables not supported"))
31+ (define-syntax weak-eq-hashtables-supported
32+ (syntax-rules () [(weak-eq-hashtables-supported) '()]))
33+ (define (make-weak-eqv-hashtable-procedure weakness)
34+ (error 'make-weak-eqv-hashtable
35+ "weak eqv hashtables not supported"))
36+ (define-syntax weak-eqv-hashtables-supported
37+ (syntax-rules () [(weak-eqv-hashtables-supported) '()]))
38+ (define (make-weak-hashtable-procedure weakness)
39+ (error 'make-weak-hashtable
40+ "weak hashtables not supported"))
41+ (define-syntax weak-hashtables-supported
42+ (syntax-rules () [(weak-hashtables-supported) '()]))
43+ (define (make-ephemeral-eq-hashtable-procedure weakness)
44+ (error 'make-ephemeral-hashtable
45+ "ephemeral eq hashtables not supported"))
46+ (define-syntax ephemeral-eq-hashtables-supported
47+ (syntax-rules () [(ephemeral-eq-hashtables-supported) '()]))
48+ (define (make-ephemeral-eqv-hashtable-procedure weakness)
49+ (error 'make-ephemeral-hashtable
50+ "ephemeral eqv hashtables not supported"))
51+ (define-syntax ephemeral-eqv-hashtables-supported
52+ (syntax-rules ()
53+ [(ephemeral-eqv-hashtables-supported) '()]))
54+ (define (make-ephemeral-hashtable-procedure weakness)
55+ (error 'make-ephemeral-hashtable
56+ "ephemeral hashtables not supported"))
57+ (define-syntax ephemeral-hashtables-supported
58+ (syntax-rules () [(ephemeral-hashtables-supported) '()]))
59+ (define (hashtable-values hashtable)
60+ (let-values ([(keys values) (hashtable-entries hashtable)])
61+ values))
62+ (define (hashtable-weakness hashtable) #f)
63+ (define-syntax hashtable-cell-support
64+ (syntax-rules () [(hashtable-cell-support) #f]))
65+ (define (hashtable-cell hashtable)
66+ (error 'hashtable-cell "hashtable cells not supported"))
67+ (define (hashtable-cell-key cell)
68+ (error 'hashtable-cell "hashtable cells not supported"))
69+ (define (hashtable-cell-value cell)
70+ (error 'hashtable-cell "hashtable cells not supported"))
71+ (define (set-hashtable-cell-value! cell value)
72+ (error 'hashtable-cell "hashtable cells not supported")))
vendor/purs/runtime/srfi/:126/r6rs-hashtables.slsnew file+354
@@ -0,0 +1,354 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a126/r6rs-hashtables.sls
7+;;;;;; File header: %3a126/126.body.scm
8+(library (purs runtime srfi :126 r6rs-hashtables)
9+ (export make-eq-hashtable make-eqv-hashtable make-hashtable
10+ alist->eq-hashtable alist->eqv-hashtable alist->hashtable
11+ weakness hashtable? hashtable-size hashtable-ref
12+ hashtable-set! hashtable-delete! hashtable-contains?
13+ hashtable-lookup hashtable-update! hashtable-intern!
14+ hashtable-copy hashtable-clear! hashtable-empty-copy
15+ hashtable-keys hashtable-values hashtable-entries
16+ hashtable-key-list hashtable-value-list
17+ hashtable-entry-lists hashtable-walk hashtable-update-all!
18+ hashtable-prune! hashtable-merge! hashtable-sum
19+ hashtable-map->lset hashtable-find hashtable-empty?
20+ hashtable-pop! hashtable-inc! hashtable-dec!
21+ hashtable-equivalence-function hashtable-hash-function
22+ hashtable-weakness hashtable-mutable? hash-salt equal-hash
23+ string-hash string-ci-hash symbol-hash)
24+ (import
25+ (rename (rnrs) (make-eq-hashtable rnrs:make-eq-hashtable)
26+ (make-eqv-hashtable rnrs:make-eqv-hashtable)
27+ (make-hashtable rnrs:make-hashtable)
28+ (hashtable-ref rnrs:hashtable-ref)
29+ (hashtable-update! rnrs:hashtable-update!)
30+ (hashtable-copy rnrs:hashtable-copy)
31+ (hashtable-clear! rnrs:hashtable-clear!))
32+ (purs runtime srfi :0 cond-expand)
33+ (purs runtime srfi :126 helpers helpers)
34+ (purs runtime srfi private include))
35+ (begin
36+ (define make-eq-hashtable
37+ (case-lambda
38+ [() (rnrs:make-eq-hashtable)]
39+ [(capacity)
40+ (if capacity
41+ (rnrs:make-eq-hashtable capacity)
42+ (rnrs:make-eq-hashtable))]
43+ [(capacity weakness)
44+ (if weakness
45+ (cond
46+ [(memq weakness (weak-eq-hashtables-supported))
47+ (if capacity
48+ ((make-weak-eq-hashtable-procedure weakness) capacity)
49+ ((make-weak-eq-hashtable-procedure weakness)))]
50+ [(memq weakness (ephemeral-eq-hashtables-supported))
51+ (if capacity
52+ ((make-ephemeral-eq-hashtable-procedure weakness)
53+ capacity)
54+ ((make-ephemeral-eq-hashtable-procedure weakness)))]
55+ [else
56+ (error 'make-eq-hashtable
57+ "weakness not supported"
58+ weakness)])
59+ (if capacity
60+ (rnrs:make-eq-hashtable capacity)
61+ (rnrs:make-eq-hashtable)))]))
62+ (define make-eqv-hashtable
63+ (case-lambda
64+ [() (rnrs:make-eqv-hashtable)]
65+ [(capacity)
66+ (if capacity
67+ (rnrs:make-eqv-hashtable capacity)
68+ (rnrs:make-eqv-hashtable))]
69+ [(capacity weakness)
70+ (if weakness
71+ (cond
72+ [(memq weakness (weak-eqv-hashtables-supported))
73+ (if capacity
74+ ((make-weak-eqv-hashtable-procedure weakness) capacity)
75+ ((make-weak-eqv-hashtable-procedure weakness)))]
76+ [(memq weakness (ephemeral-eqv-hashtables-supported))
77+ (if capacity
78+ ((make-ephemeral-eqv-hashtable-procedure weakness)
79+ capacity)
80+ ((make-ephemeral-eqv-hashtable-procedure weakness)))]
81+ [else
82+ (error 'make-eqv-hashtable
83+ "weakness not supported"
84+ weakness)])
85+ (if capacity
86+ (rnrs:make-eqv-hashtable capacity)
87+ (rnrs:make-eqv-hashtable)))]))
88+ (define make-hashtable
89+ (case-lambda
90+ [(hash equiv)
91+ (if hash
92+ (rnrs:make-hashtable
93+ (if (pair? hash) (car hash) hash)
94+ equiv)
95+ (cond
96+ [(eq? equiv eq?) (make-eq-hashtable)]
97+ [(eq? equiv eqv?) (make-eqv-hashtable)]
98+ [else
99+ (error 'make-hashtable
100+ "hash procedure cannot be #f except with eq? or eqv?"
101+ hash
102+ equiv)]))]
103+ [(hash equiv capacity)
104+ (if hash
105+ (if capacity
106+ (rnrs:make-hashtable
107+ (if (pair? hash) (car hash) hash)
108+ equiv
109+ capacity)
110+ (rnrs:make-hashtable
111+ (if (pair? hash) (car hash) hash)
112+ equiv))
113+ (cond
114+ [(eq? equiv eq?) (make-eq-hashtable capacity)]
115+ [(eq? equiv eqv?) (make-eqv-hashtable capacity)]
116+ [else
117+ (error 'make-hashtable
118+ "hash procedure cannot be #f except with eq? or eqv?"
119+ hash
120+ equiv)]))]
121+ [(hash equiv capacity weakness)
122+ (if hash
123+ (let ([hash (if (pair? hash) (car hash) hash)])
124+ (if weakness
125+ (cond
126+ [(memq weakness (weak-hashtables-supported))
127+ (if capacity
128+ ((make-weak-hashtable-procedure weakness)
129+ hash
130+ equiv
131+ capacity)
132+ ((make-weak-hashtable-procedure weakness)
133+ hash
134+ equiv))]
135+ [(memq weakness (ephemeral-hashtables-supported))
136+ (if capacity
137+ ((make-ephemeral-hashtable-procedure weakness)
138+ hash
139+ equiv
140+ capacity)
141+ ((make-ephemeral-hashtable-procedure weakness)
142+ hash
143+ equiv))]
144+ [else
145+ (error 'make-hashtable
146+ "weakness not supported"
147+ weakness)])
148+ (if capacity
149+ (rnrs:make-hashtable hash equiv capacity)
150+ (rnrs:make-hashtable hash equiv))))
151+ (cond
152+ [(eq? equiv eq?) (make-eq-hashtable capacity weakness)]
153+ [(eq? equiv eqv?) (make-eqv-hashtable capacity weakness)]
154+ [else
155+ (error 'make-hashtable
156+ "hash procedure cannot be #f except with eq? or eqv?"
157+ hash
158+ equiv)]))]))
159+ (define (alist->eq-hashtable . args)
160+ (apply alist->hashtable #f eq? args))
161+ (define (alist->eqv-hashtable . args)
162+ (apply alist->hashtable #f eqv? args))
163+ (define alist->hashtable
164+ (case-lambda
165+ [(hash equiv alist)
166+ (alist->hashtable hash equiv #f #f alist)]
167+ [(hash equiv capacity alist)
168+ (alist->hashtable hash equiv capacity #f alist)]
169+ [(hash equiv capacity weakness alist)
170+ (let ([hashtable (make-hashtable
171+ hash
172+ equiv
173+ capacity
174+ weakness)])
175+ (for-each
176+ (lambda (entry)
177+ (hashtable-set! hashtable (car entry) (cdr entry)))
178+ (reverse alist))
179+ hashtable)]))
180+ (define-enumeration weakness
181+ (weak-key weak-value weak-key-and-value ephemeral-key
182+ ephemeral-value ephemeral-key-and-value)
183+ weakness-set)
184+ (define nil (cons #f #f))
185+ (define (nil? obj) (eq? obj nil))
186+ (define hashtable-ref
187+ (case-lambda
188+ [(hashtable key)
189+ (let ([value (rnrs:hashtable-ref hashtable key nil)])
190+ (if (nil? value)
191+ (error "No such key in hashtable." hashtable key)
192+ value))]
193+ [(hashtable key default)
194+ (rnrs:hashtable-ref hashtable key default)]))
195+ (define (hashtable-lookup hashtable key)
196+ (let ([value (rnrs:hashtable-ref hashtable key nil)])
197+ (if (nil? value) (values #f #f) (values value #t))))
198+ (define hashtable-update!
199+ (case-lambda
200+ [(hashtable key proc)
201+ (rnrs:hashtable-update!
202+ hashtable
203+ key
204+ (lambda (value)
205+ (if (nil? value)
206+ (error "No such key in hashtable." hashtable key)
207+ (proc value)))
208+ nil)]
209+ [(hashtable key proc default)
210+ (rnrs:hashtable-update! hashtable key proc default)]))
211+ (define (hashtable-intern! hashtable key default-proc)
212+ (if (hashtable-cell-support)
213+ (let ([cell (hashtable-cell hashtable key nil)])
214+ (if (nil? (hashtable-cell-value cell))
215+ (let ([value (default-proc)])
216+ (set-hashtable-cell-value! cell value)
217+ value)
218+ (hashtable-cell-value cell)))
219+ (let ([value (rnrs:hashtable-ref hashtable key nil)])
220+ (if (nil? value)
221+ (let ([value (default-proc)])
222+ (hashtable-set! hashtable key value)
223+ value)
224+ value))))
225+ (define hashtable-copy
226+ (case-lambda
227+ [(hashtable) (hashtable-copy hashtable #f #f)]
228+ [(hashtable mutable) (hashtable-copy hashtable mutable #f)]
229+ [(hashtable mutable weakness)
230+ (when weakness
231+ (error 'hashtable-copy
232+ "No weak or ephemeral tables supported."))
233+ (rnrs:hashtable-copy hashtable mutable)]))
234+ (define hashtable-clear!
235+ (case-lambda
236+ [(hashtable) (rnrs:hashtable-clear! hashtable)]
237+ [(hashtable capacity)
238+ (if capacity
239+ (cond-expand
240+ (ikarus (rnrs:hashtable-clear! hashtable))
241+ (else (rnrs:hashtable-clear! hashtable capacity)))
242+ (rnrs:hashtable-clear! hashtable))]))
243+ (define hashtable-empty-copy
244+ (case-lambda
245+ [(hashtable) (hashtable-empty-copy hashtable #f)]
246+ [(hashtable capacity)
247+ (make-hashtable
248+ (hashtable-hash-function hashtable)
249+ (hashtable-equivalence-function hashtable)
250+ (if (eq? #t capacity) (hashtable-size hashtable) capacity)
251+ (hashtable-weakness hashtable))]))
252+ (define (hashtable-key-list hashtable)
253+ (hashtable-map->lset hashtable (lambda (key value) key)))
254+ (define (hashtable-value-list hashtable)
255+ (hashtable-map->lset hashtable (lambda (key value) value)))
256+ (define (hashtable-entry-lists hashtable)
257+ (let ([keys '()] [vals '()])
258+ (hashtable-walk
259+ hashtable
260+ (lambda (key val)
261+ (set! keys (cons key keys))
262+ (set! vals (cons val vals))))
263+ (values keys vals)))
264+ (define (hashtable-walk hashtable proc)
265+ (let-values ([(keys values) (hashtable-entries hashtable)])
266+ (vector-for-each proc keys values)))
267+ (define (hashtable-update-all! hashtable proc)
268+ (let-values ([(keys values) (hashtable-entries hashtable)])
269+ (vector-for-each
270+ (lambda (key value)
271+ (hashtable-set! hashtable key (proc key value)))
272+ keys
273+ values)))
274+ (define (hashtable-prune! hashtable proc)
275+ (let-values ([(keys values) (hashtable-entries hashtable)])
276+ (vector-for-each
277+ (lambda (key value)
278+ (when (proc key value) (hashtable-delete! hashtable key)))
279+ keys
280+ values)))
281+ (define (hashtable-merge! hashtable-dest hashtable-source)
282+ (let-values ([(keys values)
283+ (hashtable-entries hashtable-source)])
284+ (vector-for-each
285+ (lambda (key value)
286+ (hashtable-set! hashtable-dest key value))
287+ keys
288+ values))
289+ hashtable-dest)
290+ (define (hashtable-sum hashtable init proc)
291+ (let-values ([(keys vals) (hashtable-entries hashtable)])
292+ (let ([size (vector-length keys)])
293+ (let loop ([i 0] [result init])
294+ (if (fx>=? i size)
295+ result
296+ (loop
297+ (fx+ i 1)
298+ (proc
299+ (vector-ref keys i)
300+ (vector-ref vals i)
301+ result)))))))
302+ (define (hashtable-map->lset hashtable proc)
303+ (let-values ([(keys vals) (hashtable-entries hashtable)])
304+ (let ([size (vector-length keys)])
305+ (let loop ([i 0] [accumulator '()])
306+ (if (fx>=? i size)
307+ accumulator
308+ (loop
309+ (fx+ i 1)
310+ (cons
311+ (proc (vector-ref keys i) (vector-ref vals i))
312+ accumulator)))))))
313+ (define (hashtable-find hashtable proc)
314+ (call/cc
315+ (lambda (return)
316+ (hashtable-walk
317+ hashtable
318+ (lambda (key value)
319+ (when (proc key value) (return key value #t))))
320+ (return #f #f #f))))
321+ (define (hashtable-empty? hashtable)
322+ (fxzero? (hashtable-size hashtable)))
323+ (define (hashtable-pop! hashtable)
324+ (if (hashtable-empty? hashtable)
325+ (error "Cannot pop from empty hashtable." hashtable)
326+ (let-values ([(key value found?)
327+ (hashtable-find hashtable (lambda (k v) #t))])
328+ (hashtable-delete! hashtable key)
329+ (values key value))))
330+ (define hashtable-inc!
331+ (case-lambda
332+ [(hashtable key) (hashtable-inc! hashtable key 1)]
333+ [(hashtable key number)
334+ (hashtable-update!
335+ hashtable
336+ key
337+ (lambda (v) (+ v number))
338+ 0)]))
339+ (define hashtable-dec!
340+ (case-lambda
341+ [(hashtable key) (hashtable-dec! hashtable key 1)]
342+ [(hashtable key number)
343+ (hashtable-update!
344+ hashtable
345+ key
346+ (lambda (v) (- v number))
347+ 0)]))
348+ (define *hash-salt*
349+ (let ([seed (get-environment-variable
350+ "SRFI_126_HASH_SEED")])
351+ (if (or (not seed) (string=? seed ""))
352+ (random-integer (greatest-fixnum))
353+ (mod (string-hash seed) (greatest-fixnum)))))
354+ (define (hash-salt) *hash-salt*)))
vendor/purs/runtime/srfi/:128.slsnew file+19
@@ -0,0 +1,19 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a128.sls
7+(library (purs runtime srfi :128)
8+ (export comparator? comparator-ordered? comparator-hashable?
9+ make-comparator make-pair-comparator make-list-comparator
10+ make-vector-comparator make-eq-comparator
11+ make-eqv-comparator make-equal-comparator boolean-hash
12+ char-hash char-ci-hash string-hash string-ci-hash
13+ symbol-hash number-hash make-default-comparator default-hash
14+ comparator-register-default! comparator-type-test-predicate
15+ comparator-equality-predicate comparator-ordering-predicate
16+ comparator-hash-function comparator-test-type
17+ comparator-check-type comparator-hash hash-bound hash-salt
18+ =? <? >? <=? >=? comparator-if<=>)
19+ (import (purs runtime srfi :128 comparators)))
vendor/purs/runtime/srfi/:128/comparators.slsnew file+468
@@ -0,0 +1,468 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a128/comparators.sls
7+;;;;;; File header: %3a128/128.body1.scm
8+;;; Copyright (C) John Cowan (2015). All Rights Reserved.
9+;;;
10+;;; Permission is hereby granted, free of charge, to any person
11+;;; obtaining a copy of this software and associated documentation
12+;;; files (the "Software"), to deal in the Software without
13+;;; restriction, including without limitation the rights to use,
14+;;; copy, modify, merge, publish, distribute, sublicense, and/or
15+;;; sell copies of the Software, and to permit persons to whom the
16+;;; Software is furnished to do so, subject to the following
17+;;; conditions:
18+;;;
19+;;; The above copyright notice and this permission notice shall be
20+;;; included in all copies or substantial portions of the Software.
21+;;;
22+;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24+;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26+;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27+;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28+;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29+;;; OTHER DEALINGS IN THE SOFTWARE.
30+;;;;;; File header: %3a128/128.body2.scm
31+;;; Copyright (C) John Cowan (2015). All Rights Reserved.
32+;;;
33+;;; Permission is hereby granted, free of charge, to any person
34+;;; obtaining a copy of this software and associated documentation
35+;;; files (the "Software"), to deal in the Software without
36+;;; restriction, including without limitation the rights to use,
37+;;; copy, modify, merge, publish, distribute, sublicense, and/or
38+;;; sell copies of the Software, and to permit persons to whom the
39+;;; Software is furnished to do so, subject to the following
40+;;; conditions:
41+;;;
42+;;; The above copyright notice and this permission notice shall be
43+;;; included in all copies or substantial portions of the Software.
44+;;;
45+;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46+;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
47+;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48+;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
49+;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50+;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
51+;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
52+;;; OTHER DEALINGS IN THE SOFTWARE.
53+(library (purs runtime srfi :128 comparators)
54+ (export comparator? comparator-ordered? comparator-hashable?
55+ make-comparator make-pair-comparator make-list-comparator
56+ make-vector-comparator make-eq-comparator
57+ make-eqv-comparator make-equal-comparator boolean-hash
58+ char-hash char-ci-hash string-hash string-ci-hash
59+ symbol-hash number-hash make-default-comparator default-hash
60+ comparator-register-default! comparator-type-test-predicate
61+ comparator-equality-predicate comparator-ordering-predicate
62+ comparator-hash-function comparator-test-type
63+ comparator-check-type comparator-hash hash-bound hash-salt
64+ =? <? >? <=? >=? comparator-if<=>)
65+ (import (except (rnrs) define-record-type) (purs runtime srfi :99)
66+ (purs runtime srfi :39) (only (rnrs r5rs) modulo) (purs runtime srfi private include))
67+ (define (exact-integer? x) (and (integer? x) (exact? x)))
68+ (begin
69+ (define-syntax comparator-if<=>
70+ (syntax-rules ()
71+ [(if<=> a b less equal greater)
72+ (comparator-if<=> (make-default-comparator) a b less equal
73+ greater)]
74+ [(comparator-if<=> comparator a b less equal greater)
75+ (cond
76+ [(=? comparator a b) equal]
77+ [(<? comparator a b) less]
78+ [else greater])]))
79+ (define-syntax hash-bound
80+ (syntax-rules () [(hash-bound) 33554432]))
81+ (define %salt% (make-parameter 16064047))
82+ (define-syntax hash-salt
83+ (syntax-rules () [(hash-salt) (%salt%)]))
84+ (define-syntax with-hash-salt
85+ (syntax-rules ()
86+ [(with-hash-salt new-salt hash-func obj)
87+ (parameterize ([%salt% new-salt]) (hash-func obj))]))
88+ (define-record-type comparator
89+ (make-raw-comparator type-test equality ordering hash
90+ ordering? hash?)
91+ comparator?
92+ (type-test comparator-type-test-predicate)
93+ (equality comparator-equality-predicate)
94+ (ordering comparator-ordering-predicate)
95+ (hash comparator-hash-function)
96+ (ordering? comparator-ordered?)
97+ (hash? comparator-hashable?))
98+ (define (make-comparator type-test equality ordering hash)
99+ (make-raw-comparator (if (eq? type-test #t) (lambda (x) #t) type-test)
100+ (if (eq? equality #t)
101+ (lambda (x y) (eqv? (ordering x y) 0))
102+ equality)
103+ (if ordering
104+ ordering
105+ (lambda (x y) (error #f "ordering not supported")))
106+ (if hash
107+ hash
108+ (lambda (x y) (error #f "hashing not supported")))
109+ (if ordering #t #f) (if hash #t #f)))
110+ (define (comparator-test-type comparator obj)
111+ ((comparator-type-test-predicate comparator) obj))
112+ (define (comparator-check-type comparator obj)
113+ (if (comparator-test-type comparator obj)
114+ #t
115+ (error #f "comparator type check failed" comparator obj)))
116+ (define (comparator-hash comparator obj)
117+ ((comparator-hash-function comparator) obj))
118+ (define (binary=? comparator a b)
119+ ((comparator-equality-predicate comparator) a b))
120+ (define (binary<? comparator a b)
121+ ((comparator-ordering-predicate comparator) a b))
122+ (define (binary>? comparator a b) (binary<? comparator b a))
123+ (define (binary<=? comparator a b)
124+ (not (binary>? comparator a b)))
125+ (define (binary>=? comparator a b)
126+ (not (binary<? comparator a b)))
127+ (define (=? comparator a b . objs)
128+ (let loop ([a a] [b b] [objs objs])
129+ (and (binary=? comparator a b)
130+ (if (null? objs) #t (loop b (car objs) (cdr objs))))))
131+ (define (<? comparator a b . objs)
132+ (let loop ([a a] [b b] [objs objs])
133+ (and (binary<? comparator a b)
134+ (if (null? objs) #t (loop b (car objs) (cdr objs))))))
135+ (define (>? comparator a b . objs)
136+ (let loop ([a a] [b b] [objs objs])
137+ (and (binary>? comparator a b)
138+ (if (null? objs) #t (loop b (car objs) (cdr objs))))))
139+ (define (<=? comparator a b . objs)
140+ (let loop ([a a] [b b] [objs objs])
141+ (and (binary<=? comparator a b)
142+ (if (null? objs) #t (loop b (car objs) (cdr objs))))))
143+ (define (>=? comparator a b . objs)
144+ (let loop ([a a] [b b] [objs objs])
145+ (and (binary>=? comparator a b)
146+ (if (null? objs) #t (loop b (car objs) (cdr objs))))))
147+ (define (boolean<? a b) (and (not a) b))
148+ (define (boolean-hash obj) (if obj (%salt%) 0))
149+ (define (char-hash obj)
150+ (modulo (* (%salt%) (char->integer obj)) (hash-bound)))
151+ (define (char-ci-hash obj)
152+ (modulo
153+ (* (%salt%) (char->integer (char-foldcase obj)))
154+ (hash-bound)))
155+ (define (number-hash obj)
156+ (cond
157+ [(nan? obj) (%salt%)]
158+ [(and (infinite? obj) (positive? obj)) (* 2 (%salt%))]
159+ [(infinite? obj) (* (%salt%) 3)]
160+ [(real? obj) (abs (exact (round obj)))]
161+ [else
162+ (+ (number-hash (real-part obj))
163+ (number-hash (imag-part obj)))]))
164+ (define (complex<? a b)
165+ (if (= (real-part a) (real-part b))
166+ (< (imag-part a) (imag-part b))
167+ (< (real-part a) (real-part b))))
168+ (define (symbol<? a b)
169+ (string<? (symbol->string a) (symbol->string b)))
170+ (define (make-eq-comparator)
171+ (make-comparator #t eq? #f default-hash))
172+ (define (make-eqv-comparator)
173+ (make-comparator #t eqv? #f default-hash))
174+ (define (make-equal-comparator)
175+ (make-comparator #t equal? #f default-hash))
176+ (define (make-hasher)
177+ (let ([result (%salt%)])
178+ (case-lambda
179+ [() result]
180+ [(n)
181+ (set! result (+ (modulo (* result 33) (hash-bound)) n))
182+ result])))
183+ (define (make-pair-comparator car-comparator cdr-comparator)
184+ (make-comparator
185+ (make-pair-type-test car-comparator cdr-comparator)
186+ (make-pair=? car-comparator cdr-comparator)
187+ (make-pair<? car-comparator cdr-comparator)
188+ (make-pair-hash car-comparator cdr-comparator)))
189+ (define (make-pair-type-test car-comparator cdr-comparator)
190+ (lambda (obj)
191+ (and (pair? obj)
192+ (comparator-test-type car-comparator (car obj))
193+ (comparator-test-type cdr-comparator (cdr obj)))))
194+ (define (make-pair=? car-comparator cdr-comparator)
195+ (lambda (a b)
196+ (and ((comparator-equality-predicate car-comparator)
197+ (car a)
198+ (car b))
199+ ((comparator-equality-predicate cdr-comparator)
200+ (cdr a)
201+ (cdr b)))))
202+ (define (make-pair<? car-comparator cdr-comparator)
203+ (lambda (a b)
204+ (if (=? car-comparator (car a) (car b))
205+ (<? cdr-comparator (cdr a) (cdr b))
206+ (<? car-comparator (car a) (car b)))))
207+ (define (make-pair-hash car-comparator cdr-comparator)
208+ (lambda (obj)
209+ (let ([acc (make-hasher)])
210+ (acc (comparator-hash car-comparator (car obj)))
211+ (acc (comparator-hash cdr-comparator (cdr obj)))
212+ (acc))))
213+ (define (norp? obj) (or (null? obj) (pair? obj)))
214+ (define (make-list-comparator element-comparator type-test
215+ empty? head tail)
216+ (make-comparator
217+ (make-list-type-test element-comparator type-test empty?
218+ head tail)
219+ (make-list=? element-comparator type-test empty? head tail)
220+ (make-list<? element-comparator type-test empty? head tail)
221+ (make-list-hash element-comparator type-test empty? head
222+ tail)))
223+ (define (make-list-type-test element-comparator type-test
224+ empty? head tail)
225+ (lambda (obj)
226+ (and (type-test obj)
227+ (let ([elem-type-test (comparator-type-test-predicate
228+ element-comparator)])
229+ (let loop ([obj obj])
230+ (cond
231+ [(empty? obj) #t]
232+ [(not (elem-type-test (head obj))) #f]
233+ [else (loop (tail obj))]))))))
234+ (define (make-list=? element-comparator type-test empty?
235+ head tail)
236+ (lambda (a b)
237+ (let ([elem=? (comparator-equality-predicate
238+ element-comparator)])
239+ (let loop ([a a] [b b])
240+ (cond
241+ [(and (empty? a) (empty? b) #t)]
242+ [(empty? a) #f]
243+ [(empty? b) #f]
244+ [(elem=? (head a) (head b)) (loop (tail a) (tail b))]
245+ [else #f])))))
246+ (define (make-list<? element-comparator type-test empty?
247+ head tail)
248+ (lambda (a b)
249+ (let ([elem=? (comparator-equality-predicate
250+ element-comparator)]
251+ [elem<? (comparator-ordering-predicate element-comparator)])
252+ (let loop ([a a] [b b])
253+ (cond
254+ [(and (empty? a) (empty? b) #f)]
255+ [(empty? a) #t]
256+ [(empty? b) #f]
257+ [(elem=? (head a) (head b)) (loop (tail a) (tail b))]
258+ [(elem<? (head a) (head b)) #t]
259+ [else #f])))))
260+ (define (make-list-hash element-comparator type-test empty?
261+ head tail)
262+ (lambda (obj)
263+ (let ([elem-hash (comparator-hash-function
264+ element-comparator)]
265+ [acc (make-hasher)])
266+ (let loop ([obj obj])
267+ (cond
268+ [(empty? obj) (acc)]
269+ [else (acc (elem-hash (head obj))) (loop (tail obj))])))))
270+ (define (make-vector-comparator element-comparator type-test
271+ length ref)
272+ (make-comparator
273+ (make-vector-type-test
274+ element-comparator
275+ type-test
276+ length
277+ ref)
278+ (make-vector=? element-comparator type-test length ref)
279+ (make-vector<? element-comparator type-test length ref)
280+ (make-vector-hash element-comparator type-test length ref)))
281+ (define (make-vector-type-test element-comparator type-test
282+ length ref)
283+ (lambda (obj)
284+ (and (type-test obj)
285+ (let ([elem-type-test (comparator-type-test-predicate
286+ element-comparator)]
287+ [len (length obj)])
288+ (let loop ([n 0])
289+ (cond
290+ [(= n len) #t]
291+ [(not (elem-type-test (ref obj n))) #f]
292+ [else (loop (+ n 1))]))))))
293+ (define (make-vector=? element-comparator type-test length
294+ ref)
295+ (lambda (a b)
296+ (and (= (length a) (length b))
297+ (let ([elem=? (comparator-equality-predicate
298+ element-comparator)]
299+ [len (length b)])
300+ (let loop ([n 0])
301+ (cond
302+ [(= n len) #t]
303+ [(elem=? (ref a n) (ref b n)) (loop (+ n 1))]
304+ [else #f]))))))
305+ (define (make-vector<? element-comparator type-test length
306+ ref)
307+ (lambda (a b)
308+ (cond
309+ [(< (length a) (length b)) #t]
310+ [(> (length a) (length b)) #f]
311+ [else
312+ (let ([elem=? (comparator-equality-predicate
313+ element-comparator)]
314+ [elem<? (comparator-ordering-predicate
315+ element-comparator)]
316+ [len (length a)])
317+ (let loop ([n 0])
318+ (cond
319+ [(= n len) #f]
320+ [(elem=? (ref a n) (ref b n)) (loop (+ n 1))]
321+ [(elem<? (ref a n) (ref b n)) #t]
322+ [else #f])))])))
323+ (define (make-vector-hash element-comparator type-test
324+ length ref)
325+ (lambda (obj)
326+ (let ([elem-hash (comparator-hash-function
327+ element-comparator)]
328+ [acc (make-hasher)]
329+ [len (length obj)])
330+ (let loop ([n 0])
331+ (cond
332+ [(= n len) (acc)]
333+ [else (acc (elem-hash (ref obj n))) (loop (+ n 1))]))))))
334+ (begin
335+ (define unknown-object-comparator
336+ (make-comparator
337+ (lambda (obj) #t)
338+ (lambda (a b) #t)
339+ (lambda (a b) #f)
340+ (lambda (obj) 0)))
341+ (define first-comparator-index 9)
342+ (define *next-comparator-index* 9)
343+ (define *registered-comparators*
344+ (list unknown-object-comparator))
345+ (define (comparator-register-default! comparator)
346+ (set! *registered-comparators*
347+ (cons comparator *registered-comparators*))
348+ (set! *next-comparator-index*
349+ (+ *next-comparator-index* 1)))
350+ (define (object-type obj)
351+ (cond
352+ [(null? obj) 0]
353+ [(pair? obj) 1]
354+ [(boolean? obj) 2]
355+ [(char? obj) 3]
356+ [(string? obj) 4]
357+ [(symbol? obj) 5]
358+ [(number? obj) 6]
359+ [(vector? obj) 7]
360+ [(bytevector? obj) 8]
361+ [else (registered-index obj)]))
362+ (define (registered-index obj)
363+ (let loop ([i 0] [registry *registered-comparators*])
364+ (cond
365+ [(null? registry) (+ first-comparator-index i)]
366+ [(comparator-test-type (car registry) obj)
367+ (+ first-comparator-index i)]
368+ [else (loop (+ i 1) (cdr registry))])))
369+ (define (registered-comparator i)
370+ (list-ref
371+ *registered-comparators*
372+ (- i first-comparator-index)))
373+ (define (dispatch-equality type a b)
374+ (case type
375+ [(0) #t]
376+ [(1)
377+ ((make-pair=?
378+ (make-default-comparator)
379+ (make-default-comparator))
380+ a
381+ b)]
382+ [(2) (boolean=? a b)]
383+ [(3) (char=? a b)]
384+ [(4) (string=? a b)]
385+ [(5) (symbol=? a b)]
386+ [(6) (= a b)]
387+ [(7)
388+ ((make-vector=?
389+ (make-default-comparator)
390+ vector?
391+ vector-length
392+ vector-ref)
393+ a
394+ b)]
395+ [(8)
396+ ((make-vector=?
397+ (make-comparator exact-integer? = < default-hash)
398+ bytevector?
399+ bytevector-length
400+ bytevector-u8-ref)
401+ a
402+ b)]
403+ [else (binary=? (registered-comparator type) a b)]))
404+ (define (dispatch-ordering type a b)
405+ (case type
406+ [(0) 0]
407+ [(1)
408+ ((make-pair<?
409+ (make-default-comparator)
410+ (make-default-comparator))
411+ a
412+ b)]
413+ [(2) (boolean<? a b)]
414+ [(3) (char<? a b)]
415+ [(4) (string<? a b)]
416+ [(5) (symbol<? a b)]
417+ [(6) (complex<? a b)]
418+ [(7)
419+ ((make-vector<?
420+ (make-default-comparator)
421+ vector?
422+ vector-length
423+ vector-ref)
424+ a
425+ b)]
426+ [(8)
427+ ((make-vector<?
428+ (make-comparator exact-integer? = < default-hash)
429+ bytevector?
430+ bytevector-length
431+ bytevector-u8-ref)
432+ a
433+ b)]
434+ [else (binary<? (registered-comparator type) a b)]))
435+ (define (default-hash obj)
436+ (case (object-type obj)
437+ [(0 1 7) ((make-hasher) (equal-hash obj))]
438+ [(2) (boolean-hash obj)]
439+ [(3) (char-hash obj)]
440+ [(4) (string-hash obj)]
441+ [(5) (symbol-hash obj)]
442+ [(6) (number-hash obj)]
443+ [(8)
444+ ((make-vector-hash
445+ (make-default-comparator)
446+ bytevector?
447+ bytevector-length
448+ bytevector-u8-ref)
449+ obj)]
450+ [else
451+ (comparator-hash
452+ (registered-comparator (object-type obj))
453+ obj)]))
454+ (define (default-ordering a b)
455+ (let ([a-type (object-type a)] [b-type (object-type b)])
456+ (cond
457+ [(< a-type b-type) #t]
458+ [(> a-type b-type) #f]
459+ [else (dispatch-ordering a-type a b)])))
460+ (define (default-equality a b)
461+ (let ([a-type (object-type a)] [b-type (object-type b)])
462+ (if (= a-type b-type) (dispatch-equality a-type a b) #f)))
463+ (define (make-default-comparator)
464+ (make-comparator
465+ (lambda (obj) #t)
466+ default-equality
467+ default-ordering
468+ default-hash))))
vendor/purs/runtime/srfi/:133.slsnew file+17
@@ -0,0 +1,17 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a133.sls
7+(library (purs runtime srfi :133)
8+ (export vector-unfold vector-unfold-right vector-reverse-copy
9+ vector-concatenate vector-append-subvectors vector-empty?
10+ vector= vector-fold vector-fold-right vector-map!
11+ vector-count vector-cumulate vector-index vector-index-right
12+ vector-skip vector-skip-right vector-binary-search
13+ vector-any vector-every vector-partition vector-swap!
14+ vector-reverse! vector-reverse-copy! vector-unfold!
15+ vector-unfold-right! reverse-vector->list
16+ reverse-list->vector)
17+ (import (purs runtime srfi :133 vectors)))
vendor/purs/runtime/srfi/:133/vectors.slsnew file+885
@@ -0,0 +1,885 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a133/vectors.sls
7+;;;;;; File header: %3a133/vectors-impl.scm
8+;;;;;; SRFI 43: Vector library -*- Scheme -*-
9+;;;
10+;;; $Id$
11+;;;
12+;;; Taylor Campbell wrote this code; he places it in the public domain.
13+;;; Will Clinger [wdc] made some corrections, also in the public domain.
14+;;; John Cowan modified this code for SRFI 133; his changes are also in
15+;;; the public domain. However, in jurisdictions where it is not possible
16+;;; to dedicate something to the public domain, the entire implementation
17+;;; is made available under the same license as SRFI 133.
18+(library (purs runtime srfi :133 vectors)
19+ (export vector-unfold vector-unfold-right vector-copy
20+ vector-reverse-copy vector-append vector-concatenate
21+ vector-append-subvectors vector-empty? vector= vector-fold
22+ vector-fold-right vector-map vector-map! vector-for-each
23+ vector-count vector-cumulate vector-index vector-skip
24+ vector-index-right vector-skip-right vector-binary-search
25+ vector-any vector-every vector-partition vector-swap!
26+ vector-fill! vector-reverse! vector-copy!
27+ vector-reverse-copy! vector-unfold! vector-unfold-right!
28+ vector->list reverse-vector->list list->vector
29+ reverse-list->vector vector->string string->vector)
30+ (import
31+ (rename
32+ (rnrs)
33+ (vector-fill! rnrs:vector-fill!)
34+ (vector->list rnrs:vector->list)
35+ (list->vector rnrs:list->vector))
36+ (rnrs mutable-strings)
37+ (purs runtime srfi private include))
38+ (begin
39+ (define-syntax receive
40+ (syntax-rules ()
41+ [(receive ?formals ?producer ?body1 ?body2 ...)
42+ (call-with-values
43+ (lambda () ?producer)
44+ (lambda ?formals ?body1 ?body2 ...))]))
45+ (define-syntax let*-optionals
46+ (syntax-rules ()
47+ [(let*-optionals (?x ...) ((?var ?default) ...) ?body1
48+ ?body2 ...)
49+ (let ([args (?x ...)])
50+ (let*-optionals args ((?var ?default) ...) ?body1 ?body2
51+ ...))]
52+ [(let*-optionals ?args ((?var ?default) ...) ?body1 ?body2
53+ ...)
54+ (let*-optionals:aux ?args ?args ((?var ?default) ...) ?body1
55+ ?body2 ...)]))
56+ (define-syntax let*-optionals:aux
57+ (syntax-rules ()
58+ [(aux ?orig-args-var ?args-var () ?body1 ?body2 ...)
59+ (if (null? ?args-var)
60+ (let () ?body1 ?body2 ...)
61+ (error "too many arguments"
62+ (length ?orig-args-var)
63+ ?orig-args-var))]
64+ [(aux ?orig-args-var ?args-var ((?var ?default) ?more ...)
65+ ?body1 ?body2 ...)
66+ (if (null? ?args-var)
67+ (let* ([?var ?default] ?more ...) ?body1 ?body2 ...)
68+ (let ([?var (car ?args-var)] [new-args (cdr ?args-var)])
69+ (let*-optionals:aux ?orig-args-var new-args (?more ...)
70+ ?body1 ?body2 ...)))]))
71+ (define (nonneg-int? x)
72+ (and (integer? x) (not (negative? x))))
73+ (define (between? x y z) (and (< x y) (<= y z)))
74+ (define (unspecified-value) (if #f #f))
75+ (define (vectors-ref vectors i)
76+ (map (lambda (v) (vector-ref v i)) vectors))
77+ (define (check-type pred? value callee)
78+ (if (pred? value)
79+ value
80+ (check-type
81+ pred?
82+ (error "erroneous value"
83+ (list pred? value)
84+ `(while calling ,callee))
85+ callee)))
86+ (define (check-index vec index callee)
87+ (let ([index (check-type integer? index callee)])
88+ (cond
89+ [(< index 0)
90+ (check-index
91+ vec
92+ (error "vector index too low"
93+ index
94+ `(into vector ,vec)
95+ `(while calling ,callee))
96+ callee)]
97+ [(>= index (vector-length vec))
98+ (check-index
99+ vec
100+ (error "vector index too high"
101+ index
102+ `(into vector ,vec)
103+ `(while calling ,callee))
104+ callee)]
105+ [else index])))
106+ (define (check-indices vec start start-name end end-name
107+ callee)
108+ (let ([lose (lambda things
109+ (apply
110+ error
111+ "vector range out of bounds"
112+ (append things `(vector was ,vec) `(,start-name was ,start)
113+ `(,end-name was ,end) `(while calling ,callee))))]
114+ [start (check-type integer? start callee)]
115+ [end (check-type integer? end callee)])
116+ (cond
117+ [(> start end)
118+ (receive
119+ (new-start new-end)
120+ (lose `(,end-name < ,start-name))
121+ (check-indices vec new-start start-name new-end end-name
122+ callee))]
123+ [(< start 0)
124+ (check-indices vec (lose `(,start-name < 0)) start-name end
125+ end-name callee)]
126+ [(>= start (vector-length vec))
127+ (check-indices vec
128+ (lose `(,start-name > len) `(len was ,(vector-length vec)))
129+ start-name end end-name callee)]
130+ [(> end (vector-length vec))
131+ (check-indices vec start start-name
132+ (lose `(,end-name > len) `(len was ,(vector-length vec)))
133+ end-name callee)]
134+ [else (values start end)])))
135+ (define (vector-parse-start+end vec args start-name end-name
136+ callee)
137+ (let ([len (vector-length vec)])
138+ (cond
139+ [(null? args) (values 0 len)]
140+ [(null? (cdr args))
141+ (check-indices vec (car args) start-name len end-name
142+ callee)]
143+ [(null? (cddr args))
144+ (check-indices vec (car args) start-name (cadr args)
145+ end-name callee)]
146+ [else
147+ (error "too many arguments"
148+ `(extra args were ,(cddr args))
149+ `(while calling ,callee))])))
150+ (define-syntax let-vector-start+end
151+ (syntax-rules ()
152+ [(let-vector-start+end ?callee ?vec ?args (?start ?end)
153+ ?body1 ?body2 ...)
154+ (let ([?vec (check-type vector? ?vec ?callee)])
155+ (receive (?start ?end)
156+ (vector-parse-start+end ?vec ?args '?start '?end ?callee)
157+ ?body1 ?body2 ...))]))
158+ (define %smallest-length
159+ (letrec ([loop (lambda (vector-list length callee)
160+ (if (null? vector-list)
161+ length
162+ (loop
163+ (cdr vector-list)
164+ (min (vector-length
165+ (check-type
166+ vector?
167+ (car vector-list)
168+ callee))
169+ length)
170+ callee)))])
171+ loop))
172+ (define %vector-copy!
173+ (letrec ([loop/l->r (lambda (target source send i j)
174+ (cond
175+ [(< i send)
176+ (vector-set! target j (vector-ref source i))
177+ (loop/l->r target source send (+ i 1)
178+ (+ j 1))]))]
179+ [loop/r->l (lambda (target source sstart i j)
180+ (cond
181+ [(>= i sstart)
182+ (vector-set! target j (vector-ref source i))
183+ (loop/r->l target source sstart (- i 1)
184+ (- j 1))]))])
185+ (lambda (target tstart source sstart send)
186+ (if (> sstart tstart)
187+ (loop/l->r target source send sstart tstart)
188+ (loop/r->l target source sstart (- send 1)
189+ (+ -1 tstart send (- sstart)))))))
190+ (define %vector-reverse-copy!
191+ (letrec ([loop (lambda (target source sstart i j)
192+ (cond
193+ [(>= i sstart)
194+ (vector-set! target j (vector-ref source i))
195+ (loop target source sstart (- i 1) (+ j 1))]))])
196+ (lambda (target tstart source sstart send)
197+ (loop target source sstart (- send 1) tstart))))
198+ (define %vector-reverse!
199+ (letrec ([loop (lambda (vec i j)
200+ (cond
201+ [(<= i j)
202+ (let ([v (vector-ref vec i)])
203+ (vector-set! vec i (vector-ref vec j))
204+ (vector-set! vec j v)
205+ (loop vec (+ i 1) (- j 1)))]))])
206+ (lambda (vec start end) (loop vec start (- end 1)))))
207+ (define %vector-fold1
208+ (letrec ([loop (lambda (kons knil len vec i)
209+ (if (= i len)
210+ knil
211+ (loop kons (kons knil (vector-ref vec i)) len
212+ vec (+ i 1))))])
213+ (lambda (kons knil len vec) (loop kons knil len vec 0))))
214+ (define %vector-fold2+
215+ (letrec ([loop (lambda (kons knil len vectors i)
216+ (if (= i len)
217+ knil
218+ (loop kons
219+ (apply kons knil (vectors-ref vectors i)) len
220+ vectors (+ i 1))))])
221+ (lambda (kons knil len vectors)
222+ (loop kons knil len vectors 0))))
223+ (define %vector-map1!
224+ (letrec ([loop (lambda (f target vec i)
225+ (if (zero? i)
226+ target
227+ (let ([j (- i 1)])
228+ (vector-set! target j (f (vector-ref vec j)))
229+ (loop f target vec j))))])
230+ (lambda (f target vec len) (loop f target vec len))))
231+ (define %vector-map2+!
232+ (letrec ([loop (lambda (f target vectors i)
233+ (if (zero? i)
234+ target
235+ (let ([j (- i 1)])
236+ (vector-set!
237+ target
238+ j
239+ (apply f (vectors-ref vectors j)))
240+ (loop f target vectors j))))])
241+ (lambda (f target vectors len)
242+ (loop f target vectors len))))
243+ (define (vector-unfold f length . initial-seeds)
244+ (define vec (make-vector length))
245+ (apply vector-unfold! f vec 0 length initial-seeds)
246+ vec)
247+ (define vector-unfold!
248+ (letrec ([tabulate! (lambda (f vec i len)
249+ (cond
250+ [(< i len)
251+ (vector-set! vec i (f i))
252+ (tabulate! f vec (+ i 1) len)]))]
253+ [unfold1! (lambda (f vec i len seed)
254+ (if (< i len)
255+ (receive
256+ (elt new-seed)
257+ (f i seed)
258+ (vector-set! vec i elt)
259+ (unfold1! f vec (+ i 1) len new-seed))))]
260+ [unfold2+! (lambda (f vec i len seeds)
261+ (if (< i len)
262+ (receive
263+ (elt . new-seeds)
264+ (apply f i seeds)
265+ (vector-set! vec i elt)
266+ (unfold2+! f vec (+ i 1) len
267+ new-seeds))))])
268+ (lambda (f vec start end . initial-seeds)
269+ (let ([f (check-type procedure? f vector-unfold!)]
270+ [start (check-type nonneg-int? start vector-unfold!)]
271+ [end (check-type nonneg-int? end vector-unfold!)])
272+ (let ()
273+ (cond
274+ [(null? initial-seeds) (tabulate! f vec start end)]
275+ [(null? (cdr initial-seeds))
276+ (unfold1! f vec start end (car initial-seeds))]
277+ [else (unfold2+! f vec start end initial-seeds)]))))))
278+ (define (vector-unfold-right f len . initial-seeds)
279+ (define vec (make-vector len))
280+ (apply vector-unfold-right! f vec 0 len initial-seeds)
281+ vec)
282+ (define (vector-unfold-right! f vec start end .
283+ initial-seeds)
284+ (letrec ([tabulate! (lambda (f vec i)
285+ (cond
286+ [(>= i start)
287+ (vector-set! vec i (f i))
288+ (tabulate! f vec (- i 1))]))]
289+ [unfold1! (lambda (f vec i seed)
290+ (if (>= i start)
291+ (receive
292+ (elt new-seed)
293+ (f i seed)
294+ (vector-set! vec i elt)
295+ (unfold1! f vec (- i 1) new-seed))))]
296+ [unfold2+! (lambda (f vec i seeds)
297+ (if (>= i start)
298+ (receive
299+ (elt . new-seeds)
300+ (apply f i seeds)
301+ (vector-set! vec i elt)
302+ (unfold2+! f vec (- i 1) new-seeds))))])
303+ (let ([f (check-type procedure? f vector-unfold-right!)]
304+ [start (check-type nonneg-int? start vector-unfold-right!)]
305+ [end (check-type nonneg-int? end vector-unfold-right!)])
306+ (let ([i (- end 1)])
307+ (cond
308+ [(null? initial-seeds) (tabulate! f vec i)]
309+ [(null? (cdr initial-seeds))
310+ (unfold1! f vec i (car initial-seeds))]
311+ [else (unfold2+! f vec i initial-seeds)])))))
312+ (define (vector-copy vec . args)
313+ (let ([vec (check-type vector? vec vector-copy)])
314+ (receive
315+ (start end fill)
316+ (vector-copy:parse-args vec args)
317+ (let ([new-vector (make-vector (- end start) fill)])
318+ (%vector-copy! new-vector 0 vec start
319+ (if (> end (vector-length vec)) (vector-length vec) end))
320+ new-vector))))
321+ (define (vector-copy:parse-args vec args)
322+ (define (parse-args start end n fill)
323+ (let ([start (check-type nonneg-int? start vector-copy)]
324+ [end (check-type nonneg-int? end vector-copy)])
325+ (cond
326+ [(and (<= 0 start end) (<= start n))
327+ (values start end fill)]
328+ [else
329+ (error "illegal arguments"
330+ `(while calling ,vector-copy)
331+ `(start was ,start)
332+ `(end was ,end)
333+ `(vector was ,vec))])))
334+ (let ([n (vector-length vec)])
335+ (cond
336+ [(null? args) (parse-args 0 n n (unspecified-value))]
337+ [(null? (cdr args))
338+ (parse-args (car args) n n (unspecified-value))]
339+ [(null? (cddr args))
340+ (parse-args (car args) (cadr args) n (unspecified-value))]
341+ [(null? (cdddr args))
342+ (parse-args (car args) (cadr args) n (caddr args))]
343+ [else
344+ (error "too many arguments" vector-copy (cdddr args))])))
345+ (define (vector-reverse-copy vec . maybe-start+end)
346+ (let-vector-start+end vector-reverse-copy vec maybe-start+end (start end)
347+ (let ([new (make-vector (- end start))])
348+ (%vector-reverse-copy! new 0 vec start end)
349+ new)))
350+ (define (vector-append . vectors)
351+ (vector-concatenate:aux vectors vector-append))
352+ (define (vector-concatenate vector-list)
353+ (vector-concatenate:aux vector-list vector-concatenate))
354+ (define vector-concatenate:aux
355+ (letrec ([compute-length (lambda (vectors len callee)
356+ (if (null? vectors)
357+ len
358+ (let ([vec (check-type
359+ vector?
360+ (car vectors)
361+ callee)])
362+ (compute-length
363+ (cdr vectors)
364+ (+ (vector-length vec) len)
365+ callee))))]
366+ [concatenate! (lambda (vectors target to)
367+ (if (null? vectors)
368+ target
369+ (let* ([vec1 (car vectors)]
370+ [len (vector-length vec1)])
371+ (%vector-copy! target to vec1 0 len)
372+ (concatenate!
373+ (cdr vectors)
374+ target
375+ (+ to len)))))])
376+ (lambda (vectors callee)
377+ (cond
378+ [(null? vectors) (make-vector 0)]
379+ [(null? (cdr vectors))
380+ (let* ([vec (check-type vector? (car vectors) callee)]
381+ [len (vector-length vec)]
382+ [new (make-vector len)])
383+ (%vector-copy! new 0 vec 0 len)
384+ new)]
385+ [else
386+ (let ([new-vector (make-vector
387+ (compute-length vectors 0 callee))])
388+ (concatenate! vectors new-vector 0)
389+ new-vector)]))))
390+ (define (vector-append-subvectors . args)
391+ (define (gather-args args)
392+ (let loop ([args args] [vecs '()] [starts '()] [ends '()])
393+ (if (null? args)
394+ (values (reverse vecs) (reverse starts) (reverse ends))
395+ (loop
396+ (cdddr args)
397+ (cons (car args) vecs)
398+ (cons (cadr args) starts)
399+ (cons (caddr args) ends)))))
400+ (define (total-length starts ends)
401+ (let loop ([count 0] [starts starts] [ends ends])
402+ (if (null? starts)
403+ count
404+ (let ([start (car starts)] [end (car ends)])
405+ (loop (+ count (- end start)) (cdr starts) (cdr ends))))))
406+ (define (copy-each! result vecs starts ends)
407+ (let loop ([at 0] [vecs vecs] [starts starts] [ends ends])
408+ (if (null? vecs)
409+ result
410+ (let ([vec (car vecs)]
411+ [start (car starts)]
412+ [end (car ends)])
413+ (%vector-copy! result at vec start end)
414+ (loop
415+ (+ at (- end start))
416+ (cdr vecs)
417+ (cdr starts)
418+ (cdr ends))))))
419+ (receive
420+ (vecs starts ends)
421+ (gather-args args)
422+ (define result (make-vector (total-length starts ends)))
423+ (copy-each! result vecs starts ends)))
424+ (define (vector-empty? vec)
425+ (let ([vec (check-type vector? vec vector-empty?)])
426+ (zero? (vector-length vec))))
427+ (define (vector= elt=? . vectors)
428+ (let ([elt=? (check-type procedure? elt=? vector=)])
429+ (cond
430+ [(null? vectors) #t]
431+ [(null? (cdr vectors))
432+ (check-type vector? (car vectors) vector=)
433+ #t]
434+ [else
435+ (let loop ([vecs vectors])
436+ (let ([vec1 (check-type vector? (car vecs) vector=)]
437+ [vec2+ (cdr vecs)])
438+ (or (null? vec2+)
439+ (and (binary-vector= elt=? vec1 (car vec2+))
440+ (loop vec2+)))))])))
441+ (define (binary-vector= elt=? vector-a vector-b)
442+ (or (eq? vector-a vector-b)
443+ (let ([length-a (vector-length vector-a)]
444+ [length-b (vector-length vector-b)])
445+ (letrec ([loop (lambda (i)
446+ (or (= i length-a)
447+ (and (< i length-b)
448+ (test
449+ (vector-ref vector-a i)
450+ (vector-ref vector-b i)
451+ i))))]
452+ [test (lambda (elt-a elt-b i)
453+ (and (or (eq? elt-a elt-b)
454+ (elt=? elt-a elt-b))
455+ (loop (+ i 1))))])
456+ (and (= length-a length-b) (loop 0))))))
457+ (define (vector-fold kons knil vec . vectors)
458+ (let ([kons (check-type procedure? kons vector-fold)]
459+ [vec (check-type vector? vec vector-fold)])
460+ (if (null? vectors)
461+ (%vector-fold1 kons knil (vector-length vec) vec)
462+ (%vector-fold2+
463+ kons
464+ knil
465+ (%smallest-length vectors (vector-length vec) vector-fold)
466+ (cons vec vectors)))))
467+ (define vector-fold-right
468+ (letrec ([loop1 (lambda (kons knil vec i)
469+ (if (negative? i)
470+ knil
471+ (loop1
472+ kons
473+ (kons knil (vector-ref vec i))
474+ vec
475+ (- i 1))))]
476+ [loop2+ (lambda (kons knil vectors i)
477+ (if (negative? i)
478+ knil
479+ (loop2+
480+ kons
481+ (apply kons knil (vectors-ref vectors i))
482+ vectors
483+ (- i 1))))])
484+ (lambda (kons knil vec . vectors)
485+ (let ([kons (check-type procedure? kons vector-fold-right)]
486+ [vec (check-type vector? vec vector-fold-right)])
487+ (if (null? vectors)
488+ (loop1 kons knil vec (- (vector-length vec) 1))
489+ (loop2+
490+ kons
491+ knil
492+ (cons vec vectors)
493+ (- (%smallest-length
494+ vectors
495+ (vector-length vec)
496+ vector-fold-right)
497+ 1)))))))
498+ (define (vector-map! f vec . vectors)
499+ (let ([f (check-type procedure? f vector-map!)]
500+ [vec (check-type vector? vec vector-map!)])
501+ (if (null? vectors)
502+ (%vector-map1! f vec vec (vector-length vec))
503+ (%vector-map2+!
504+ f
505+ vec
506+ (cons vec vectors)
507+ (%smallest-length vectors (vector-length vec) vector-map!)))
508+ (unspecified-value)))
509+ (define (vector-count pred? vec . vectors)
510+ (let ([pred? (check-type procedure? pred? vector-count)]
511+ [vec (check-type vector? vec vector-count)])
512+ (if (null? vectors)
513+ (%vector-fold1
514+ (lambda (count elt) (if (pred? elt) (+ count 1) count))
515+ 0
516+ (vector-length vec)
517+ vec)
518+ (%vector-fold2+
519+ (lambda (count . elts)
520+ (if (apply pred? elts) (+ count 1) count))
521+ 0
522+ (%smallest-length vectors (vector-length vec) vector-count)
523+ (cons vec vectors)))))
524+ (define (vector-cumulate f vec knil)
525+ (let* ([len (vector-length vec)] [result (make-vector len)])
526+ (let loop ([i 0] [left knil])
527+ (if (= i len)
528+ result
529+ (let* ([right (vector-ref vec i)] [r (f left right)])
530+ (vector-set! result i r)
531+ (loop (+ i 1) r))))))
532+ (define (vector-index pred? vec . vectors)
533+ (vector-index/skip pred? vec vectors vector-index))
534+ (define (vector-skip pred? vec . vectors)
535+ (vector-index/skip
536+ (lambda elts (not (apply pred? elts)))
537+ vec
538+ vectors
539+ vector-skip))
540+ (define vector-index/skip
541+ (letrec ([loop1 (lambda (pred? vec len i)
542+ (cond
543+ [(= i len) #f]
544+ [(pred? (vector-ref vec i)) i]
545+ [else (loop1 pred? vec len (+ i 1))]))]
546+ [loop2+ (lambda (pred? vectors len i)
547+ (cond
548+ [(= i len) #f]
549+ [(apply pred? (vectors-ref vectors i)) i]
550+ [else (loop2+ pred? vectors len (+ i 1))]))])
551+ (lambda (pred? vec vectors callee)
552+ (let ([pred? (check-type procedure? pred? callee)]
553+ [vec (check-type vector? vec callee)])
554+ (if (null? vectors)
555+ (loop1 pred? vec (vector-length vec) 0)
556+ (loop2+
557+ pred?
558+ (cons vec vectors)
559+ (%smallest-length vectors (vector-length vec) callee)
560+ 0))))))
561+ (define (vector-index-right pred? vec . vectors)
562+ (vector-index/skip-right
563+ pred?
564+ vec
565+ vectors
566+ vector-index-right))
567+ (define (vector-skip-right pred? vec . vectors)
568+ (vector-index/skip-right
569+ (lambda elts (not (apply pred? elts)))
570+ vec
571+ vectors
572+ vector-index-right))
573+ (define vector-index/skip-right
574+ (letrec ([loop1 (lambda (pred? vec i)
575+ (cond
576+ [(negative? i) #f]
577+ [(pred? (vector-ref vec i)) i]
578+ [else (loop1 pred? vec (- i 1))]))]
579+ [loop2+ (lambda (pred? vectors i)
580+ (cond
581+ [(negative? i) #f]
582+ [(apply pred? (vectors-ref vectors i)) i]
583+ [else (loop2+ pred? vectors (- i 1))]))])
584+ (lambda (pred? vec vectors callee)
585+ (let ([pred? (check-type procedure? pred? callee)]
586+ [vec (check-type vector? vec callee)])
587+ (if (null? vectors)
588+ (loop1 pred? vec (- (vector-length vec) 1))
589+ (loop2+
590+ pred?
591+ (cons vec vectors)
592+ (- (%smallest-length vectors (vector-length vec) callee)
593+ 1)))))))
594+ (define (vector-binary-search vec value cmp .
595+ maybe-start+end)
596+ (let ([cmp (check-type
597+ procedure?
598+ cmp
599+ vector-binary-search)])
600+ (let-vector-start+end vector-binary-search vec maybe-start+end (start end)
601+ (let loop ([start start] [end end] [j #f])
602+ (let ([i (div (+ start end) 2)])
603+ (if (or (= start end) (and j (= i j)))
604+ #f
605+ (let ([comparison (check-type
606+ integer?
607+ (cmp (vector-ref vec i) value)
608+ `(,cmp for ,vector-binary-search))])
609+ (cond
610+ [(zero? comparison) i]
611+ [(positive? comparison) (loop start i i)]
612+ [else (loop i end i)]))))))))
613+ (define vector-any
614+ (letrec ([loop1 (lambda (pred? vec i len len-1)
615+ (and (not (= i len))
616+ (if (= i len-1)
617+ (pred? (vector-ref vec i))
618+ (or (pred? (vector-ref vec i))
619+ (loop1 pred? vec (+ i 1) len
620+ len-1)))))]
621+ [loop2+ (lambda (pred? vectors i len len-1)
622+ (and (not (= i len))
623+ (if (= i len-1)
624+ (apply pred? (vectors-ref vectors i))
625+ (or (apply pred? (vectors-ref vectors i))
626+ (loop2+ pred? vectors (+ i 1) len
627+ len-1)))))])
628+ (lambda (pred? vec . vectors)
629+ (let ([pred? (check-type procedure? pred? vector-any)]
630+ [vec (check-type vector? vec vector-any)])
631+ (if (null? vectors)
632+ (let ([len (vector-length vec)])
633+ (loop1 pred? vec 0 len (- len 1)))
634+ (let ([len (%smallest-length
635+ vectors
636+ (vector-length vec)
637+ vector-any)])
638+ (loop2+ pred? (cons vec vectors) 0 len (- len 1))))))))
639+ (define vector-every
640+ (letrec ([loop1 (lambda (pred? vec i len len-1)
641+ (or (= i len)
642+ (if (= i len-1)
643+ (pred? (vector-ref vec i))
644+ (and (pred? (vector-ref vec i))
645+ (loop1 pred? vec (+ i 1) len
646+ len-1)))))]
647+ [loop2+ (lambda (pred? vectors i len len-1)
648+ (or (= i len)
649+ (if (= i len-1)
650+ (apply pred? (vectors-ref vectors i))
651+ (and (apply pred? (vectors-ref vectors i))
652+ (loop2+ pred? vectors (+ i 1) len
653+ len-1)))))])
654+ (lambda (pred? vec . vectors)
655+ (let ([pred? (check-type procedure? pred? vector-every)]
656+ [vec (check-type vector? vec vector-every)])
657+ (if (null? vectors)
658+ (let ([len (vector-length vec)])
659+ (loop1 pred? vec 0 len (- len 1)))
660+ (let ([len (%smallest-length
661+ vectors
662+ (vector-length vec)
663+ vector-every)])
664+ (loop2+ pred? (cons vec vectors) 0 len (- len 1))))))))
665+ (define (vector-partition pred? vec)
666+ (let* ([len (vector-length vec)]
667+ [cnt (vector-count pred? vec)]
668+ [result (make-vector len)])
669+ (let loop ([i 0] [yes 0] [no cnt])
670+ (if (= i len)
671+ (values result cnt)
672+ (let ([elem (vector-ref vec i)])
673+ (if (pred? elem)
674+ (begin
675+ (vector-set! result yes elem)
676+ (loop (+ i 1) (+ yes 1) no))
677+ (begin
678+ (vector-set! result no elem)
679+ (loop (+ i 1) yes (+ no 1)))))))))
680+ (define (vector-swap! vec i j)
681+ (let ([vec (check-type vector? vec vector-swap!)])
682+ (let ([i (check-index vec i vector-swap!)]
683+ [j (check-index vec j vector-swap!)])
684+ (let ([x (vector-ref vec i)])
685+ (vector-set! vec i (vector-ref vec j))
686+ (vector-set! vec j x)))))
687+ (define $check-types
688+ (case-lambda
689+ [(who v start)
690+ (check-type vector? v who)
691+ (check-indices v start 'start (vector-length v) 'end who)]
692+ [(who v start end)
693+ (check-type vector? v who)
694+ (check-indices v start 'start end 'end who)]))
695+ (define vector-fill!
696+ (let ()
697+ (define $vector-fill!
698+ (lambda (vec value start end)
699+ (do ([i start (+ i 1)])
700+ ((= i end))
701+ (vector-set! vec i value))))
702+ (case-lambda
703+ [(vec value) (rnrs:vector-fill! vec value)]
704+ [(vec value start)
705+ ($check-types 'vector-fill! vec start)
706+ ($vector-fill! vec value start (vector-length vec))]
707+ [(vec value start end)
708+ ($check-types 'vector-fill! vec start end)
709+ ($vector-fill! vec value start end)])))
710+ (define (vector-copy! target tstart source .
711+ maybe-sstart+send)
712+ (define (doit! sstart send source-length)
713+ (let ([tstart (check-type nonneg-int? tstart vector-copy!)]
714+ [sstart (check-type nonneg-int? sstart vector-copy!)]
715+ [send (check-type nonneg-int? send vector-copy!)])
716+ (cond
717+ [(and (<= 0 sstart send source-length)
718+ (<= (+ tstart (- send sstart)) (vector-length target)))
719+ (%vector-copy! target tstart source sstart send)]
720+ [else
721+ (error "illegal arguments"
722+ `(while calling ,vector-copy!)
723+ `(target was ,target)
724+ `(target-length was ,(vector-length target))
725+ `(tstart was ,tstart)
726+ `(source was ,source)
727+ `(source-length was ,source-length)
728+ `(sstart was ,sstart)
729+ `(send was ,send))])))
730+ (let ([n (vector-length source)])
731+ (cond
732+ [(null? maybe-sstart+send) (doit! 0 n n)]
733+ [(null? (cdr maybe-sstart+send))
734+ (doit! (car maybe-sstart+send) n n)]
735+ [(null? (cddr maybe-sstart+send))
736+ (doit! (car maybe-sstart+send) (cadr maybe-sstart+send) n)]
737+ [else
738+ (error "too many arguments"
739+ vector-copy!
740+ (cddr maybe-sstart+send))])))
741+ (define (vector-reverse-copy! target tstart source .
742+ maybe-sstart+send)
743+ (define (doit! sstart send source-length)
744+ (let ([tstart (check-type
745+ nonneg-int?
746+ tstart
747+ vector-reverse-copy!)]
748+ [sstart (check-type
749+ nonneg-int?
750+ sstart
751+ vector-reverse-copy!)]
752+ [send (check-type nonneg-int? send vector-reverse-copy!)])
753+ (cond
754+ [(and (eq? target source)
755+ (or (between? sstart tstart send)
756+ (between? tstart sstart (+ tstart (- send sstart)))))
757+ (error "vector range for self-copying overlaps"
758+ vector-reverse-copy!
759+ `(vector was ,target)
760+ `(tstart was ,tstart)
761+ `(sstart was ,sstart)
762+ `(send was ,send))]
763+ [(and (<= 0 sstart send source-length)
764+ (<= (+ tstart (- send sstart)) (vector-length target)))
765+ (%vector-reverse-copy! target tstart source sstart send)]
766+ [else
767+ (error "illegal arguments"
768+ `(while calling ,vector-reverse-copy!)
769+ `(target was ,target)
770+ `(target-length was ,(vector-length target))
771+ `(tstart was ,tstart)
772+ `(source was ,source)
773+ `(source-length was ,source-length)
774+ `(sstart was ,sstart)
775+ `(send was ,send))])))
776+ (let ([n (vector-length source)])
777+ (cond
778+ [(null? maybe-sstart+send) (doit! 0 n n)]
779+ [(null? (cdr maybe-sstart+send))
780+ (doit! (car maybe-sstart+send) n n)]
781+ [(null? (cddr maybe-sstart+send))
782+ (doit! (car maybe-sstart+send) (cadr maybe-sstart+send) n)]
783+ [else
784+ (error "too many arguments"
785+ vector-reverse-copy!
786+ (cddr maybe-sstart+send))])))
787+ (define (vector-reverse! vec . start+end)
788+ (let-vector-start+end vector-reverse! vec start+end
789+ (start end) (%vector-reverse! vec start end)))
790+ (define vector->list
791+ (let ()
792+ (define ($vector->list vec start end)
793+ (do ([i (- end 1) (- i 1)]
794+ [result '() (cons (vector-ref vec i) result)])
795+ ((< i start) result)))
796+ (case-lambda
797+ [(vec) (rnrs:vector->list vec)]
798+ [(vec start)
799+ ($check-types 'vector->list vec start)
800+ ($vector->list vec start (vector-length vec))]
801+ [(vec start end)
802+ ($check-types 'vector->list vec start end)
803+ ($vector->list vec start (vector-length vec))])))
804+ (define (reverse-vector->list vec . maybe-start+end)
805+ (let-vector-start+end reverse-vector->list vec maybe-start+end (start end)
806+ (do ([i start (+ i 1)]
807+ [result '() (cons (vector-ref vec i) result)])
808+ ((= i end) result))))
809+ (define list->vector
810+ (case-lambda
811+ [(lst) (rnrs:list->vector lst)]
812+ [(lst start)
813+ (check-type nonneg-int? start list->vector)
814+ (rnrs:list->vector (list-tail lst start))]
815+ [(lst start end)
816+ (check-type nonneg-int? start list->vector)
817+ (check-type nonneg-int? end list->vector)
818+ (unless (<= start end)
819+ (error 'list->vector "start is greater than end" start end))
820+ (let ([len (- end start)])
821+ (let ([v (make-vector len)])
822+ (let loop ([i 0] [ls (list-tail lst start)])
823+ (unless (= i len)
824+ (unless (pair? ls)
825+ (if (null? ls)
826+ (error 'list->vector "list too short" lst start end)
827+ (error 'list->vector "improper list" lst)))
828+ (vector-set! v i (car ls))
829+ (loop (fx+ i 1) (cdr ls))))
830+ v))]))
831+ (define (reverse-list->vector lst . maybe-start+end)
832+ (let*-optionals
833+ maybe-start+end
834+ ((start 0) (end (length lst)))
835+ (let ([start (check-type
836+ nonneg-int?
837+ start
838+ reverse-list->vector)]
839+ [end (check-type nonneg-int? end reverse-list->vector)])
840+ ((lambda (f)
841+ (vector-unfold-right f (- end start) (list-tail lst start)))
842+ (lambda (index l)
843+ (cond
844+ [(null? l)
845+ (error "list too short"
846+ `(list was ,lst)
847+ `(attempted end was ,end)
848+ `(while calling ,reverse-list->vector))]
849+ [(pair? l) (values (car l) (cdr l))]
850+ [else
851+ (error "erroneous value"
852+ (list list? lst)
853+ `(while calling ,reverse-list->vector))]))))))
854+ (define (vector->string vec . maybe-start+end)
855+ (let* ([len (vector-length vec)]
856+ [start (if (null? maybe-start+end) 0 (car maybe-start+end))]
857+ [end (if (null? maybe-start+end)
858+ len
859+ (if (null? (cdr maybe-start+end))
860+ len
861+ (cadr maybe-start+end)))]
862+ [size (- end start)])
863+ (define result (make-string size))
864+ (let loop ([at 0] [i start])
865+ (if (= i end)
866+ result
867+ (begin
868+ (string-set! result at (vector-ref vec i))
869+ (loop (+ at 1) (+ i 1)))))))
870+ (define (string->vector str . maybe-start+end)
871+ (let* ([len (string-length str)]
872+ [start (if (null? maybe-start+end) 0 (car maybe-start+end))]
873+ [end (if (null? maybe-start+end)
874+ len
875+ (if (null? (cdr maybe-start+end))
876+ len
877+ (cadr maybe-start+end)))]
878+ [size (- end start)])
879+ (define result (make-vector size))
880+ (let loop ([at 0] [i start])
881+ (if (= i end)
882+ result
883+ (begin
884+ (vector-set! result at (string-ref str i))
885+ (loop (+ at 1) (+ i 1)))))))))
vendor/purs/runtime/srfi/:133/vectors.sls3a132.slsnew file+6
@@ -0,0 +1,6 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a133/vectors.sls3a132.sls
vendor/purs/runtime/srfi/:158.slsnew file+25
@@ -0,0 +1,25 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a158.sls
7+(library (purs runtime srfi :158)
8+ (export generator circular-generator make-iota-generator
9+ make-range-generator make-coroutine-generator
10+ list->generator vector->generator reverse-vector->generator
11+ string->generator bytevector->generator
12+ make-for-each-generator make-unfold-generator gcons* gappend
13+ gflatten ggroup gmerge gmap gcombine gfilter gremove
14+ gstate-filter gtake gdrop gtake-while gdrop-while gdelete
15+ gdelete-neighbor-dups gindex gselect generator->list
16+ generator->reverse-list generator->vector generator->vector!
17+ generator->string generator-fold generator-for-each
18+ generator-map->list generator-find generator-count
19+ generator-any generator-every generator-unfold
20+ make-accumulator count-accumulator list-accumulator
21+ reverse-list-accumulator vector-accumulator
22+ reverse-vector-accumulator vector-accumulator!
23+ string-accumulator bytevector-accumulator
24+ bytevector-accumulator! sum-accumulator product-accumulator)
25+ (import (purs runtime srfi :158 generators-and-accumulators)))
vendor/purs/runtime/srfi/:158/generators-and-accumulators.slsnew file+457
@@ -0,0 +1,457 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a158/generators-and-accumulators.sls
7+;;;;;; File header: %3a158/srfi-158-impl.scm
8+;; reference implementation from: https://github.com/scheme-requests-for-implementation/srfi-158
9+(library (purs runtime srfi :158 generators-and-accumulators)
10+ (export generator circular-generator make-iota-generator
11+ make-range-generator make-coroutine-generator
12+ list->generator vector->generator reverse-vector->generator
13+ string->generator bytevector->generator
14+ make-for-each-generator make-unfold-generator gcons* gappend
15+ gflatten ggroup gmerge gmap gcombine gfilter gremove
16+ gstate-filter gtake gdrop gtake-while gdrop-while gdelete
17+ gdelete-neighbor-dups gindex gselect generator->list
18+ generator->reverse-list generator->vector generator->vector!
19+ generator->string generator-fold generator-for-each
20+ generator-map->list generator-find generator-count
21+ generator-any generator-every generator-unfold
22+ make-accumulator count-accumulator list-accumulator
23+ reverse-list-accumulator vector-accumulator
24+ reverse-vector-accumulator vector-accumulator!
25+ string-accumulator bytevector-accumulator
26+ bytevector-accumulator! sum-accumulator product-accumulator)
27+ (import (rnrs) (only (purs runtime srfi :1) make-list)
28+ (only (chezscheme) call/1cc) (purs runtime srfi private include)
29+ (purs runtime srfi private define-values))
30+ (begin
31+ (define (any pred ls)
32+ (if (null? (cdr ls))
33+ (pred (car ls))
34+ ((lambda (x) (if x x (any pred (cdr ls))))
35+ (pred (car ls)))))
36+ (define (list->bytevector list)
37+ (let ([vec (make-bytevector (length list) 0)])
38+ (let loop ([i 0] [list list])
39+ (if (null? list)
40+ vec
41+ (begin
42+ (bytevector-u8-set! vec i (car list))
43+ (loop (+ i 1) (cdr list)))))))
44+ (define (generator . args)
45+ (lambda ()
46+ (if (null? args)
47+ (eof-object)
48+ (let ([next (car args)]) (set! args (cdr args)) next))))
49+ (define (circular-generator . args)
50+ (let ([base-args args])
51+ (lambda ()
52+ (when (null? args) (set! args base-args))
53+ (let ([next (car args)]) (set! args (cdr args)) next))))
54+ (define make-iota-generator
55+ (case-lambda
56+ [(count) (make-iota-generator count 0 1)]
57+ [(count start) (make-iota-generator count start 1)]
58+ [(count start step) (make-iota count start step)]))
59+ (define (make-iota count start step)
60+ (lambda ()
61+ (cond
62+ [(<= count 0) (eof-object)]
63+ [else
64+ (let ([result start])
65+ (set! count (- count 1))
66+ (set! start (+ start step))
67+ result)])))
68+ (define make-range-generator
69+ (case-lambda
70+ [(start end) (make-range-generator start end 1)]
71+ [(start) (make-infinite-range-generator start)]
72+ [(start end step)
73+ (set! start (- (+ start step) step))
74+ (lambda ()
75+ (if (< start end)
76+ (let ([v start]) (set! start (+ start step)) v)
77+ (eof-object)))]))
78+ (define (make-infinite-range-generator start)
79+ (lambda ()
80+ (let ([result start]) (set! start (+ start 1)) result)))
81+ (define (make-coroutine-generator proc)
82+ (define return #f)
83+ (define resume #f)
84+ (define yield
85+ (lambda (v)
86+ (call/cc (lambda (r) (set! resume r) (return v)))))
87+ (lambda ()
88+ (call/1cc
89+ (lambda (cc)
90+ (set! return cc)
91+ (if resume
92+ (resume (if #f #f))
93+ (begin
94+ (proc yield)
95+ (set! resume (lambda (v) (return (eof-object))))
96+ (return (eof-object))))))))
97+ (define (list->generator lst)
98+ (lambda ()
99+ (if (null? lst)
100+ (eof-object)
101+ (let ([next (car lst)]) (set! lst (cdr lst)) next))))
102+ (define vector->generator
103+ (case-lambda
104+ [(vec) (vector->generator vec 0 (vector-length vec))]
105+ [(vec start)
106+ (vector->generator vec start (vector-length vec))]
107+ [(vec start end)
108+ (lambda ()
109+ (if (>= start end)
110+ (eof-object)
111+ (let ([next (vector-ref vec start)])
112+ (set! start (+ start 1))
113+ next)))]))
114+ (define reverse-vector->generator
115+ (case-lambda
116+ [(vec)
117+ (reverse-vector->generator vec 0 (vector-length vec))]
118+ [(vec start)
119+ (reverse-vector->generator vec start (vector-length vec))]
120+ [(vec start end)
121+ (lambda ()
122+ (if (>= start end)
123+ (eof-object)
124+ (let ([next (vector-ref vec (- end 1))])
125+ (set! end (- end 1))
126+ next)))]))
127+ (define string->generator
128+ (case-lambda
129+ [(str) (string->generator str 0 (string-length str))]
130+ [(str start)
131+ (string->generator str start (string-length str))]
132+ [(str start end)
133+ (lambda ()
134+ (if (>= start end)
135+ (eof-object)
136+ (let ([next (string-ref str start)])
137+ (set! start (+ start 1))
138+ next)))]))
139+ (define bytevector->generator
140+ (case-lambda
141+ [(str)
142+ (bytevector->generator str 0 (bytevector-length str))]
143+ [(str start)
144+ (bytevector->generator str start (bytevector-length str))]
145+ [(str start end)
146+ (lambda ()
147+ (if (>= start end)
148+ (eof-object)
149+ (let ([next (bytevector-u8-ref str start)])
150+ (set! start (+ start 1))
151+ next)))]))
152+ (define (make-for-each-generator for-each obj)
153+ (make-coroutine-generator
154+ (lambda (yield) (for-each yield obj))))
155+ (define (make-unfold-generator stop? mapper successor seed)
156+ (make-coroutine-generator
157+ (lambda (yield)
158+ (let loop ([s seed])
159+ (if (stop? s)
160+ (if #f #f)
161+ (begin (yield (mapper s)) (loop (successor s))))))))
162+ (define (gcons* . args)
163+ (lambda ()
164+ (if (null? args)
165+ (eof-object)
166+ (if (= (length args) 1)
167+ ((car args))
168+ (let ([v (car args)]) (set! args (cdr args)) v)))))
169+ (define (gappend . args)
170+ (lambda ()
171+ (if (null? args)
172+ (eof-object)
173+ (let loop ([v ((car args))])
174+ (if (eof-object? v)
175+ (begin
176+ (set! args (cdr args))
177+ (if (null? args) (eof-object) (loop ((car args)))))
178+ v)))))
179+ (define (gflatten gen)
180+ (let ([state '()])
181+ (lambda ()
182+ (if (null? state) (set! state (gen)))
183+ (if (eof-object? state)
184+ state
185+ (let ([obj (car state)]) (set! state (cdr state)) obj)))))
186+ (define ggroup
187+ (case-lambda
188+ [(gen k) (simple-ggroup gen k)]
189+ [(gen k padding)
190+ (padded-ggroup (simple-ggroup gen k) k padding)]))
191+ (define (simple-ggroup gen k)
192+ (lambda ()
193+ (let loop ([item (gen)] [result '()] [count (- k 1)])
194+ (if (eof-object? item)
195+ (if (null? result) item (reverse result))
196+ (if (= count 0)
197+ (reverse (cons item result))
198+ (loop (gen) (cons item result) (- count 1)))))))
199+ (define (padded-ggroup gen k padding)
200+ (lambda ()
201+ (let ([item (gen)])
202+ (if (eof-object? item)
203+ item
204+ (let ([len (length item)])
205+ (if (= len k)
206+ item
207+ (append item (make-list (- k len) padding))))))))
208+ (define gmerge
209+ (case-lambda
210+ [(<) (error #f "wrong number of arguments for gmerge")]
211+ [(< gen) gen]
212+ [(< genleft genright)
213+ (let ([left (genleft)] [right (genright)])
214+ (lambda ()
215+ (cond
216+ [(and (eof-object? left) (eof-object? right)) left]
217+ [(eof-object? left)
218+ (let ([obj right]) (set! right (genright)) obj)]
219+ [(eof-object? right)
220+ (let ([obj left]) (set! left (genleft)) obj)]
221+ [(< right left)
222+ (let ([obj right]) (set! right (genright)) obj)]
223+ [else (let ([obj left]) (set! left (genleft)) obj)])))]
224+ [(< . gens)
225+ (apply
226+ gmerge
227+ <
228+ (let loop ([gens gens] [gs '()])
229+ (cond
230+ [(null? gens) (reverse gs)]
231+ [(null? (cdr gens)) (reverse (cons (car gens) gs))]
232+ [else
233+ (loop
234+ (cddr gens)
235+ (cons (gmerge < (car gens) (cadr gens)) gs))])))]))
236+ (define gmap
237+ (case-lambda
238+ [(proc) (error #f "wrong number of arguments for gmap")]
239+ [(proc gen)
240+ (lambda ()
241+ (let ([item (gen)])
242+ (if (eof-object? item) item (proc item))))]
243+ [(proc . gens)
244+ (lambda ()
245+ (let ([items (map (lambda (x) (x)) gens)])
246+ (if (any eof-object? items)
247+ (eof-object)
248+ (apply proc items))))]))
249+ (define (gcombine proc seed . gens)
250+ (lambda ()
251+ (define items (map (lambda (x) (x)) gens))
252+ (if (any eof-object? items)
253+ (eof-object)
254+ (let ()
255+ (define-values (value newseed)
256+ (apply proc (append items (list seed))))
257+ (set! seed newseed)
258+ value))))
259+ (define (gfilter pred gen)
260+ (lambda ()
261+ (let loop ()
262+ (let ([next (gen)])
263+ (if (or (eof-object? next) (pred next)) next (loop))))))
264+ (define (gstate-filter proc seed gen)
265+ (let ([state seed])
266+ (lambda ()
267+ (let loop ([item (gen)])
268+ (if (eof-object? item)
269+ item
270+ (let-values ([(yes newstate) (proc item state)])
271+ (set! state newstate)
272+ (if yes item (loop (gen)))))))))
273+ (define (gremove pred gen)
274+ (gfilter (lambda (v) (not (pred v))) gen))
275+ (define gtake
276+ (case-lambda
277+ [(gen k) (gtake gen k (eof-object))]
278+ [(gen k padding)
279+ (define (%gtake gen k)
280+ (lambda ()
281+ (if (zero? k) (eof-object) (begin (set! k (- k 1)) (gen)))))
282+ (%gtake (gappend gen (lambda () padding)) k)]))
283+ (define (gdrop gen k)
284+ (lambda () (do () ((<= k 0)) (set! k (- k 1)) (gen)) (gen)))
285+ (define (gdrop-while pred gen)
286+ (define found #f)
287+ (lambda ()
288+ (let loop ()
289+ (let ([val (gen)])
290+ (cond
291+ [found val]
292+ [(and (not (eof-object? val)) (pred val)) (loop)]
293+ [else (set! found #t) val])))))
294+ (define (gtake-while pred gen)
295+ (lambda ()
296+ (let ([next (gen)])
297+ (if (eof-object? next)
298+ next
299+ (if (pred next)
300+ next
301+ (begin (set! gen (generator)) (gen)))))))
302+ (define gdelete
303+ (case-lambda
304+ [(item gen) (gdelete item gen equal?)]
305+ [(item gen ==)
306+ (lambda ()
307+ (let loop ([v (gen)])
308+ (cond
309+ [(eof-object? v) (eof-object)]
310+ [(== item v) (loop (gen))]
311+ [else v])))]))
312+ (define gdelete-neighbor-dups
313+ (case-lambda
314+ [(gen) (gdelete-neighbor-dups gen equal?)]
315+ [(gen ==)
316+ (define firsttime #t)
317+ (define prev #f)
318+ (lambda ()
319+ (if firsttime
320+ (begin (set! firsttime #f) (set! prev (gen)) prev)
321+ (let loop ([v (gen)])
322+ (cond
323+ [(eof-object? v) v]
324+ [(== prev v) (loop (gen))]
325+ [else (set! prev v) v]))))]))
326+ (define (gindex value-gen index-gen)
327+ (let ([done? #f] [count 0])
328+ (lambda ()
329+ (if done?
330+ (eof-object)
331+ (let loop ([value (value-gen)] [index (index-gen)])
332+ (cond
333+ [(or (eof-object? value) (eof-object? index))
334+ (set! done? #t)
335+ (eof-object)]
336+ [(= index count) (set! count (+ count 1)) value]
337+ [else
338+ (set! count (+ count 1))
339+ (loop (value-gen) index)]))))))
340+ (define (gselect value-gen truth-gen)
341+ (let ([done? #f])
342+ (lambda ()
343+ (if done?
344+ (eof-object)
345+ (let loop ([value (value-gen)] [truth (truth-gen)])
346+ (cond
347+ [(or (eof-object? value) (eof-object? truth))
348+ (set! done? #t)
349+ (eof-object)]
350+ [truth value]
351+ [else (loop (value-gen) (truth-gen))]))))))
352+ (define generator->list
353+ (case-lambda
354+ [(gen n) (generator->list (gtake gen n))]
355+ [(gen) (reverse (generator->reverse-list gen))]))
356+ (define generator->reverse-list
357+ (case-lambda
358+ [(gen n) (generator->reverse-list (gtake gen n))]
359+ [(gen) (generator-fold cons '() gen)]))
360+ (define generator->vector
361+ (case-lambda
362+ [(gen) (list->vector (generator->list gen))]
363+ [(gen n) (list->vector (generator->list gen n))]))
364+ (define (generator->vector! vector at gen)
365+ (let loop ([value (gen)] [count 0] [at at])
366+ (cond
367+ [(eof-object? value) count]
368+ [(>= at (vector-length vector)) count]
369+ [else
370+ (begin
371+ (vector-set! vector at value)
372+ (loop (gen) (+ count 1) (+ at 1)))])))
373+ (define generator->string
374+ (case-lambda
375+ [(gen) (list->string (generator->list gen))]
376+ [(gen n) (list->string (generator->list gen n))]))
377+ (define (generator-fold f seed . gs)
378+ (define (inner-fold seed)
379+ (let ([vs (map (lambda (g) (g)) gs)])
380+ (if (any eof-object? vs)
381+ seed
382+ (inner-fold (apply f (append vs (list seed)))))))
383+ (inner-fold seed))
384+ (define (generator-for-each f . gs)
385+ (let loop ()
386+ (let ([vs (map (lambda (g) (g)) gs)])
387+ (if (any eof-object? vs)
388+ (if #f #f)
389+ (begin (apply f vs) (loop))))))
390+ (define (generator-map->list f . gs)
391+ (let loop ([result '()])
392+ (let ([vs (map (lambda (g) (g)) gs)])
393+ (if (any eof-object? vs)
394+ (reverse result)
395+ (loop (cons (apply f vs) result))))))
396+ (define (generator-find pred g)
397+ (let loop ([v (g)])
398+ (if (or (pred v) (eof-object? v)) v (loop (g)))))
399+ (define (generator-count pred g)
400+ (generator-fold (lambda (v n) (if (pred v) (+ 1 n) n)) 0 g))
401+ (define (generator-any pred g)
402+ (let loop ([v (g)])
403+ (if (eof-object? v) #f (if (pred v) #t (loop (g))))))
404+ (define (generator-every pred g)
405+ (let loop ([v (g)])
406+ (if (eof-object? v) #t (if (pred v) (loop (g)) #f))))
407+ (define (generator-unfold g unfold . args)
408+ (apply unfold eof-object? (lambda (x) x) (lambda (x) (g))
409+ (g) args))
410+ (define (make-accumulator kons knil finalize)
411+ (let ([state knil])
412+ (lambda (obj)
413+ (if (eof-object? obj)
414+ (finalize state)
415+ (set! state (kons obj state))))))
416+ (define (count-accumulator)
417+ (make-accumulator
418+ (lambda (obj state) (+ 1 state))
419+ 0
420+ (lambda (x) x)))
421+ (define (list-accumulator)
422+ (make-accumulator cons '() reverse))
423+ (define (reverse-list-accumulator)
424+ (make-accumulator cons '() (lambda (x) x)))
425+ (define (vector-accumulator)
426+ (make-accumulator
427+ cons
428+ '()
429+ (lambda (x) (list->vector (reverse x)))))
430+ (define (reverse-vector-accumulator)
431+ (make-accumulator cons '() list->vector))
432+ (define (vector-accumulator! vec at)
433+ (lambda (obj)
434+ (if (eof-object? obj)
435+ vec
436+ (begin (vector-set! vec at obj) (set! at (+ at 1))))))
437+ (define (bytevector-accumulator)
438+ (make-accumulator
439+ cons
440+ '()
441+ (lambda (x) (list->bytevector (reverse x)))))
442+ (define (bytevector-accumulator! bytevec at)
443+ (lambda (obj)
444+ (if (eof-object? obj)
445+ bytevec
446+ (begin
447+ (bytevector-u8-set! bytevec at obj)
448+ (set! at (+ at 1))))))
449+ (define (string-accumulator)
450+ (make-accumulator
451+ cons
452+ '()
453+ (lambda (lst) (list->string (reverse lst)))))
454+ (define (sum-accumulator)
455+ (make-accumulator + 0 (lambda (x) x)))
456+ (define (product-accumulator)
457+ (make-accumulator * 1 (lambda (x) x)))))
vendor/purs/runtime/srfi/:214.slsnew file+35
@@ -0,0 +1,35 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a214.sls
7+#!r6rs
8+(library (purs runtime srfi :214)
9+ (export make-flexvector flexvector flexvector-unfold
10+ flexvector-unfold-right flexvector-copy
11+ flexvector-reverse-copy flexvector-append
12+ flexvector-concatenate flexvector-append-subvectors
13+ flexvector? flexvector-empty? flexvector=? flexvector-ref
14+ flexvector-front flexvector-back flexvector-length
15+ flexvector-add! flexvector-add-front! flexvector-add-back!
16+ flexvector-remove! flexvector-remove-front!
17+ flexvector-remove-back! flexvector-add-all!
18+ flexvector-remove-range! flexvector-clear! flexvector-set!
19+ flexvector-swap! flexvector-fill! flexvector-reverse!
20+ flexvector-copy! flexvector-reverse-copy! flexvector-append!
21+ flexvector-fold flexvector-fold-right flexvector-map
22+ flexvector-map! flexvector-map/index flexvector-map/index!
23+ flexvector-append-map flexvector-append-map/index
24+ flexvector-filter flexvector-filter! flexvector-filter/index
25+ flexvector-filter/index! flexvector-for-each
26+ flexvector-for-each/index flexvector-count
27+ flexvector-cumulate flexvector-index flexvector-index-right
28+ flexvector-skip flexvector-skip-right
29+ flexvector-binary-search flexvector-any flexvector-every
30+ flexvector-partition flexvector->vector flexvector->list
31+ flexvector->string vector->flexvector list->flexvector
32+ string->flexvector reverse-flexvector->list
33+ reverse-list->flexvector generator->flexvector
34+ flexvector->generator)
35+ (import (purs runtime srfi :214 impl)))
vendor/purs/runtime/srfi/:214/impl.slsnew file+546
@@ -0,0 +1,546 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a214/impl.sls
7+#!r6rs
8+(library (purs runtime srfi :214 impl)
9+ (export make-flexvector flexvector flexvector-unfold
10+ flexvector-unfold-right flexvector-copy
11+ flexvector-reverse-copy flexvector-append
12+ flexvector-concatenate flexvector-append-subvectors
13+ flexvector? flexvector-empty? flexvector=? flexvector-ref
14+ flexvector-front flexvector-back flexvector-length
15+ flexvector-add! flexvector-add-front! flexvector-add-back!
16+ flexvector-remove! flexvector-remove-front!
17+ flexvector-remove-back! flexvector-add-all!
18+ flexvector-remove-range! flexvector-clear! flexvector-set!
19+ flexvector-swap! flexvector-fill! flexvector-reverse!
20+ flexvector-copy! flexvector-reverse-copy! flexvector-append!
21+ flexvector-fold flexvector-fold-right flexvector-map
22+ flexvector-map! flexvector-map/index flexvector-map/index!
23+ flexvector-append-map flexvector-append-map/index
24+ flexvector-filter flexvector-filter! flexvector-filter/index
25+ flexvector-filter/index! flexvector-for-each
26+ flexvector-for-each/index flexvector-count
27+ flexvector-cumulate flexvector-index flexvector-index-right
28+ flexvector-skip flexvector-skip-right
29+ flexvector-binary-search flexvector-any flexvector-every
30+ flexvector-partition flexvector->vector flexvector->list
31+ flexvector->string vector->flexvector list->flexvector
32+ string->flexvector reverse-flexvector->list
33+ reverse-list->flexvector generator->flexvector
34+ flexvector->generator)
35+ (import (except (rnrs) vector-fill!) (purs runtime srfi :26)
36+ (purs runtime srfi :214 parameters)
37+ (except (purs runtime srfi :133 vectors) vector->list list->vector)
38+ (purs runtime srfi :158))
39+ (define (nonnegative? num) (and (number? num) (>= num 0)))
40+ (define (negate pred?)
41+ (lambda args (not (apply pred? args))))
42+ (define (assert-index-validity fv . ids)
43+ (let ([len (flexvector-len fv)])
44+ (for-each
45+ (lambda (i) (assert (and (>= i 0) (< i len))))
46+ ids)))
47+ (define (group lst num)
48+ (define (split l n)
49+ (let loop ([acc (list)] [ls l] [count 0])
50+ (cond
51+ [(>= count n) (values (reverse acc) ls)]
52+ [(null? ls)
53+ (error group "Not enough elements for a group" lst num)]
54+ [else (loop (cons (car ls) acc) (cdr ls) (+ count 1))])))
55+ (assert (positive? num))
56+ (let loop ([acc (list)] [source lst])
57+ (cond
58+ [(null? source) (reverse acc)]
59+ [else
60+ (let-values ([(grp rest) (split source num)])
61+ (loop (cons grp acc) rest))])))
62+ (define-record-type (%flexvector
63+ %make-flexvector
64+ flexvector?)
65+ (nongenerative flexvector-vtlmh5fxbj)
66+ (fields
67+ (mutable vec flexvector-vec flexvector-vec-set!)
68+ (mutable len flexvector-len flexvector-len-set!)))
69+ (define-syntax with-flexvectors
70+ (syntax-rules ()
71+ [(_ (((vec len) fv) rest ...) body ...)
72+ (let* ([fv* fv]
73+ [vec (flexvector-vec fv*)]
74+ [len (flexvector-len fv*)])
75+ (with-flexvectors (rest ...) body ...))]
76+ [(_ () body ...) (let () body ...)]))
77+ (define-syntax with-clamped-range
78+ (syntax-rules ()
79+ [(_ (fv start end) body ...)
80+ (let ([start (max 0 start)]
81+ [end (min end (flexvector-len fv))])
82+ (assert (<= start end))
83+ (let () body ...))]))
84+ (define-syntax define-with-range
85+ (syntax-rules (of)
86+ [(_ (name fv ... start (end of what)) body ...)
87+ (define name
88+ (case-lambda
89+ [(fv ...) (name fv ... 0)]
90+ [(fv ... start) (name fv ... start (flexvector-len what))]
91+ [(fv ... start end)
92+ (with-clamped-range (what start end) body ...)]))]))
93+ (define (shortest-length vecs)
94+ (apply min (map flexvector-len vecs)))
95+ (define-syntax with-shortest-length
96+ (syntax-rules ()
97+ [(_ ((vecs shortest-len) vecs-expr) body ...)
98+ (let* ([vecs vecs-expr]
99+ [shortest-len (shortest-length vecs)])
100+ body
101+ ...)]))
102+ (define (flexvector-cap fv)
103+ (vector-length (flexvector-vec fv)))
104+ (define (ensure-capacity! fv required-cap)
105+ (let ([current-cap (flexvector-cap fv)])
106+ (unless (>= current-cap required-cap)
107+ (let* ([vec (flexvector-vec fv)]
108+ [new-cap ((flexvector-capacity-estimator)
109+ current-cap
110+ required-cap)]
111+ [new-vec (make-vector new-cap)])
112+ (vector-copy! new-vec 0 vec 0 (vector-length vec))
113+ (flexvector-vec-set! fv new-vec)))))
114+ (define (ensure-valid-capacity requested-size)
115+ (assert (and (exact? requested-size) (>= requested-size 0)))
116+ (max requested-size (flexvector-min-capacity)))
117+ (define make-flexvector
118+ (case-lambda
119+ [(size)
120+ (assert (nonnegative? size))
121+ (%make-flexvector
122+ (make-vector (ensure-valid-capacity size))
123+ size)]
124+ [(size fill)
125+ (assert (nonnegative? size))
126+ (%make-flexvector
127+ (make-vector (ensure-valid-capacity size) fill)
128+ size)]))
129+ (define (flexvector . els)
130+ (cond
131+ [(null? els) (make-flexvector 0)]
132+ [else (list->flexvector els)]))
133+ (define (flexvector-unfold pred func gen . seeds)
134+ (let ([fv (flexvector)])
135+ (do ([seeds seeds (let-values ([seeds (apply gen seeds)])
136+ seeds)])
137+ ((apply pred seeds) fv)
138+ (flexvector-add-back! fv (apply func seeds)))))
139+ (define (flexvector-unfold-right pred func gen . seeds)
140+ (let ([fv (apply flexvector-unfold pred func gen seeds)])
141+ (flexvector-reverse! fv)
142+ fv))
143+ (define-with-range
144+ (flexvector-copy fv start (end of fv))
145+ (with-flexvectors
146+ (((vec len) fv))
147+ (let ([result (make-flexvector (- end start))])
148+ (vector-copy! (flexvector-vec result) 0 vec start end)
149+ result)))
150+ (define (flexvector-reverse-copy . args)
151+ (let ([copy (apply flexvector-copy args)])
152+ (flexvector-reverse! copy)
153+ copy))
154+ (define (flexvector-append fv . rest)
155+ (flexvector-concatenate (cons fv rest)))
156+ (define (flexvector-concatenate fvs)
157+ (let* ([total-len (fold-left + 0 (map flexvector-len fvs))]
158+ [result (make-flexvector total-len)])
159+ (let loop ([vecs fvs] [offset 0])
160+ (cond
161+ [(null? vecs) result]
162+ [else
163+ (let ([current (car vecs)])
164+ (flexvector-copy! result offset current)
165+ (loop (cdr vecs) (+ offset (flexvector-len current))))]))))
166+ (define (flexvector-append-subvectors . args)
167+ (let* ([triplets (group args 3)]
168+ [subvecs (map (lambda (triplet)
169+ (apply flexvector-copy triplet))
170+ triplets)])
171+ (flexvector-concatenate subvecs)))
172+ (define (flexvector-empty? fv) (zero? (flexvector-len fv)))
173+ (define (flexvector=? elt=? . fvs)
174+ (define (combine result . es) (and result (apply elt=? es)))
175+ (let ([lens (map flexvector-len fvs)])
176+ (or (null? fvs)
177+ (null? (cdr fvs))
178+ (and (apply = lens)
179+ (apply flexvector-fold combine #t fvs)))))
180+ (define (flexvector-ref fv index)
181+ (with-flexvectors
182+ (((vec len) fv))
183+ (assert-index-validity fv index)
184+ (vector-ref vec index)))
185+ (define (flexvector-front fv) (flexvector-ref fv 0))
186+ (define (flexvector-back fv)
187+ (let ([len (flexvector-len fv)])
188+ (flexvector-ref fv (- len 1))))
189+ (define flexvector-length flexvector-len)
190+ (define (flexvector-add! fv i . els)
191+ (flexvector-add-all! fv i els))
192+ (define (flexvector-add-front! fv . els)
193+ (flexvector-add-all! fv 0 els))
194+ (define (flexvector-add-back! fv . els)
195+ (flexvector-add-all! fv (flexvector-len fv) els))
196+ (define (flexvector-add-all! fv i els)
197+ (let* ([count (length els)]
198+ [len (flexvector-len fv)]
199+ [total-len (+ len count)])
200+ (ensure-capacity! fv total-len)
201+ (let ([vec (flexvector-vec fv)])
202+ (vector-copy! vec (+ i count) vec i len)
203+ (let loop ([ls els] [offset 0])
204+ (cond
205+ [(null? ls) (flexvector-len-set! fv total-len) fv]
206+ [else
207+ (let ([el (car ls)])
208+ (vector-set! vec (+ i offset) el)
209+ (loop (cdr ls) (+ offset 1)))])))))
210+ (define (flexvector-append! fv . fvs)
211+ (let* ([len (flexvector-len fv)]
212+ [total-len (fold-left + len (map flexvector-len fvs))])
213+ (ensure-capacity! fv total-len)
214+ (let ([vec (flexvector-vec fv)])
215+ (let loop ([fvs fvs] [offset len])
216+ (cond
217+ [(null? fvs) (flexvector-len-set! fv total-len) fv]
218+ [else
219+ (with-flexvectors
220+ (((current-vec current-len) (car fvs)))
221+ (vector-copy! vec offset current-vec 0 current-len)
222+ (loop (cdr fvs) (+ offset current-len)))])))))
223+ (define (flexvector-remove! fv i)
224+ (let ([value (flexvector-ref fv i)])
225+ (flexvector-remove-range! fv i (+ i 1))
226+ value))
227+ (define (flexvector-remove-front! fv)
228+ (flexvector-remove! fv 0))
229+ (define (flexvector-remove-back! fv)
230+ (flexvector-remove! fv (- (flexvector-len fv) 1)))
231+ (define flexvector-remove-range!
232+ (case-lambda
233+ [(fv start)
234+ (flexvector-remove-range! fv start (flexvector-len fv))]
235+ [(fv start end)
236+ (with-flexvectors
237+ (((vec len) fv))
238+ (let* ([start (max start 0)]
239+ [end (min len end)]
240+ [move-count (- len end)]
241+ [len-delta (- end start)])
242+ (assert (<= start end))
243+ (unless (zero? move-count)
244+ (vector-copy! vec start vec end (+ end move-count)))
245+ (flexvector-len-set! fv (- len len-delta))
246+ fv))]))
247+ (define (flexvector-clear! fv)
248+ (flexvector-len-set! fv 0)
249+ fv)
250+ (define (flexvector-set! fv i el)
251+ (assert-index-validity fv i)
252+ (with-flexvectors
253+ (((vec len) fv))
254+ (let* ([val (vector-ref vec i)])
255+ (vector-set! vec i el)
256+ val)))
257+ (define (flexvector-swap! fv i j)
258+ (assert-index-validity fv i j)
259+ (with-flexvectors (((vec len) fv)) (vector-swap! vec i j)))
260+ (define-with-range
261+ (flexvector-fill! fv fill start (end of fv))
262+ (with-flexvectors
263+ (((vec len) fv))
264+ (let ([start (max 0 start)] [end (min end len)])
265+ (vector-fill! vec fill start end)
266+ fv)))
267+ (define-with-range
268+ (flexvector-reverse! fv start (end of fv))
269+ (let* ([len (- end start)]
270+ [vec (flexvector-vec fv)]
271+ [half (floor (/ len 2))])
272+ (do ([index 0 (+ index 1)])
273+ ((>= index half) fv)
274+ (let ([jndex (- len index 1)])
275+ (vector-swap! vec (+ start index) (+ start jndex))))))
276+ (define-with-range
277+ (flexvector-copy! to at from start (end of from))
278+ (let* ([len (flexvector-len to)]
279+ [delta (- end start)]
280+ [new-len (+ len delta)])
281+ (assert (and (>= at 0) (<= at len)))
282+ (ensure-capacity! to new-len)
283+ (with-flexvectors
284+ (((to-vec to-len) to) ((from-vec from-len) from))
285+ (vector-copy! to-vec at from-vec start end)
286+ (flexvector-len-set! to (max len (+ at delta)))
287+ to)))
288+ (define-with-range
289+ (flexvector-reverse-copy! to at from start (end of from))
290+ (flexvector-copy! to at from start end)
291+ (flexvector-reverse! to at (+ at (- end start))))
292+ (define (flexvector-fold-impl index-proc reductor initial fv
293+ . rest)
294+ (with-shortest-length
295+ ((vecs shortest-len) (cons fv rest))
296+ (let loop ([index 0] [state initial])
297+ (cond
298+ [(>= index shortest-len) state]
299+ [else
300+ (loop
301+ (+ index 1)
302+ (apply
303+ reductor
304+ state
305+ (map (cut flexvector-ref <> (index-proc index shortest-len))
306+ vecs)))]))))
307+ (define (flexvector-fold reductor initial fv . rest)
308+ (define (left-to-right index len) index)
309+ (apply flexvector-fold-impl left-to-right reductor initial
310+ fv rest))
311+ (define (flexvector-fold-right reductor initial fv . rest)
312+ (define (right-to-left index len) (- len index 1))
313+ (apply flexvector-fold-impl right-to-left reductor initial
314+ fv rest))
315+ (define (flexvector-map/index-into! dst proc fv . rest)
316+ (with-shortest-length
317+ ((vecs shortest-len) (cons fv rest))
318+ (let loop ([index 0])
319+ (cond
320+ [(>= index shortest-len) dst]
321+ [else
322+ (let ([value (apply
323+ proc
324+ index
325+ (map (cut flexvector-ref <> index) vecs))])
326+ (flexvector-set! dst index value)
327+ (loop (+ index 1)))]))))
328+ (define (flexvector-map/index! proc fv . rest)
329+ (apply flexvector-map/index-into! fv proc fv rest))
330+ (define (flexvector-map! proc fv . rest)
331+ (define (ignore-index . args) (apply proc (cdr args)))
332+ (apply flexvector-map/index! ignore-index fv rest))
333+ (define (flexvector-map/index proc fv . rest)
334+ (with-shortest-length
335+ ((vecs shortest-len) (cons fv rest))
336+ (let ([result (make-flexvector shortest-len)])
337+ (apply flexvector-map/index-into! result proc fv rest))))
338+ (define (flexvector-map proc fv . rest)
339+ (define (ignore-index . args) (apply proc (cdr args)))
340+ (apply flexvector-map/index ignore-index fv rest))
341+ (define (flexvector-append-map/index proc fv . rest)
342+ (flexvector-fold
343+ flexvector-append!
344+ (flexvector)
345+ (apply flexvector-map/index proc fv rest)))
346+ (define (flexvector-append-map proc fv . rest)
347+ (flexvector-fold
348+ flexvector-append!
349+ (flexvector)
350+ (apply flexvector-map proc fv rest)))
351+ (define (flexvector-filter/index! pred? fv)
352+ (with-flexvectors
353+ (((vec len) fv))
354+ (let loop ([check-index 0] [fill-index 0])
355+ (cond
356+ [(>= check-index len)
357+ (flexvector-len-set! fv fill-index)
358+ fv]
359+ [(pred? check-index (flexvector-ref fv check-index))
360+ (flexvector-set!
361+ fv
362+ fill-index
363+ (flexvector-ref fv check-index))
364+ (loop (+ check-index 1) (+ fill-index 1))]
365+ [else (loop (+ check-index 1) fill-index)]))))
366+ (define (flexvector-filter! pred? fv)
367+ (define (ignore-index index value) (pred? value))
368+ (flexvector-filter/index! ignore-index fv))
369+ (define (flexvector-filter/index pred? fv)
370+ (flexvector-filter/index! pred? (flexvector-copy fv)))
371+ (define (flexvector-filter pred? fv)
372+ (flexvector-filter! pred? (flexvector-copy fv)))
373+ (define (flexvector-for-each/index proc fv . rest)
374+ (with-shortest-length
375+ ((vecs shortest-len) (cons fv rest))
376+ (do ([index 0 (+ index 1)])
377+ ((>= index shortest-len))
378+ (apply
379+ proc
380+ index
381+ (map (cut flexvector-ref <> index) vecs)))))
382+ (define (flexvector-for-each proc fv . rest)
383+ (define (ignore-index . args) (apply proc (cdr args)))
384+ (apply flexvector-for-each/index ignore-index fv rest))
385+ (define (flexvector-count pred? fv . rest)
386+ (with-shortest-length
387+ ((vecs shortest-len) (cons fv rest))
388+ (let loop ([index 0] [count 0])
389+ (cond
390+ [(>= index shortest-len) count]
391+ [(apply pred? (map (cut flexvector-ref <> index) vecs))
392+ (loop (+ index 1) (+ count 1))]
393+ [else (loop (+ index 1) count)]))))
394+ (define (flexvector-cumulate reductor initial fv)
395+ (with-flexvectors
396+ (((vec len) fv))
397+ (let* ([result (make-flexvector len)]
398+ [new-vec (flexvector-vec result)])
399+ (let loop ([index 0] [state initial])
400+ (cond
401+ [(>= index len) result]
402+ [else
403+ (let ([new-state (reductor state (vector-ref vec index))])
404+ (vector-set! new-vec index new-state)
405+ (loop (+ index 1) new-state))])))))
406+ (define (flexvector-index pred? fv . rest)
407+ (with-shortest-length
408+ ((vecs shortest-len) (cons fv rest))
409+ (let loop ([index 0])
410+ (cond
411+ [(>= index shortest-len) #f]
412+ [(apply pred? (map (cut flexvector-ref <> index) vecs))
413+ index]
414+ [else (loop (+ index 1))]))))
415+ (define (flexvector-index-right pred? fv . rest)
416+ (with-shortest-length
417+ ((vecs shortest-len) (cons fv rest))
418+ (let loop ([index 0])
419+ (cond
420+ [(>= index shortest-len) #f]
421+ [(apply
422+ pred?
423+ (map (cut flexvector-ref <> (- shortest-len index 1)) vecs))
424+ (- shortest-len index 1)]
425+ [else (loop (+ index 1))]))))
426+ (define (flexvector-skip pred? fv . rest)
427+ (apply flexvector-index (negate pred?) fv rest))
428+ (define (flexvector-skip-right pred? fv . rest)
429+ (apply flexvector-index-right (negate pred?) fv rest))
430+ (define-with-range
431+ (flexvector-binary-search fv value comp start (end of fv))
432+ (let ([vec (flexvector-vec fv)])
433+ (vector-binary-search vec value comp start end)))
434+ (define (flexvector-any pred? fv . rest)
435+ (with-shortest-length
436+ ((vecs shortest-len) (cons fv rest))
437+ (let loop ([index 0])
438+ (cond
439+ [(>= index shortest-len) #f]
440+ [(apply pred? (map (cut flexvector-ref <> index) vecs))]
441+ [else (loop (+ index 1))]))))
442+ (define (flexvector-every pred? fv . rest)
443+ (with-shortest-length
444+ ((vecs shortest-len) (cons fv rest))
445+ (let loop ([index 0] [last-value #t])
446+ (cond
447+ [(>= index shortest-len) last-value]
448+ [(apply pred? (map (cut flexvector-ref <> index) vecs)) =>
449+ (lambda (val) (loop (+ index 1) val))]
450+ [else #f]))))
451+ (define (flexvector-partition pred? fv)
452+ (let ([matching (flexvector)] [non-matching (flexvector)])
453+ (flexvector-for-each
454+ (lambda (el)
455+ (flexvector-add-back!
456+ (if (pred? el) matching non-matching)
457+ el))
458+ fv)
459+ (values matching non-matching)))
460+ (define-with-range
461+ (flexvector->vector fv start (end of fv))
462+ (let ([vec (flexvector-vec fv)])
463+ (vector-copy vec start end)))
464+ (define vector->flexvector
465+ (case-lambda
466+ [(vec) (vector->flexvector vec 0)]
467+ [(vec start)
468+ (vector->flexvector vec start (vector-length vec))]
469+ [(vec start end)
470+ (let* ([len (- end start)]
471+ [result (make-flexvector len)]
472+ [fvec (flexvector-vec result)])
473+ (vector-copy! fvec 0 vec start end)
474+ result)]))
475+ (define (flexvector->list-impl finalizer fv start end)
476+ (with-flexvectors
477+ (((vec len) fv))
478+ (let loop ([acc (list)] [index 0])
479+ (cond
480+ [(>= index len) (finalizer acc)]
481+ [else
482+ (loop (cons (vector-ref vec index) acc) (+ index 1))]))))
483+ (define-with-range
484+ (flexvector->list fv start (end of fv))
485+ (flexvector->list-impl reverse fv start end))
486+ (define-with-range
487+ (reverse-flexvector->list fv start (end of fv))
488+ (define (identity l) l)
489+ (flexvector->list-impl identity fv start end))
490+ (define (list->flexvector-impl lst index-func)
491+ (let* ([len (length lst)] [fv (make-flexvector len)])
492+ (let loop ([lst lst] [index 0])
493+ (cond
494+ [(null? lst) fv]
495+ [else
496+ (flexvector-set! fv (index-func len index) (car lst))
497+ (loop (cdr lst) (+ index 1))]))))
498+ (define (list->flexvector lst)
499+ (list->flexvector-impl lst (lambda (len index) index)))
500+ (define (reverse-list->flexvector lst)
501+ (list->flexvector-impl
502+ lst
503+ (lambda (len index) (- len index 1))))
504+ (define-with-range
505+ (flexvector->string fv start (end of fv))
506+ (let-values ([(out fin) (open-string-output-port)])
507+ (with-flexvectors
508+ (((vec len) fv))
509+ (let loop ([index start])
510+ (cond
511+ [(>= index end) (fin)]
512+ [else
513+ (put-char out (vector-ref vec index))
514+ (loop (+ index 1))])))))
515+ (define string->flexvector
516+ (case-lambda
517+ [(str) (string->flexvector str 0)]
518+ [(str start)
519+ (string->flexvector str start (string-length str))]
520+ [(str start end)
521+ (let ([in (open-string-input-port
522+ (substring str start end))]
523+ [fv (flexvector)])
524+ (let loop ([ch (get-char in)])
525+ (cond
526+ [(eof-object? ch) fv]
527+ [else
528+ (flexvector-add-back! fv ch)
529+ (loop (get-char in))])))]))
530+ (define (flexvector->generator fv)
531+ (with-flexvectors
532+ (((vec len) fv))
533+ (let ([index 0])
534+ (lambda ()
535+ (cond
536+ [(>= index len) (eof-object)]
537+ [else
538+ (let ([value (vector-ref vec index)])
539+ (set! index (+ index 1))
540+ value)])))))
541+ (define (generator->flexvector gen)
542+ (let ([fv (flexvector)])
543+ (generator-fold
544+ (lambda (v r) (flexvector-add-back! r v))
545+ fv
546+ gen))))
vendor/purs/runtime/srfi/:214/parameters.slsnew file+39
@@ -0,0 +1,39 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a214/parameters.sls
7+#!r6rs
8+(library (purs runtime srfi :214 parameters)
9+ (export
10+ flexvector-min-capacity
11+ flexvector-capacity-estimator)
12+ (import (rnrs) (purs runtime srfi :39))
13+ (define (assert-valid-capacity-value value)
14+ (assert (and (number? value) (> value 0)))
15+ value)
16+ (define flexvector-min-capacity
17+ (make-parameter 4 assert-valid-capacity-value))
18+ (define (assert-valid-capacity-estimator value)
19+ (assert (procedure? value))
20+ (let* ([example-current 4]
21+ [example-requested 8]
22+ [example-cap (value example-current example-requested)])
23+ (assert
24+ (and (number? example-cap)
25+ (exact? example-cap)
26+ (>= example-cap example-requested)))
27+ value))
28+ (define (multiple-of-current-estimator current requested)
29+ (assert
30+ (and (number? current)
31+ (number? requested)
32+ (> current 0)
33+ (> requested 0)))
34+ (let ([quot (exact (ceiling (/ requested current)))])
35+ (* quot current)))
36+ (define flexvector-capacity-estimator
37+ (make-parameter
38+ multiple-of-current-estimator
39+ assert-valid-capacity-estimator)))
vendor/purs/runtime/srfi/:23.slsnew file+11
@@ -0,0 +1,11 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a23.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :23)
10+ (export error)
11+ (import (purs runtime srfi :23 error)))
vendor/purs/runtime/srfi/:23/error.slsnew file+13
@@ -0,0 +1,13 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a23/error.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :23 error)
11+ (export error)
12+ (import (rename (rnrs base) (error rnrs:error)))
13+ (define (error . args) (apply rnrs:error #f args)))
vendor/purs/runtime/srfi/:23/error/tricks.slsnew file+43
@@ -0,0 +1,43 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a23/error/tricks.sls
7+#!r6rs
8+;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :23 error tricks)
11+ (export SRFI-23-error->R6RS)
12+ (import (rnrs))
13+ (define-syntax error-wrap
14+ (lambda (stx)
15+ (syntax-case stx ()
16+ [(_ ctxt signal . forms)
17+ (with-syntax ([e (datum->syntax #'ctxt 'error)])
18+ #'(let-syntax ([e (identifier-syntax signal)]) . forms))])))
19+ (define (AV who)
20+ (lambda args (apply assertion-violation who args)))
21+ (define-syntax SRFI-23-error->R6RS
22+ (lambda (stx)
23+ (syntax-case stx ()
24+ [(ctxt ewho . forms)
25+ (with-syntax ([e (datum->syntax #'ctxt 'error)]
26+ [d (datum->syntax #'ctxt 'define)])
27+ #'(let-syntax ([e (identifier-syntax (AV 'ewho))]
28+ [d (lambda (stx)
29+ (syntax-case stx ()
30+ [(kw (id . formals) . body)
31+ (identifier? #'id)
32+ #'(error-wrap
33+ kw
34+ (AV 'id)
35+ (d (id . formals) . body))]
36+ [(kw id . r)
37+ (identifier? #'id)
38+ #'(error-wrap
39+ kw
40+ (AV 'id)
41+ (d id . r))]))])
42+ .
43+ forms))]))))
vendor/purs/runtime/srfi/:26.slsnew file+11
@@ -0,0 +1,11 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a26.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :26)
10+ (export cut cute <> <...>)
11+ (import (purs runtime srfi :26 cut)))
vendor/purs/runtime/srfi/:26/cut.slsnew file+102
@@ -0,0 +1,102 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a26/cut.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+;;;;;; File header: %3a26/cut-impl.scm
11+; REFERENCE IMPLEMENTATION FOR SRFI-26 "CUT"
12+; ==========================================
13+;
14+; Sebastian.Egner@philips.com, 5-Jun-2002.
15+; adapted from the posting by Al Petrofsky <al@petrofsky.org>
16+; placed in the public domain
17+;
18+; The code to handle the variable argument case was originally
19+; proposed by Michael Sperber and has been adapted to the new
20+; syntax of the macro using an explicit rest-slot symbol. The
21+; code to evaluate the non-slots for cute has been proposed by
22+; Dale Jordan. The code to allow a slot for the procedure position
23+; and to process the macro using an internal macro is based on
24+; a suggestion by Al Petrofsky. The code found below is, with
25+; exception of this header and some changes in variable names,
26+; entirely written by Al Petrofsky.
27+;
28+; compliance:
29+; Scheme R5RS (including macros).
30+;
31+; loading this file into Scheme 48 0.57:
32+; ,load cut.scm
33+;
34+; history of this file:
35+; SE, 6-Feb-2002: initial version as 'curry' with ". <>" notation
36+; SE, 14-Feb-2002: revised for <...>
37+; SE, 27-Feb-2002: revised for 'cut'
38+; SE, 03-Jun-2002: revised for proc-slot, cute
39+; SE, 04-Jun-2002: rewritten with internal transformer (no "loop" pattern)
40+; SE, 05-Jun-2002: replace my code by Al's; substituted "constant" etc.
41+; to match the convention in the SRFI-document
42+(library (purs runtime srfi :26 cut)
43+ (export cut cute <> <...>)
44+ (import (rnrs) (purs runtime srfi private include))
45+ (begin
46+ (define-syntax srfi-26-internal-cut
47+ (syntax-rules (<> <...>)
48+ [(srfi-26-internal-cut (slot-name ...) (proc arg ...))
49+ (lambda (slot-name ...) ((begin proc) arg ...))]
50+ [(srfi-26-internal-cut (slot-name ...) (proc arg ...) <...>)
51+ (lambda (slot-name ... . rest-slot)
52+ (apply proc arg ... rest-slot))]
53+ [(srfi-26-internal-cut (slot-name ...) (position ...) <> .
54+ se)
55+ (srfi-26-internal-cut
56+ (slot-name ... x)
57+ (position ... x)
58+ .
59+ se)]
60+ [(srfi-26-internal-cut (slot-name ...) (position ...) nse .
61+ se)
62+ (srfi-26-internal-cut
63+ (slot-name ...)
64+ (position ... nse)
65+ .
66+ se)]))
67+ (define-syntax srfi-26-internal-cute
68+ (syntax-rules (<> <...>)
69+ [(srfi-26-internal-cute
70+ (slot-name ...)
71+ nse-bindings
72+ (proc arg ...))
73+ (let nse-bindings (lambda [slot-name ...] [proc arg ...]))]
74+ [(srfi-26-internal-cute
75+ (slot-name ...)
76+ nse-bindings
77+ (proc arg ...)
78+ <...>)
79+ (let nse-bindings (lambda
80+ [slot-name ... . x]
81+ [apply proc arg ... x]))]
82+ [(srfi-26-internal-cute (slot-name ...) nse-bindings
83+ (position ...) <> . se)
84+ (srfi-26-internal-cute (slot-name ... x) nse-bindings
85+ (position ... x) . se)]
86+ [(srfi-26-internal-cute slot-names nse-bindings
87+ (position ...) nse . se)
88+ (srfi-26-internal-cute slot-names ((x nse) . nse-bindings)
89+ (position ... x) . se)]))
90+ (define-syntax <>
91+ (identifier-syntax (error #f "misplaced aux keyword <>")))
92+ (define-syntax <...>
93+ (identifier-syntax (error #f
94+ "misplaced aux keyword <...>")))
95+ (define-syntax cut
96+ (syntax-rules ()
97+ [(cut . slots-or-exprs)
98+ (srfi-26-internal-cut () () . slots-or-exprs)]))
99+ (define-syntax cute
100+ (syntax-rules ()
101+ [(cute . slots-or-exprs)
102+ (srfi-26-internal-cute () () () . slots-or-exprs)]))))
vendor/purs/runtime/srfi/:39.slsnew file+11
@@ -0,0 +1,11 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :39)
10+ (export make-parameter parameterize)
11+ (import (purs runtime srfi :39 parameters)))
vendor/purs/runtime/srfi/:39/parameters.chezscheme.slsnew file+24
@@ -0,0 +1,24 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39/parameters.chezscheme.sls
7+;;; Copyright (c) 2012 Aaron W. Hsu <arcfide@sacrideo.us>
8+;;;
9+;;; Permission to use, copy, modify, and distribute this software for
10+;;; any purpose with or without fee is hereby granted, provided that the
11+;;; above copyright notice and this permission notice appear in all
12+;;; copies.
13+;;;
14+;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
15+;;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
16+;;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
17+;;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
18+;;; DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
19+;;; OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20+;;; TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21+;;; PERFORMANCE OF THIS SOFTWARE.
22+(library (purs runtime srfi :39 parameters)
23+ (export make-parameter parameterize)
24+ (import (only (chezscheme) make-parameter parameterize)))
vendor/purs/runtime/srfi/:39/parameters.ikarus.slsnew file+12
@@ -0,0 +1,12 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39/parameters.ikarus.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :39 parameters)
11+ (export make-parameter parameterize)
12+ (import (only (ikarus) make-parameter parameterize)))
vendor/purs/runtime/srfi/:39/parameters.ironscheme.slsnew file+14
@@ -0,0 +1,14 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39/parameters.ironscheme.sls
7+#!r6rs
8+;; Copyright (c) 2009 Derick Eddington. All rights reserved. Licensed under an
9+;; MIT-style license. My license is in the file named LICENSE from the original
10+;; collection this file is distributed with. If this file is redistributed with
11+;; some other collection, my license must also be included.
12+(library (purs runtime srfi :39 parameters)
13+ (export make-parameter parameterize)
14+ (import (only (ironscheme) make-parameter parameterize)))
vendor/purs/runtime/srfi/:39/parameters.mzscheme.slsnew file+12
@@ -0,0 +1,12 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39/parameters.mzscheme.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :39 parameters)
11+ (export make-parameter parameterize)
12+ (import (only (scheme base) make-parameter parameterize)))
vendor/purs/runtime/srfi/:39/parameters.slsnew file+35
@@ -0,0 +1,35 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39/parameters.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :39 parameters)
11+ (export make-parameter parameterize)
12+ (import (rnrs))
13+ (define make-parameter
14+ (case-lambda
15+ [(val) (make-parameter val values)]
16+ [(val guard)
17+ (unless (procedure? guard)
18+ (assertion-violation 'make-parameter
19+ "not a procedure"
20+ guard))
21+ (let ([p (case-lambda [() val] [(x) (set! val (guard x))])])
22+ (p val)
23+ p)]))
24+ (define-syntax parameterize
25+ (lambda (stx)
26+ (syntax-case stx ()
27+ [(_ () b0 b ...) #'(let () b0 b ...)]
28+ [(_ ((p e) ...) b0 b ...)
29+ (with-syntax ([(tp ...) (generate-temporaries #'(p ...))]
30+ [(te ...) (generate-temporaries #'(e ...))])
31+ #'(let ([tp p] ... [te e] ...)
32+ (let ([swap (lambda ()
33+ (let ([t (tp)]) (tp te) (set! te t))
34+ ...)])
35+ (dynamic-wind swap (lambda () b0 b ...) swap))))]))))
vendor/purs/runtime/srfi/:39/parameters.ypsilon.slsnew file+12
@@ -0,0 +1,12 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a39/parameters.ypsilon.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :39 parameters)
11+ (export make-parameter parameterize)
12+ (import (only (core) make-parameter parameterize)))
vendor/purs/runtime/srfi/:8.slsnew file+11
@@ -0,0 +1,11 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a8.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :8)
10+ (export receive)
11+ (import (purs runtime srfi :8 receive)))
vendor/purs/runtime/srfi/:8/receive.slsnew file+18
@@ -0,0 +1,18 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a8/receive.sls
7+#!r6rs
8+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
9+;; LICENSE from the original collection this file is distributed with.
10+(library (purs runtime srfi :8 receive)
11+ (export receive)
12+ (import (rnrs))
13+ (define-syntax receive
14+ (syntax-rules ()
15+ [(_ formals expression b b* ...)
16+ (call-with-values
17+ (lambda () expression)
18+ (lambda formals b b* ...))])))
vendor/purs/runtime/srfi/:99.slsnew file+14
@@ -0,0 +1,14 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99.sls
7+#!r6rs
8+;; Automatically generated by private/make-aliased-libraries.sps
9+(library (purs runtime srfi :99)
10+ (export define-record-type make-rtd record-rtd record? rtd-accessor
11+ rtd-all-field-names rtd-constructor rtd-field-mutable?
12+ rtd-field-names rtd-mutator rtd-name rtd-parent
13+ rtd-predicate rtd?)
14+ (import (purs runtime srfi :99 records)))
vendor/purs/runtime/srfi/:99/records.slsnew file+35
@@ -0,0 +1,35 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records.sls
7+#!r6rs
8+;; Copyright (C) William D Clinger 2008. All Rights Reserved.
9+;;
10+;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+;; of this software and associated documentation files (the "Software"), to deal
12+;; in the Software without restriction, including without limitation the rights
13+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+;; copies of the Software, and to permit persons to whom the Software is
15+;; furnished to do so, subject to the following conditions:
16+;;
17+;; The above copyright notice and this permission notice shall be included in
18+;; all copies or substantial portions of the Software.
19+;;
20+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO
23+;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25+;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26+;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+(library (purs runtime srfi :99 records)
28+ (export record? record-rtd rtd-name rtd-parent rtd-field-names
29+ rtd-all-field-names rtd-field-mutable? make-rtd rtd?
30+ rtd-constructor rtd-predicate rtd-accessor rtd-mutator
31+ define-record-type)
32+ (import
33+ (purs runtime srfi :99 records inspection)
34+ (purs runtime srfi :99 records procedural)
35+ (purs runtime srfi :99 records syntactic)))
vendor/purs/runtime/srfi/:99/records/helper.slsnew file+30
@@ -0,0 +1,30 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/helper.sls
7+#!r6rs
8+;; Copyright (C) William D Clinger 2008. All Rights Reserved.
9+;;
10+;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+;; of this software and associated documentation files (the "Software"), to deal
12+;; in the Software without restriction, including without limitation the rights
13+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+;; copies of the Software, and to permit persons to whom the Software is
15+;; furnished to do so, subject to the following conditions:
16+;;
17+;; The above copyright notice and this permission notice shall be included in
18+;; all copies or substantial portions of the Software.
19+;;
20+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO
23+;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25+;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26+;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+(library (purs runtime srfi :99 records helper)
28+ (export rtd?)
29+ (import (rnrs base) (rnrs records procedural))
30+ (define rtd? record-type-descriptor?))
vendor/purs/runtime/srfi/:99/records/inspection.larceny.slsnew file+10
@@ -0,0 +1,10 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/inspection.larceny.sls
7+(library (purs runtime srfi :99 records inspection)
8+ (export record? record-rtd rtd-name rtd-parent
9+ rtd-field-names rtd-all-field-names rtd-field-mutable?)
10+ (import (err5rs records inspection)))
vendor/purs/runtime/srfi/:99/records/inspection.slsnew file+60
@@ -0,0 +1,60 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/inspection.sls
7+#!r6rs
8+;; Copyright (C) William D Clinger 2008. All Rights Reserved.
9+;;
10+;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+;; of this software and associated documentation files (the "Software"), to deal
12+;; in the Software without restriction, including without limitation the rights
13+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+;; copies of the Software, and to permit persons to whom the Software is
15+;; furnished to do so, subject to the following conditions:
16+;;
17+;; The above copyright notice and this permission notice shall be included in
18+;; all copies or substantial portions of the Software.
19+;;
20+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO
23+;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25+;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26+;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+(library (purs runtime srfi :99 records inspection)
28+ (export record? record-rtd rtd-name rtd-parent
29+ rtd-field-names rtd-all-field-names rtd-field-mutable?)
30+ (import
31+ (rnrs base)
32+ (rnrs lists)
33+ (rnrs records inspection)
34+ (purs runtime srfi :99 records helper))
35+ (define rtd-name record-type-name)
36+ (define rtd-parent record-type-parent)
37+ (define rtd-field-names record-type-field-names)
38+ (define (rtd-all-field-names rtd)
39+ (define (loop rtd othernames)
40+ (let ([parent (rtd-parent rtd)]
41+ [names (append
42+ (vector->list (rtd-field-names rtd))
43+ othernames)])
44+ (if parent (loop parent names) (list->vector names))))
45+ (loop rtd '()))
46+ (define (rtd-field-mutable? rtd0 fieldname)
47+ (define (loop rtd)
48+ (if (rtd? rtd)
49+ (let* ([names (vector->list (rtd-field-names rtd))]
50+ [probe (memq fieldname names)])
51+ (if probe
52+ (record-field-mutable?
53+ rtd
54+ (- (length names) (length probe)))
55+ (loop (rtd-parent rtd))))
56+ (assertion-violation 'rtd-field-mutable?
57+ "illegal argument"
58+ rtd0
59+ fieldname)))
60+ (loop rtd0)))
vendor/purs/runtime/srfi/:99/records/procedural.larceny.slsnew file+10
@@ -0,0 +1,10 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/procedural.larceny.sls
7+(library (purs runtime srfi :99 records procedural)
8+ (export make-rtd rtd? rtd-constructor rtd-predicate
9+ rtd-accessor rtd-mutator)
10+ (import (err5rs records procedural)))
vendor/purs/runtime/srfi/:99/records/procedural.slsnew file+108
@@ -0,0 +1,108 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/procedural.sls
7+#!r6rs
8+;; Copyright (C) William D Clinger 2008. All Rights Reserved.
9+;;
10+;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+;; of this software and associated documentation files (the "Software"), to deal
12+;; in the Software without restriction, including without limitation the rights
13+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+;; copies of the Software, and to permit persons to whom the Software is
15+;; furnished to do so, subject to the following conditions:
16+;;
17+;; The above copyright notice and this permission notice shall be included in
18+;; all copies or substantial portions of the Software.
19+;;
20+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO
23+;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25+;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26+;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+(library (purs runtime srfi :99 records procedural)
28+ (export make-rtd rtd? rtd-constructor rtd-predicate
29+ rtd-accessor rtd-mutator)
30+ (import
31+ (rnrs base)
32+ (rnrs lists)
33+ (rnrs records procedural)
34+ (purs runtime srfi :99 records inspection))
35+ (define (make-rtd name fieldspecs . rest)
36+ (let* ([parent (if (null? rest) #f (car rest))]
37+ [options (if (null? rest) '() (cdr rest))]
38+ [sealed? (and (memq 'sealed options) #t)]
39+ [opaque? (and (memq 'opaque options) #t)]
40+ [uid (let ([probe (memq 'uid options)])
41+ (if (and probe (not (null? (cdr probe))))
42+ (cadr probe)
43+ #f))])
44+ (make-record-type-descriptor name parent uid sealed? opaque?
45+ (vector-map
46+ (lambda (fieldspec)
47+ (if (symbol? fieldspec)
48+ (list 'mutable fieldspec)
49+ fieldspec))
50+ (if (list? fieldspecs)
51+ (list->vector fieldspecs)
52+ fieldspecs)))))
53+ (define rtd? record-type-descriptor?)
54+ (define (rtd-constructor rtd . rest)
55+ (define (make-constructor fieldspecs allnames maker)
56+ (let* ([k (length fieldspecs)]
57+ [n (length allnames)]
58+ [buffer (make-vector n)]
59+ [reverse-all-names (reverse allnames)])
60+ (define (position fieldname)
61+ (let ([names (memq fieldname reverse-all-names)])
62+ (assert names)
63+ (- (length names) 1)))
64+ (let ([indexes (map position fieldspecs)])
65+ (lambda args
66+ (assert (= (length args) k))
67+ (for-each
68+ (lambda (arg posn) (vector-set! buffer posn arg))
69+ args
70+ indexes)
71+ (apply maker (vector->list buffer))))))
72+ (if (null? rest)
73+ (record-constructor
74+ (make-record-constructor-descriptor rtd #f #f))
75+ (begin
76+ (assert (null? (cdr rest)))
77+ (make-constructor
78+ (vector->list (car rest))
79+ (vector->list (rtd-all-field-names rtd))
80+ (record-constructor
81+ (make-record-constructor-descriptor rtd #f #f))))))
82+ (define rtd-predicate record-predicate)
83+ (define (rtd-accessor rtd0 fieldname)
84+ (define (loop rtd)
85+ (if (rtd? rtd)
86+ (let* ([names (vector->list (rtd-field-names rtd))]
87+ [probe (memq fieldname names)])
88+ (if probe
89+ (record-accessor rtd (- (length names) (length probe)))
90+ (loop (rtd-parent rtd))))
91+ (assertion-violation 'rtd-accessor
92+ "illegal argument"
93+ rtd0
94+ fieldname)))
95+ (loop rtd0))
96+ (define (rtd-mutator rtd0 fieldname)
97+ (define (loop rtd)
98+ (if (rtd? rtd)
99+ (let* ([names (vector->list (rtd-field-names rtd))]
100+ [probe (memq fieldname names)])
101+ (if probe
102+ (record-mutator rtd (- (length names) (length probe)))
103+ (loop (rtd-parent rtd))))
104+ (assertion-violation 'rtd-mutator
105+ "illegal argument"
106+ rtd0
107+ fieldname)))
108+ (loop rtd0)))
vendor/purs/runtime/srfi/:99/records/syntactic.larceny.slsnew file+9
@@ -0,0 +1,9 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/syntactic.larceny.sls
7+(library (purs runtime srfi :99 records syntactic)
8+ (export define-record-type)
9+ (import (err5rs records syntactic)))
vendor/purs/runtime/srfi/:99/records/syntactic.slsnew file+208
@@ -0,0 +1,208 @@
1+;; DO NOT EDIT THIS FILE!!
2+;; This inlined chez-srfi library code is autogenerated using command:
3+;; $ ./install.chezscheme.sps ../vendor/
4+;; Source origin: https://github.com/arcfide/chez-srfi
5+;; Please refer to project site for full credits and original code.
6+;;;;;; File header: %3a99/records/syntactic.sls
7+#!r6rs
8+;; Copyright (C) William D Clinger 2008. All Rights Reserved.
9+;;
10+;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+;; of this software and associated documentation files (the "Software"), to deal
12+;; in the Software without restriction, including without limitation the rights
13+;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+;; copies of the Software, and to permit persons to whom the Software is
15+;; furnished to do so, subject to the following conditions:
16+;;
17+;; The above copyright notice and this permission notice shall be included in
18+;; all copies or substantial portions of the Software.
19+;;
20+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO
23+;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25+;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26+;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+(library (purs runtime srfi :99 records syntactic)
28+ (export define-record-type)
29+ (import
30+ (for (rnrs base) run expand)
31+ (for (rnrs lists) run expand)
32+ (for (rnrs syntax-case) run expand)
33+ (purs runtime srfi :99 records procedural))
34+ (define-syntax define-record-type
35+ (syntax-rules ()
36+ [(_ (type-name parent) constructor-spec predicate-spec .
37+ field-specs)
38+ (define-record-type-helper0 type-name parent
39+ constructor-spec predicate-spec . field-specs)]
40+ [(_ type-name constructor-spec predicate-spec . field-specs)
41+ (define-record-type-helper0 type-name #f constructor-spec
42+ predicate-spec . field-specs)]))
43+ (define-syntax define-record-type-helper0
44+ (lambda (x)
45+ (define (construct-record-type-definitions tname fields
46+ parent cspec pred afields mfields)
47+ (let ()
48+ (define (frob x)
49+ (cond
50+ [(identifier? x) x]
51+ [(pair? x) (cons (frob (car x)) (frob (cdr x)))]
52+ [(vector? x) (vector-map frob x)]
53+ [(symbol? x) (datum->syntax tname x)]
54+ [else x]))
55+ #`(#,(frob #'define-record-type-helper) #,(frob tname) #,(frob fields) #,(frob parent)
56+ #,(frob cspec) #,(frob pred) #,(frob afields)
57+ #,(frob mfields))))
58+ (define (syntax-car x)
59+ (syntax-case x () [(x0 x1 ...) #'x0]))
60+ (define (syntax-cdr x)
61+ (syntax-case x () [(x0 x1 ...) #'(x1 ...)]))
62+ (define (syntax->list x)
63+ (syntax-case x ()
64+ [() '()]
65+ [(x0 . x1) (cons #'x0 (syntax->list #'x1))]))
66+ (define (complain)
67+ (syntax-violation 'define-record-type "illegal syntax" x))
68+ (syntax-case x ()
69+ [(_ tname pname constructor-spec predicate-spec .
70+ field-specs)
71+ (let* ([type-name (syntax->datum #'tname)]
72+ [cspec (syntax->datum #'constructor-spec)]
73+ [pspec (syntax->datum #'predicate-spec)]
74+ [fspecs (syntax->datum #'field-specs)]
75+ [type-name-string (begin
76+ (if (not (symbol? type-name))
77+ (complain))
78+ (symbol->string type-name))]
79+ [constructor-name (cond
80+ [(eq? cspec #f) #'constructor-spec]
81+ [(eq? cspec #t)
82+ (datum->syntax
83+ #'tname
84+ (string->symbol
85+ (string-append
86+ "make-"
87+ type-name-string)))]
88+ [(symbol? cspec) #'constructor-spec]
89+ [(and (pair? cspec)
90+ (symbol? (car cspec)))
91+ (syntax-car #'constructor-spec)]
92+ [else (complain)])]
93+ [constructor-args (cond
94+ [(pair? cspec)
95+ (if (not (for-all symbol? cspec))
96+ (complain)
97+ (list->vector
98+ (syntax->list
99+ (syntax-cdr
100+ #'constructor-spec))))]
101+ [else #f])]
102+ [new-constructor-spec (if constructor-args
103+ (list
104+ constructor-name
105+ constructor-args)
106+ constructor-name)]
107+ [predicate-name (cond
108+ [(eq? pspec #f) #'predicate-spec]
109+ [(eq? pspec #t)
110+ (datum->syntax
111+ #'tname
112+ (string->symbol
113+ (string-append
114+ type-name-string
115+ "?")))]
116+ [(symbol? pspec) #'predicate-spec]
117+ [else (complain)])]
118+ [field-specs (map (lambda (fspec field-spec)
119+ (cond
120+ [(symbol? fspec)
121+ (list
122+ 'immutable
123+ fspec
124+ (string->symbol
125+ (string-append
126+ type-name-string
127+ "-"
128+ (symbol->string fspec))))]
129+ [(not (pair? fspec)) (complain)]
130+ [(not (list? fspec)) (complain)]
131+ [(not (for-all symbol? fspec))
132+ (complain)]
133+ [(null? (cdr fspec))
134+ (list
135+ 'mutable
136+ (car fspec)
137+ (string->symbol
138+ (string-append
139+ type-name-string
140+ "-"
141+ (symbol->string (car fspec))))
142+ (string->symbol
143+ (string-append
144+ type-name-string
145+ "-"
146+ (symbol->string (car fspec))
147+ "-set!")))]
148+ [(null? (cddr fspec))
149+ (list
150+ 'immutable
151+ (car fspec)
152+ (syntax-car
153+ (syntax-cdr field-spec)))]
154+ [(null? (cdddr fspec))
155+ (list
156+ 'mutable
157+ (car fspec)
158+ (syntax-car
159+ (syntax-cdr field-spec))
160+ (syntax-car
161+ (syntax-cdr
162+ (syntax-cdr field-spec))))]
163+ [else (complain)]))
164+ fspecs
165+ (syntax->list #'field-specs))]
166+ [fields (list->vector (map cadr field-specs))]
167+ [accessor-fields (map (lambda (x)
168+ (list (caddr x) (cadr x)))
169+ (filter
170+ (lambda (x) (>= (length x) 3))
171+ field-specs))]
172+ [mutator-fields (map (lambda (x)
173+ (list (cadddr x) (cadr x)))
174+ (filter
175+ (lambda (x) (= (length x) 4))
176+ field-specs))])
177+ (construct-record-type-definitions #'tname fields #'pname new-constructor-spec predicate-name
178+ accessor-fields mutator-fields))])))
179+ (define-syntax define-record-type-helper
180+ (syntax-rules ()
181+ [(_ type-name fields parent #f predicate
182+ ((accessor field) ...) ((mutator mutable-field) ...))
183+ (define-record-type-helper type-name fields parent ignored predicate
184+ ((accessor field) ...) ((mutator mutable-field) ...))]
185+ [(_ type-name fields parent constructor #f
186+ ((accessor field) ...) ((mutator mutable-field) ...))
187+ (define-record-type-helper type-name fields parent constructor ignored
188+ ((accessor field) ...) ((mutator mutable-field) ...))]
189+ [(_ type-name fields parent (constructor args) predicate
190+ ((accessor field) ...) ((mutator mutable-field) ...))
191+ (begin
192+ (define type-name (make-rtd 'type-name 'fields parent))
193+ (define constructor (rtd-constructor type-name 'args))
194+ (define predicate (rtd-predicate type-name))
195+ (define accessor (rtd-accessor type-name 'field))
196+ ...
197+ (define mutator (rtd-mutator type-name 'mutable-field))
198+ ...)]
199+ [(_ type-name fields parent constructor predicate
200+ ((accessor field) ...) ((mutator mutable-field) ...))
201+ (begin
202+ (define type-name (make-rtd 'type-name 'fields parent))
203+ (define constructor (rtd-constructor type-name))
204+ (define predicate (rtd-predicate type-name))
205+ (define accessor (rtd-accessor type-name 'field))
206+ ...
207+ (define mutator (rtd-mutator type-name 'mutable-field))
208+ ...)])))
vendor/purs/runtime/srfi/private/OS-id-features.slsnew file+22
@@ -0,0 +1,22 @@
1+#!r6rs
2+;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
3+;; LICENSE from the original collection this file is distributed with.
4+
5+(library (purs runtime srfi private OS-id-features)
6+ (export
7+ OS-id-features)
8+ (import
9+ (rnrs))
10+
11+ (define (OS-id-features OS-id features-alist)
12+ (define OS-id-len (string-length OS-id))
13+ (define (OS-id-contains? str)
14+ (define str-len (string-length str))
15+ (let loop ((i 0))
16+ (and (<= (+ i str-len) OS-id-len)
17+ (or (string-ci=? str (substring OS-id i (+ i str-len)))
18+ (loop (+ 1 i))))))
19+ (apply append
20+ (map cdr (filter (lambda (x) (OS-id-contains? (car x)))
21+ features-alist))))
22+)
vendor/purs/runtime/srfi/private/include.chezscheme.slsnew file+3
@@ -0,0 +1,3 @@
1+(library (purs runtime srfi private include)
2+ (export)
3+ (import (chezscheme)))
vendor/purs/runtime/srfi/private/platform-features.chezscheme.slsnew file+34
@@ -0,0 +1,34 @@
1+;;; Copyright (c) 2012 Aaron W. Hsu <arcfide@sacrideo.us>
2+;;;
3+;;; Permission to use, copy, modify, and distribute this software for any
4+;;; purpose with or without fee is hereby granted, provided that the above
5+;;; copyright notice and this permission notice appear in all copies.
6+;;;
7+;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+;;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+;;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+;;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+;;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+;;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+
15+(library (purs runtime srfi private platform-features)
16+ (export expand-time-features run-time-features)
17+ (import (chezscheme) (purs runtime srfi private OS-id-features))
18+
19+(define (expand-time-features) '(chezscheme syntax-case))
20+
21+(define (run-time-features)
22+ (OS-id-features (symbol->string (machine-type))
23+ '(("t" threads)
24+ ("a6" x86-64)
25+ ("i3" x86)
26+ ("le" linux posix)
27+ ("ob" openbsd posix bsd)
28+ ("fb" freebsd posix bsd)
29+ ("nb" netbsd posix bsd)
30+ ("osx" darwin posix)
31+ ("s2" solaris posix)
32+ ("nt" windows))))
33+
34+)
vendor/purs/runtime/srfi/private/registry-names.slsnew file+66
@@ -0,0 +1,66 @@
1+#!r6rs
2+;; Automatically generated by registry-names-update.sps
3+(library (purs runtime srfi private registry-names)
4+ (export SRFIs)
5+ (import (rnrs))
6+ (define SRFIs
7+ '((0 cond-expand)
8+ (1 lists)
9+ (2 and-let*)
10+ (4 numeric-vectors)
11+ (5 let)
12+ (6 basic-string-ports)
13+ (8 receive)
14+ (9 records)
15+ (11 let-values)
16+ (13 strings)
17+ (14 char-sets)
18+ (16 case-lambda)
19+ (17 generalized-set!)
20+ (19 time)
21+ (23 error)
22+ (25 multi-dimensional-arrays)
23+ (26 cut)
24+ (27 random-bits)
25+ (28 basic-format-strings)
26+ (29 localization)
27+ (31 rec)
28+ (34 exception-handling)
29+ (35 conditions)
30+ (37 args-fold)
31+ (38 with-shared-structure)
32+ (39 parameters)
33+ (41 streams)
34+ (42 eager-comprehensions)
35+ (43 vectors)
36+ (45 lazy)
37+ (48 intermediate-format-strings)
38+ (51 rest-values)
39+ (54 cat)
40+ (60 integer-bits)
41+ (61 cond)
42+ (64 testing)
43+ (67 compare-procedures)
44+ (69 basic-hash-tables)
45+ (78 lightweight-testing)
46+ (98 os-environment-variables)
47+ (99 records)
48+ (115 regex)
49+ (117 list-queues)
50+ (125 hashtables)
51+ (126 r6rs-hashtables)
52+ (127 lazy-sequences)
53+ (128 comparators)
54+ (129 titlecase)
55+ (130 string-cursors)
56+ (131 records)
57+ (132 sorting)
58+ (133 vectors)
59+ (141 integer-division)
60+ (143 fixnums)
61+ (145 assumptions)
62+ (151 bitwise-operations)
63+ (152 strings)
64+ (156 predicate-combiners)
65+ (158 generators-and-accumulators)
66+ (175 ascii))))
vendor/purs/runtime/srfi/private/registry.slsnew file+48
@@ -0,0 +1,48 @@
1+#!r6rs
2+;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named
3+;; LICENSE from the original collection this file is distributed with.
4+
5+(library (purs runtime srfi private registry)
6+ (export
7+ expand-time-features
8+ run-time-features
9+ available-features)
10+ (import
11+ (rnrs)
12+ (purs runtime srfi private registry-names)
13+ (for (prefix (purs runtime srfi private platform-features) platform-)
14+ run expand))
15+
16+ (define-syntax make-expand-time-features
17+ (lambda (_)
18+ (define (SRFI-names x)
19+ (define number car)
20+ (define mnemonic cdr)
21+ (define (make-symbol . args)
22+ (string->symbol (apply string-append
23+ (map (lambda (a)
24+ (if (symbol? a) (symbol->string a) a))
25+ args))))
26+ (let* ((n-str (number->string (number x)))
27+ (colon-n (make-symbol ":" n-str))
28+ (srfi-n (make-symbol "srfi-" n-str))
29+ (srfi-n-m (apply make-symbol srfi-n
30+ (map (lambda (m) (make-symbol "-" m))
31+ (mnemonic x)))))
32+ ;; The first two are recommended by SRFI-97.
33+ ;; The last two are the two types of SRFI-97 library name.
34+ (list srfi-n
35+ srfi-n-m
36+ `(srfi ,colon-n)
37+ `(srfi ,colon-n . ,(mnemonic x)))))
38+ (let ((s (apply append (map SRFI-names SRFIs)))
39+ (h (platform-expand-time-features))
40+ (o '(r6rs)))
41+ #`(quote #,(datum->syntax #'ignored (append s h o))))))
42+
43+ (define expand-time-features (make-expand-time-features))
44+
45+ (define run-time-features (platform-run-time-features))
46+
47+ (define available-features (append run-time-features expand-time-features))
48+)