racket/match
library include pattern matching that can use arbitrary predicates with a pattern ?
. Along with and
, you should be able to make the Racket token behave. Although I'm a little weak in my OCaml, I think the following translation of the above code matches its meaning:
(define (my-read
Pairing ?
has an implicit and
built into it, so the code can be expressed a little more succinctly, like:
(define (my-read
In both cases, the lambdas do not look there, which corresponded, so I just called them _
to denote non-exit. But you can imagine more complex models where predicates could take deep care of what exactly matched.
Eli suggests using a generic cond
here, as there is no meaningful pattern matching in the code. I agree. The code will look like this:
(define (my-read
source share