
this looks interesting, but I don’t know what reader is. Is this the right thing I am looking for? https://docs.racket-lang.org/guide/hash-lang_reader.html

https://lisper.in/reader-macros — This is Common Lisp, but a good example of how powerful it is. You basically have access to the lexer at compile-time and can modify it to do other things at “read time”.
With Racket take a look at https://docs.racket-lang.org/reference/reader.html. Racket uses the #lang
to let you completely override the entire reader with one of your own. Think of it as a very powerful lex/yacc that converts whatever your language is back into valid Racket code.

For Racket I really feel like there ought to be a very easy way to do this with a custom readtable and reading exception messages, but getting it so that <
matches only >
so far seems to make it more trouble than it’s worth

I’ve never used readtables before though so I might be missing something.

Not sure how far you’ve gotten (or finished), but I think w/ part 2 the read table would likely be more trouble than it’s worth.

yeah, haven’t done part 2 yet. shame though, seems like it’d be extra lispy just to have the reader do it all!


I tried the readtable first @joel but I couldn’t get the information I wanted out of exceptions when reading failed because of the imbalance.

I still have half-baked code if you want it

<https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day10/day10.rkt|Day 10 Solution>

@badkins wouldn’t https://github.com/lojic/LearningRacket/blob/master/advent-of-code-2021/solutions/day10/day10.rkt#L7 allocate a new hash every single iteration of the loop as opposed to #hash
?

not sure if racket would realize everything in is constant and work it out. if so, that’s awesome

Yes, you’re probably right :-o I usually don’t worry about such things when in puzzle mode, but in this case, there’s no reason to not use a literal - thanks!

Of course, there are many things I’d change about it if in production code :)

Yeah, depends on the optimizations. Sometimes extracting those myself makes a difference in time, at least, which I assume is correlated with memory usage in these particular cases

oh for sure. i was asking for myself to just know whether or not that’s what racket would do

Hmm… using #hash
requires cons pairs which lengthens the line and makes it less clear, so for “puzzle mode”, I think I’ll stick with (hash)

I am curious about possible optimizations - my guess would be “no”, but it’s totally a guess.

I’m going to make a more readable version, defining those hashes separately will make sense.

I suppose #hash
is immutable vs. mutable hash
, so already probably not

hash is immutable. make-hash is mutable

Here’s a (hopefully) <https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day10/day10-readable.rkt|more readable version>

Day 11 spoilers

Another fairly simple day. A couple potential gotchyas.
https://github.com/massung/advent2021/blob/main/day11/day11.lisp