
traversal composition! :tada:

@juzhenliang has joined the channel

subtraversals!

Pretty neat.

thanks! I’m glad I finally got around to making this, I’ve wanted it for years

a cute example: #lang racket
(require glass/traversal)
(define words (list "hello" "darkness" "my" "old" "friend"))
(define first-letters
(traversal-pipe list-traversal (subtraversal string-traversal 0 1)))
(traversal-map first-letters words char-upcase)
outputs: '("Hello" "Darkness" "My" "Old" "Friend")

I just installed 7.8 BC after initially running 7.8 CS. I expected to have to reinstall/recompile my downloaded packages, but that doesn’t appear to be the case. How is that so?

From what I gather .zo files are bytecode files, which Racket CS did seem to create in my .racket packages directories. I thought Racket CS compiled to native code though. Does it use bytecode as an intermediate step? Are the .zo files compatible between CS and BC? Does CS even compile to native code like I thought?

Looking at the distribution’s compiled packages I see that the CS .zo files are larger, which matches my expectations. Just wondering what is going on with my side-by-side installation of CS and BC.

So it looks like .zo files are native code for CS. What is the best approach to running CS and BC side-by-side? Is there a way to keep both the CS and BC compiled objects without them overwriting each other?

Regarding embedded DSLs, I know it’s possible to define a custom reader but I’m not sure if Racket supports delegating to other readers since a DSL might have different syntax. For example, something like (#range [0, 3))
. If this is possible I’d be really interested in knowing the approach used to accomplish this.

Maybe you can use a read-table?
https://docs.racket-lang.org/reference/readtables.html?q=reader-macro

It allows you to “parse a datum that starts with #” with a custion reader.

That definitely looks to be on the right track with things. I’d have a really hard time understanding how to apply that to something like SQL though.

Do you want to do something like this. : https://docs.racket-lang.org/2d/index.html?q=2d\|https://docs.racket-lang.org/2d/index.html?q=2d ?

That looks exactly like what I’m trying to do.

Reader macros needs a “trigger”, so one could, say, use #sql as a trigger and write: #sql"select customer from subscribers" Reader macros are best for single datums. If you need more control, you need something more advanced.
Consider for example Alex Knauth’s multi-file-lang
which allows you to change language in the middle of a file.
https://github.com/AlexKnauth/multi-file-lang/tree/master
(you can probably get some tricks by looking at the source)

database.query(#sql {
SELECT *
FROM Languages
WHERE name = $name
});

There’s the example I’m building off of; pardon the lack of parens lol xD

In your example, the reader macro can spot #sql and using {} it can find the start and end. The missing piece is a parser for sql syntax - and there are multiple ways of writing such a parser (one way is to use parser-tools
).

Yep. Right now I’ve hacked things a bit by using the braces and indentation to get a raw string and go from there. Will try delegating to the lexer directly at some point.

One way is to set PLTCOMPILEDROOTS
to a BC- or CS-specific absolute directory path when running. That will put “.zo” files in the specified directory, shadowing the subtree of the filesystem that would otherwise have “.zo” files.

Thanks. That should help. I was a little confused why some of my code ran out of the box when I switched to BC. I have a local package that I manage with ‘raco setup’. When I built my app which depends on it, it seems like it recompiled the package automatically. It also seems like it recompiled any other dependencies it needed transparently. But only the .zo files it actually needed. I guess that is why I was confused.

It seems like everything just worked when I switched, which wasn’t what I expected!

Yes, raco setup
and raco make
will compile dependencies. Glad to hear that things work when they should!

Is there an easy way to fix this problem when running redex
on a headless machine? $ racket
Welcome to Racket v7.7.
> (require redex)
Unable to init server: Could not connect: Connection refused
; Gtk initialization failed for display ":0" [,bt for context]

you can start the X Virtual Frame buffer (xvfb). Starting it is platform specific, so you will have to look up the details for your platform

Thanks! I’d rather try to fix it on Redex side, honestly. Could you think of how to even trace this? I searched Redex sources and the most popular source of this problem (require plot
) is not there: they seem to correctly use require plot/no-gui
. So it’s some other dependency, I guess…

actually, xvfb
seems to work fine, thanks!

I think redex/reduction-semantics
is the layer that works without racket/gui
.