Hi, Racket Discourse.
I wanted to try my hand at writing a reader macro extension, which was less intimidating than I thought it would be.
The result works, but I am curious where I would implement custom syntax colours for such macros. I have had a quick look at the info.rkt
for the Dracula theme, for example, but it's not clear to me where, if at all, this modification would fit.
#lang reader "iverson-racket.rkt"
;; I recently encountered the "Iverson Bracket" again, and
;; it seemed like an easy goal to try and implement (so named after the "Kronecker delta")
(define ≤ <=)
(define (Max x y)
(+ (* x #δ(> x y))
(* y #δ(≤ x y))))
(define (Min x y)
(+ (* x #δ(≤ x y))
(* y #δ(> x y))))
(define (Sgn x)
(- #δ(positive? x)
#δ(negative? x)))
(Min 1 2) ;=> 1
(Max 1 2) ;=> 2
(Sgn 100) ;=> +1
(Sgn -20) ;=> -1
(require
math/number-theory)
(define (φ n)
(for/sum ([i (in-range 1 n)])
#δ(= 1 (gcd n i))))
(φ 11) ;=> 10
At the moment, #δ
is coloured red, like so:
P.S. for the curious reader (haha):