chansey97
2020-7-7 09:05:40

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:


maueroats
2020-7-7 17:48:33

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…


samth
2020-7-7 17:52:07

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


samth
2020-7-7 17:52:33

the first element of #"b" is 98.


soegaard2
2020-7-7 17:53:42

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


soegaard2
2020-7-7 17:55:07

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


maueroats
2020-7-7 17:57:24

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 ?


samth
2020-7-7 17:59:07

I think you just need to use numbers


maueroats
2020-7-7 17:59:55

#barf. Good to know, though.


samth
2020-7-7 18:00:47

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


samth
2020-7-7 18:03:04

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


samth
2020-7-7 18:03:46

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


maueroats
2020-7-7 18:05:24

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


spdegabrielle
2020-7-7 20:26:13

badkins
2020-7-8 01:43:18

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 ?


badkins
2020-7-8 01:44:46

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.


gfb
2020-7-8 02:01:47

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


gfb
2020-7-8 02:03:06

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


gfb
2020-7-8 02:03:58

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


samth
2020-7-8 02:07:17

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


samth
2020-7-8 02:07:47

Well, maybe not


gfb
2020-7-8 02:08:20

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


gfb
2020-7-8 02:11:45

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.