Last active
February 1, 2023 03:11
-
-
Save wilbowma/94e935d7276ba2b7ef5ba2bc28daf447 to your computer and use it in GitHub Desktop.
A library for set!-ing numbers. You shouldn't use this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) |
Seems reasonable; added. Not sure how to get for
to use this new interpretation of numbers as sequence by default, though...
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
This is excellent!
I feel it would be even better if numbers could --- seeing as how
sequence?
already turns true -- behave as a sequence of digits. Perhaps octal digits?A few more features like this, and I believe Racket could really hold its own in the stand-up WAT talk competition.