
@sorawee Do you happen to use dynamic-require
?

Hi all, sorry of this has been asked recently, but I have a student working on a small webapp in Racket that will exchange JSON back and forth with a client-side JS app. Does anyone have a favorite web framework in Racket for this kind of work?

@krismicinski Have you looked at koyo
? https://docs.racket-lang.org/koyo/json.html?q=koyo


Hey @mflatt and @robby the arrows in DrRacket are a bit..err…broken.

As in, they fade out after a short while.

Here is an example:

They reappear at the other end, but there’s a large chunk in the middle where they are invisible.

Oh, this is also on Ubuntu. I tried it also on @ben’s laptop and the arrows worked fine there.

Which makes me think this is a mred or racket/gui problem, rather than a DrRacket problem. But I’m not 100% sure of that.

Also, short arrows show up fine. Its only longer ones that have this issue.

Or maybe an ubuntu problem?

Hard to say without some work on it, for sure

I mean, ya, it could be an ubuntu problem.

I guess the best way to test that is to use another OS that racket still uses gtk for.

I’m prototyping a #lang
that allows embedded #lang
s in a Scribble reader. Implementation here: https://github.com/zyrolasting/polyglot/blob/inline-modules/polyglot-lib/polyglot/main.rkt#L19
Here’s an example snippet.
#lang polyglot
@mod['what]{
#lang racket/base
(provide out)
(define out 1)
}
@require['what]
@out
It works in DrRacket, but not using the racket
CLI launcher. In the latter case, I see the reader invoked 6 times, with an error complaining that 'what
was not found in the interim. Why does the behavior differ this much between the two environments?

Possibly it’s because of errortrace being on in DrRacket

I understand errortrace adding behavior, but changing it? What can I do to make the #lang
behave consistently if instrumentation is disabled?

Well first figure out if that’s it. Probably by turning the debugging settings off in DrRacket

Applied these settings. The behavior is consistent, in that it still works only in DrRacket.

This is 7.6 CS, btw

I see a scary (eval
(require …) ns)` expression

Would that cause the error?

I am really unsure But eval require
like that depends on certain (runtime) parameters like <https://docs.racket-lang.org/reference/eval.html?q=current-load-rel#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29\|current-load-relative-directory
, which are fragile>

DrR and Racket CLI are two pretty different implementation of REPL

as far as I understand, DrR does something like evaluating the expression inside a module’s namespace, using module->namespace


while Racket CLI runs things at the hopeless top-level

If you can obtain the absolute path, there are options like (require (file "absolute path"))

I already use an absolute path in the case of an rcfile.

If you are sure that module is going to be in some fixed relative position w.r.t. to the main module, there is define-runtime-module-path

The one that’s reporting an error is a module declared by expanding a module form from a user string.

Hmm, then current-load-relative-directory should not affect things

ah.. That’s definitely going to be interpreted differently

That example snippet above… The 'what
module is what fails to load.

oh I see where is what

But again, only in the CLI launcher. What else differs?

what
is declared immediately above the require
in the snippet.

sorry, let me read it more carefully

I’ll simplify it. The error reproduces in this case too.
#lang polyglot
@(module what racket/base (provide out) (define out 1))
@(require 'what)
@out

That is, works in DrRacket but not elsewhere.

What do I need to install? I got standard-module-name-resolver: collection not found
for module path: polyglot/lang/reader
collection: "polyglot/lang"

Another piece of code I tried work: ;; ilm.rkt
#lang racket/base
(provide (all-defined-out))
(define ns (make-base-namespace))
(define (eval-for-each stx)
(define enriched-stx (namespace-syntax-introduce stx ns))
(for ([each-stx (in-list (syntax->list enriched-stx))])
(eval-syntax each-stx ns)))
#lang racket/base
(require "ilm.rkt")
(eval-for-each
(datum->syntax
#f
'(
(module what racket/base (provide out) (define out 1))
(require 'what)
(displayln out)
))
)

What if you use command-line racket, but then use the xrepl command ,enter main.rkt
to run. IIRC that does a module->namespace
. Maybe interesting if you want to confirm that is the element that DrRacket is contributing.

OTOH I remember seeing where that (eval E ns)
and (parameterize ([current-namespace ns]) (eval E))
are different..some module registry thingy

(It’s late and my brain is tired, but quick glance at that code, it feels like you’re re-inventing various things that the Racket module system does, which isn’t necessarily bad, but gets you into unusual territory. Like, quick/shallow glance, I’m not sure why you couldn’t rely more on plain old dynamic-require
? But idk, really.)

“unusual territory” meaning there are probably dozens of details like what @shu—hung mentioned about setting the current-namespace, etc.

Which could be fun to learn about! But could be a detour from what you’re trying to do.

Anyway sorry for the tired free advice. It does look cool!

If it turns out it work in DrRacket because of module->namespace
, you might be able to make it work more generally by using define-namespace-anchor
to get the namespace “in” your main.rkt module. Instead of using make-base-namespace
.

Just a rough guess.

@greg Is there already a way to embed a #lang
in a textual language that doesn’t involve a third party package?

@shu—hung You can install the package locally using raco pkg install --link
after cloning the repository.

,enter
on the #lang polyglot
module reproduces the error, so I guess that means missing module->namespace
wasn’t an issue.

Oh, and @greg, using racket-run
in racket-mode
is the only case in which I see several applications of the reader. In both DrRacket and racket
, the reader is called once. But when using racket-run
, it is called 4 times!
mkup.rkt>
Entering run-markup
Entering run-markup
; require: unknown module
; module name: #<resolved-module-path:'what>
; Context:
; /home/sage/Code/polyglot/polyglot-lib/polyglot/main.rkt:76:7 for-loop
; /home/sage/Code/polyglot/polyglot-lib/polyglot/main.rkt:42:2 run-markup
; /home/sage/Code/polyglot/polyglot-lib/polyglot/main.rkt:33:2 markup-read-syntax
Entering run-markup
; [Due to errors, REPL is just racket/base]
Entering run-markup
mkup.rkt>
Maybe there’s a clue there?

In any case, clearly something about how I wrote this code makes it so that it behaves differently depending on what starts it.

Not sure what, but I’ll reread the docs and see what I can figure out.

My suspicion is that the module registry for the wrong namespace was updated, even though that module was eval
’d on the custom namespace.

Racket Mode has a “retry as skeleton” feature that, when evaluating the module results in an error, retries it just for bindings (just requires and defines) so that completions are available while you edit to fix the error. This is N/A on the upcoming check-syntax
branch, since it is able to get completion candidates by fully expanding (not evaluating). I’m not immediately sure why you’re seeing 4X instead of 2X, I’d need to fully understand your program and do some research.
