Skip to content

Instantly share code, notes, and snippets.

@shegeley
Last active May 26, 2024 05:57
Show Gist options
  • Save shegeley/d42e737b7d758c3ec7fb6e9918abe81b to your computer and use it in GitHub Desktop.
Save shegeley/d42e737b7d758c3ec7fb6e9918abe81b to your computer and use it in GitHub Desktop.
Guile Scheme SRFI-125 packaging attempt
(use-modules
(guix gexp)
(guix download)
((guix licenses) #:prefix license:)
(guix packages)
(guix git-download)
(guix download)
(guix utils)
(guix build-system guile)
(gnu packages guile)
(gnu packages guile-xyz)
(gnu packages package-management))
(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))))
guile-srfi-125
@shegeley
Copy link
Author

shegeley commented May 25, 2024

Problem: won't see the new (srfi srfi-125) modules with guix shell -f srfi-125.scm guile -- guile or guix build -f srfi-125.scm.

<shegeley@zone51:~/>
zsh/2 708  (git)-[main]-% guix shell -f srfi-125.scm guile -- guile
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,m (srfi srfi-125)
scheme@(srfi srfi-125)> ,b
scheme@(srfi srfi-125)>

⬆️ means empty module, no bindings


Works fine launching from the guix build -f srfi-125.scm directory:

<shegeley@zone51:/gnu/store/dqcf9i5njn5b2r50m8xm82l5i7sj8fa3-guile-srfi-125-1/share/guile/site/3.0/srfi>
zsh/2 706 [1] % guile -l 125.body.scm -l 125.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /gnu/store/dqcf9i5njn5b2r50m8xm82l5i7sj8fa3-guile-srfi-125-1/share/guile/site/3.0/srfi/125.scm
WARNING: (srfi srfi-126): imported module (rnrs hashtables) overrides core binding `symbol-hash'
;;; compiled /home/shegeley/.cache/guile/ccache/3.0-LE-8-4.7/gnu/store/dqcf9i5njn5b2r50m8xm82l5i7sj8fa3-guile-srfi-125-1/share/guile/site/3.0/srfi/125.scm.go
GNU Guile 3.0.9-0.3b76a30
Copyright (C) 1995-2024 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,m (srfi srfi-125)
scheme@(srfi srfi-125)> ,b
hash-table=?            #<variable 7f8ec97e4de0 value: #<procedure hash-table=? (value-comparator ht1 ht2)>>
...
scheme@(srfi srfi-125)>

Also works fine when launching from the source directory.

@shegeley
Copy link
Author

FIXED! ✅
It has to be

(rename-file "srfi/125.sld" "srfi/srfi-125.scm") 

not

(rename-file "srfi/125.sld" "srfi/125.scm")

@shegeley
Copy link
Author

Changed the gist source.

@shegeley
Copy link
Author

Examples using srfi-125:

(use-modules
 (scheme char)
 (srfi srfi-125)
 (srfi srfi-128))

(alist->hash-table `((a . 1) (b . 2)) equal?)

(hash-table=? (make-default-comparator)
 (alist->hash-table `((a . 1) (b . 2)) equal?)
 (alist->hash-table `((b . 2) (a . 1)) equal?))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment