

Thank you @ryanc! Woah, I wasn’t expected such a bug in a anything related to the compiler! Sounds like compile-directory-zos isn’t that much used.

I’ve also tried multiple versions of the make-evaluator
, all of which fail with the same error. (make-evaluator 'racket/base '(test) #:requires '(test))
(make-evaluator 'racket/base '(test) #:allow-for-require '(test))
Error: standard-module-name-resolver: collection not found
for module path: efuns
collection: "efuns"
in collection directories:
C:\Program Files\Racket\collects

The compile-directory-zos
function is used by raco setup
, and maybe the problem is that the function drifted too much toward specifics of raco setup
: the skip-paths
arguments are always directories, and info
is always the same as reading the info.rkt
file, while omit-paths
needs to be able to check multiple directories (parent and maybe child? I forget exactly) to gather al of the omitted paths.

Adjusting the skip-paths
treatment to allow exact matches seems fine. It might make sense to use info
in place of reading info.rkt
in the immediate directory, or maybe a non-#f
info
should disable info.rkt
reading; I’m not sure on that.

I think part of the problem is that make-evaluator
needs a quoted module name, so if you’d use 'test
with require
, then you need ''test
for `make-evaluator (two quotes). I’m probably missing some other pieces, though.

Yeah. been trying lots of things, and just can’t get the evaluator to see the module at all. Double quotes results in require: unknown module
, which is at least an improvement in that it isn’t searching for it on disk any more.

Since test
starts out declared in the current namespace, with no other way to get to it, you need to set sandbox-namespace-specs
to attach it to the sandbox’s namespace, something like this: (parameterize ([sandbox-output current-output-port]
[sandbox-namespace-specs (append (sandbox-namespace-specs)
'('test))])
....)

Ok. that makes sense. So, that should mean (I’d think), that the following would work, but it doesn’t: (require racket/sandbox)
(module test-mod racket/base
(provide test)
(define (test)
(display "Hello, world!")))
(define namespace-spec (list make-base-namespace ''test-mod))
(parameterize ([sandbox-output current-output-port]
[sandbox-namespace-specs namespace-spec])
(make-evaluator 'racket/base '(test)))
But, it errors with module name: #<resolved-module-path:'test-mod>
.
To be honest, this is starting to drive me a bit nuts. I don’t know if what I want is possible (or if there’s an easier way to do it), but what I want is to just expose a few functions from my project to some “scripts” that will be executed at runtime within a sandboxed directory. For example:
(define (load-data) #\| makes use of this module's environment \|#)
(define (save-results) #\| makes use of this module's environment \|#)
(module* exposed-functions #f
(provide load-data save-results))
(define (run-script filename)
(parameterize ([sandbox-... ...])
(make-evaluator 'racket/base `(load ,filename) '(run) #:requires '(exposed-functions))))
The above is obviously wrong, but I just can’t seem to get the loaded script to have access to the functions I want them to be able to call. :disappointed:

Is the code above in a module? If so, test-mod
is a submodule of the enclosing module, so you can’t refer to it dynamically with 'test-mod
(in much the same way that (let ([x 5]) (eval 'x))
doesn’t work, because eval
doesn’t know about local context). You’ll need a submod
path to reach the module.

And when you use a submod
path, if it extends a module path that can be loaded into other namespaces, then maybe you won’t need to change namespace-spec
.

The last bit is - in the end- what I’m hoping for. I can’t even get a basic module to work, though.

The old list (Mailman?) worked well for me. I receive the digest. Under GG, I don’t see full messages in my mailbox. I have to click to open a browser window. Half the time it wants me to sign into my Google account (I have to click carefully to avoid this). I don’t know how to reply without signing in. Here’s what I would like, and it may not be possible: to see the full content of any message (not attachments) in the digest (mind you, if everyone top-posts, then digests are useless also, especially if people top-post on the DIGEST) and to be able to selectively quote and respond without having some major corporation tracking me.

Here’s one example, which reloads the enclosing module in the sandbox namespace: #lang racket/base
(require racket/sandbox
syntax/modresolve)
(module test racket/base
(define (test) 'ok)
(provide test))
(define test-submod
(resolve-module-path-index
(module-path-index-join
'(submod "." test)
;; get a reference to the enclosing module
(variable-reference->module-path-index (#%variable-reference)))))
(define e
(make-evaluator 'racket/base
;; Tell the sandbox that it's ok to load the enclosing file:
#:allow-for-require (list test-submod)))
(e `(namespace-require ',test-submod))
(e '(test))

Here’s another example, which uses the current instance of the submodule: #lang racket/base
(require racket/sandbox
syntax/modresolve)
(module test racket/base
(define (test) 'ok)
(provide test))
(define test-submod
(resolve-module-path-index
(module-path-index-join
'(submod "." test)
;; get a reference to the enclosing module
(variable-reference->module-path-index (#%variable-reference)))))
(define e
(parameterize ([sandbox-namespace-specs (append (sandbox-namespace-specs)
(list test-submod))])
(make-evaluator 'racket/base)))
(e `(namespace-require ',test-submod))
(e '(test))

The old list was indeed Mailman, and we are extremely unlikely to go back to something self-hosted. It sounds like you might have the “abridged” setting on, rather than “digest”.

As for top-posting, I think that’s not going to go away.

tyvm, ill study these :slightly_smiling_face:

hello, I’m trying to make a CRUD REST api cooperate with a sqlite database for a small application. I’m basing the CRUD on this <https://lisp.sh/crud-web-api-in-racket/|CRUD web api in Racket> . There’s this line in the db module that bothers me <https://docs.racket-lang.org/db/notes.html#%28part._ffi-concurrency%29|FFI-Based Connections and Concurrency> . Basically it says that all racket threads get blocked when a query is being executed… I suppose that means that the server could miss incoming POST/GET requests and not handle them…
It offers a solution though, the connection can use a place for queries, what I don’t understand is how does this works. You can pass a boolean to #:use-place
, I made some tests with query-rows and threads and basically it works as normal… But what if a sql query is already getting processed while a new request comes in? I suppose I have to use something like a semaphore? or sync? I’m lost… I haven’t manipulated databases and web servers much, so I’m still a noob and also I guess this questions overlap with racket only in how to proceed with the implemented parts (places and db connections). Finally, is there a channel to ask for help that isn’t beginners? Or do I just post it in general?
Edit 1: I have the understanding that sqlite can only have one connection to the database.


My thinking is, that the simplest is to switch to a wire-based connection. I.e. use MySQL, PostgreSQL or Cassandra.

I see. I’ll investigate on that.

But you could measure how long your queries take - maybe they are so fast, that it isn’t a problem?

mmm… i thought about that possibility…

The place solution works like this: Think of a “place” as an instance of Racket running in separate OS thread. (I think of it as a convenient way of running two instances of Racket at the same time). One place runs the db queries and the other is your current web-server. Now instead of running the db query directly, your web-place must send the query over to the other place and get an answer back.

oh i did think about using places like that. but i dont get the #:use-place
from the sqlite3-connect function. where does this place reside, and how do my queries still work without changing anything of my code? edit: #:use-place
that receives a boolean which is the most puzzling to me.

raw calls to things like query-exec and query-rows work just fine in the test code i made.

Good question.

The docs of sqlite3-connect
says: If use-place is true, the actual connection is created in a distinct place for database connections and a proxy is returned; see FFI-Based Connections and Concurrency.

So it returns a proxy connection. Maybe it is as simple as writing #:use-place #t
?

i… see but i still have to coordinate my queries i suppose

@cris2000.espinoza677 If you create the database connection with #:use-place #t
, then it automatically creates the other place and handles the communication of queries and results between the new place and the original. You shouldn’t have to worry about any of that; just use the connection normally. You just get a connection where each query is a bit slower (because of the communication overhead) but where a query no longer blocks other threads on in the original place.

@ryanc oh thank you. but since i use only one connection (as sqlite has limit for only one) and im going to make a crud that handles incoming connections in different threads, i have to sync those queries so it doesnt interrupt an ongoing query right?

No, connections are thread-safe. That is, they have internal synchronization, so if the connection is already executing a query in one thread and you call a query function in another thread, the second call will just block until the connection finishes the first query.

Also, sqlite3 can handle multiple connections to the same database. It works fine for multiple simultaneous readers. If you have multiple writers (or writers and readers together), then you start getting conflicts, and you would have to retry queries when they fail because of concurrent access.

OOHH thank you, that was just what I needed to know! thanks @soegaard2 @ryanc you really helped me!

I see, I didnt knew that about sqlite3.

Sure, I’m glad I could help.

With reference to this discussion on reddit/r/racket :
Does https://github.com/racket/racket/blob/master/pkgs/racket-doc/scribblings/guide/macros.scrbl need to be updated to link to the syntax parse introduction https://docs.racket-lang.org/syntax/stxparse-intro.html ?
What should it say?
> Robust macros can be written with syntax-parse and syntax classes. Does the Style Guide need a section for macros in the spirt of https://docs.racket-lang.org/style/Choosing_the_Right_Construct.html#%28part._.Functions_vs_.Macros%29 (That indicates) When to use syntax-rules
, -case
or -parse
?

FWIW this is what a digest from Discourse looks like:

I see, thank you. Either option seems fine to me, although the last one has a more general feeling to it maybe.

@sorawee one thing that concerns me about Discourse is the export is specifically to another discourse instance not mbox or other general format. Once you are committed to discourse you cant leave (without a major migration effort, or more likely abandoning your data).

@mflatt Thanks! This was able to get me going! A question if you don’t mind:
• What’s the purpose of the variable-reference->module-path-index
and #%variable-reference
?

@plragde :point_up_2:

That combination obtains the identity of the surrounding module. In your program, you may know a simpler way to reference the module, such as a plain module path.

@samth Thank you for the tip on settings. I was migrated from Mailman to GG and I had no idea this setting existed. That will help (also perhaps I can reply in my mail client now, with a bit of header-munging).

I changed skip-paths
so that “starts with” includes an exact match, and I made an info
argument disable all info.rkt
files.

Question: why don’t the contract’s symbols appear as hyperlinks in the scribblings docs I made?

It’s very likely that (require (for-label racket/contract))
will fix the problem.

But it really depends on what contract’s symbol you are talking about

Most contracts are defined in racket/contract
, that’s why I suggest you to try the above code first.

But if that fails, then you need to figure out where that contract is from, and require it for-label
.

nono it does work thank you!