The point of this small libriary is to mimic clojure’s basic operations on data structures with guile scheme as close as possible because author find them usefull and miss them a lot using Guile Scheme.
The structures are:
- vector [clojure] <-> vector [scheme]
- hash-map [clojure] <-> srfi-125* hash-table [scheme]
- atom [clojure] <-> ice-9 atomic [scheme]
The operations are:
- get, get-in (vector, hash-table)
- assoc, assoc-in (vector, hash-table)
- update, update-in (vector, hash-table)
- ref, swap!, reset! (atomic)
- bonuses:
- clojure-alike hash-table printer (it’s enabled by default when requiring
(clojureism)
module)
- clojure-alike hash-table printer (it’s enabled by default when requiring
The main difference is that in get/get-in procedures #f
will be returned instead of nil
.
Caveat: clojureism
depends on srfi-125 (which depends on srfi-126) that’s still not in guix upstream. I’m working on it.
Options:
git clone
this directory and domake install
- Add this to your system configuration as a package:
(use-modules
(gnu packages guile)
((guix licenses) #:prefix license:)
(guix build-system guile)
(guix download)
(guix gexp)
(guix git-download)
(guix packages)
(guix utils))
(define-public guile-srfi-126
(let [(commit "f480cf2d1a33c1f3d0fab3baf321c0ed5b5eb248")
(revision "0")]
(package
(name "guile-srfi-126")
(version revision)
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/scheme-requests-for-implementation/srfi-126")
(commit commit)))
(file-name (git-file-name name version))
(modules '((guix build utils)))
(snippet
'(begin
(delete-file-recursively "r6rs")
(delete-file "srfi/126.sld")
(delete-file "srfi/126.sld.in")
(delete-file "srfi/:126.sls")
(delete-file "srfi/:126.sls.in")
(delete-file "test-suite.body.scm")
(delete-file "test-suite.r6rs.sps")
(delete-file "test-suite.r6rs.sps.in")
(delete-file "test-suite.r7rs.scm")
(delete-file "test-suite.r7rs.scm.in")
#t))
(sha256
(base32 "18psw8l798xmbv2h90cz41r51q1mydzg7yr71krfprx5kdfqn32q"))))
(build-system guile-build-system)
(native-inputs (list guile-3.0))
(home-page "https://github.com/scheme-requests-for-implementation/srfi-126")
(synopsis "SRFI 126: R6RS-based hashtables")
(description "The utility procedures provided by this SRFI in addition to the R6RS API may be categorized as follows:
- Constructors: alist->eq-hashtable, alist->eqv-hashtable, alist->hashtable
- Access and mutation: hashtable-lookup, hashtable-intern!
- Copying: hashtable-empty-copy
- Key/value collections: hashtable-values, hashtable-key-list, hashtable-value-list, hashtable-entry-lists
- Iteration: hashtable-walk, hashtable-update-all!, hashtable-prune!, hashtable-merge!, hashtable-sum, hashtable-map->lset, hashtable-find
- Miscellaneous: hashtable-empty?, hashtable-pop!, hashtable-inc!, hashtable-dec!")
(license license:expat))))
(define-public guile-srfi-125
(let [(commit "8f4942f0612b6cc6af56fc90146afcccfe67d85f")
(hash "11fzpsjqlg2qd6gcxnsiy9vgisnw4d0gkh9wiarkjqyr3j95440q")
(revision "1")]
(package
(name "guile-srfi-125")
(version revision)
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/shegeley/srfi-125")
(commit commit)))
(sha256 (base32 hash))
(snippet '(begin
(rename-file "srfi/125.sld" "srfi/srfi-125.scm")
(delete-file "tables-test.sps")
#t))))
(build-system guile-build-system)
(inputs (list guile-3.0))
(propagated-inputs (list guile-srfi-128 guile-srfi-126))
(home-page "https://github.com/scheme-requests-for-implementation/srfi-125")
(synopsis "SRFI 125: Intermediate hash tables")
(description "The procedures in this SRFI are drawn primarily from SRFI 69 and R6RS. In addition, the following sources are acknowledged:
- The hash-table-mutable? procedure and the second argument of hash-table-copy (which allows the creation of immutable hash tables) are from R6RS, renamed in the style of this SRFI.
- The hash-table-intern! procedure is from Racket, renamed in the style of this SRFI.
- The hash-table-find procedure is a modified version of table-search in Gambit.
- The procedures hash-table-unfold and hash-table-count were suggested by SRFI 1.
- The procedures hash-table=? and hash-table-map were suggested by Haskell's Data.Map.Strict module.
- The procedure hash-table-map->list is from Guile.
The procedures hash-table-empty?, hash-table-empty-copy, hash-table-pop!, hash-table-map!, hash-table-intersection!, hash-table-difference!, and hash-table-xor! were added for convenience and completeness. ")
(license license:expat))))
(define-public clojureism
(let [(version "0.0.2")
(hash "0pjr0m937kz1skx1yivwnpjfqg3jppsv19pyzlfd6skcs0dq6790")]
(package
(name "clojureism")
(version version)
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/shegeley/clojureism")
(commit (string-append "v" version))))
(sha256 (base32 hash))))
(build-system guile-build-system)
(arguments (list #:source-directory "src"))
(propagated-inputs (list guile-srfi-125))
(native-inputs (list guile-3.0))
(synopsis "Small guile scheme libriary to provide clojure-alike atom, vector and hash-map basic procedures")
(description "The point of this small libriary is to mimic clojure's basic operations on data structures with guile scheme as close as possible.
Structures correspondence: vector [clojure] <-> vector [scheme], hash-map [clojure] <-> srfi-125 hash-table [scheme], atom [clojure] <-> ice-9 atomic [scheme].
Operations: get, get-in (vector, hash-table); assoc, assoc-in (vector, hash-table); update, update-in (vector, hash-table); ref, swap!, reset! (atomic).
Bonus: clojure-alike hash-table printer.")
(license license:gpl3+)
(home-page "https://github.com/shegeley/clojureism"))))
See tests
directory
Guile Scheme has at least 3 hash-tables realizations:
- built-in
- (hoot hashtables)
- srfi-69
- srfi-125
Srfi-125 one is the most advanced. at least it has built’in hash-table comparator hash-table=?
, while others don’t. That’s why it was chosen for the hash-table. Other ones can be added in next versions.