
Hi, I wrote a parser combinator library in Racket and parsed Scheme (r5rs) successfully by this library. https://github.com/chansey97/parsing-rkt
Although it is not very useful to implement a LISP parser in Racket, it is still an interesting journey for me. Thanks to every person who helped me here.:smile:

Is there a simple way to get a byte from the reader? I can get a bunch of types by typing #"bytes". Now if I want to match a particular byte to see if it is the first element in #"b" what should I do? (match byte [#"b" "GOOD"])
is not it…

@maueroats #"b"
is a byte string, not a byte

the first element of #"b"
is 98.

And (bytes-ref #"foo" 0)
will get the first byte.

But if you are only peeking one byte/char at a time, take a look at peek-byte or peek-char.

What is a good way to make a lookup table (hash table or match statement) for these things? It sounds like I should use chars not bytes and type #\b
?

I think you just need to use numbers

#barf
. Good to know, though.

What do you want to write for bytes that don’t correspond to individual latin characters?

It would be pretty easy to write a match expander that made the pattern (byte #"b")
match 98
.

But then the way to match 150 is (byte #"\226")

I think I’m going to do (match (bytes x) [ #"b" (whatever)] [#"c" (whatever else)])
. I’ll learn about match expanders later.


I have two files, A & B. A needs to use some functions in B and vice versa. In the past, I’ve moved functions into separate files to get around the “cycle in loading” issue, but I’m wondering if there might be other options that I’m unaware of - possibly via fancy use of modules ?

In this particular case, A is already requiring B, and B only needs to use one function in A, and that function doesn’t use any other bindings in A, so in theory it seems like B should be able to “cherry pick” that one function.

You can put it in a sub-module of A, then lazy-require it in B.

A.rkt #lang racket
(require "B.rkt")
(g 123)
(module a racket (provide f) (define (f x) x))

B.rkt #lang racket
(require racket/lazy-require)
(lazy-require [(submod "A.rkt" a) (f)])
(f 456)
(define (g x) (f x))
(provide g)

You shouldn’t even need lazy-require in that case

Well, maybe not

Presumably since B could export module
, it shouldn’t work, right?

What you don’t need is to put in a sub-module, since lazy-require
trusts you. But it’s safer, since it will prevent certain dynamic cycles.