git @ Cat's Eye Technologies Decoy / master lib / decoy / map.scm
master

Tree @master (Download .tar.gz)

map.scm @masterraw · history · blame

; maps

; SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
; For more information, please refer to <https://unlicense.org/>
; SPDX-License-Identifier: Unlicense

(define module "maps")

(import-from "list" (null?))


(define new-map (lambda ()
  (list)
))

(define set (lambda (key val map)
  (cons (list key val) map)
))

(define get (lambda (key map)
  (cond
    ((null? map) (error "No such key"))
    ((equal? (car (car map)) key) (car (cdr (car map))))
    (else (get key (cdr map))))
))

(define update (lambda (key fn map)
  (set key (fn (get key map)) map)))