Skip to content

Instantly share code, notes, and snippets.

@wilbowma
Last active February 1, 2023 03:11
Show Gist options
  • Save wilbowma/94e935d7276ba2b7ef5ba2bc28daf447 to your computer and use it in GitHub Desktop.
Save wilbowma/94e935d7276ba2b7ef5ba2bc28daf447 to your computer and use it in GitHub Desktop.
A library for set!-ing numbers. You shouldn't use this.
#lang racket/base
(require
(for-syntax
racket/base
syntax/parse)
(rename-in
racket/base
[#%datum old-datum]
[set! old-set!]))
(define number-map (make-hasheq))
(define-syntax (set! stx)
(syntax-parse stx
[(_ i:number v)
#'(hash-set! number-map i v)]
[(_ . stx) #'(old-set! . stx)]))
(define-syntax (#%datum stx)
(syntax-parse stx
[(_ . i:number)
#'(hash-ref! number-map (old-datum . i) (old-datum . i))]
[stx #'(old-datum . stx)]))
(module+ test
(require rackunit)
(check-equal? 5 5)
(set! 5 6)
(check-equal? 5 6))
@wilbowma
Copy link
Author

Seems reasonable; added. Not sure how to get for to use this new interpretation of numbers as sequence by default, though...

@wilbowma
Copy link
Author

Should probably add support for reals by making that sequence lazy.

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