laurent.orseau
2020-8-23 12:20:24

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.


massung
2020-8-23 12:50:32

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


mflatt
2020-8-23 12:53:07

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.


mflatt
2020-8-23 12:54:48

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.


mflatt
2020-8-23 12:59:00

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.


massung
2020-8-23 13:11:20

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.


mflatt
2020-8-23 14:57:48

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))]) ....)


massung
2020-8-23 15:47:55

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:


mflatt
2020-8-23 16:00:10

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.


mflatt
2020-8-23 16:01:22

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.


massung
2020-8-23 16:02:14

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


plragde
2020-8-23 16:02:17

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.


mflatt
2020-8-23 16:13:32

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))


mflatt
2020-8-23 16:14:02

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))


samth
2020-8-23 16:18:40

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”.


samth
2020-8-23 16:18:50

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


massung
2020-8-23 16:22:26

tyvm, ill study these :slightly_smiling_face:


cris2000.espinoza677
2020-8-23 16:52:47

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.


soegaard2
2020-8-23 16:55:16

#general is fine.


soegaard2
2020-8-23 16:56:39

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


cris2000.espinoza677
2020-8-23 16:57:21

I see. I’ll investigate on that.


soegaard2
2020-8-23 16:58:01

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


cris2000.espinoza677
2020-8-23 16:59:25

mmm… i thought about that possibility…


soegaard2
2020-8-23 17:00:11

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.


cris2000.espinoza677
2020-8-23 17:02:02

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.


cris2000.espinoza677
2020-8-23 17:02:33

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


soegaard2
2020-8-23 17:07:40

Good question.


soegaard2
2020-8-23 17:09:18

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.


soegaard2
2020-8-23 17:10:28

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


cris2000.espinoza677
2020-8-23 17:11:08

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


ryanc
2020-8-23 17:19:33

@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.


cris2000.espinoza677
2020-8-23 17:21:29

@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?


ryanc
2020-8-23 17:24:25

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.


ryanc
2020-8-23 17:26:45

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.


cris2000.espinoza677
2020-8-23 17:26:46

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


cris2000.espinoza677
2020-8-23 17:27:35

I see, I didnt knew that about sqlite3.


ryanc
2020-8-23 17:30:22

Sure, I’m glad I could help.


spdegabrielle
2020-8-23 17:40:42

With reference to this discussion on reddit/r/racket :

https://www.reddit.com/r/Racket/comments/ie8rlf/when_creating_macros_is_syntaxparse_preferred_to/?utm_source=share&amp;utm_medium=ios_app&amp;utm_name=iossmf

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?


spdegabrielle
2020-8-23 17:55:47

FWIW this is what a digest from Discourse looks like:


laurent.orseau
2020-8-23 18:38:52

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


spdegabrielle
2020-8-23 19:09:12

@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).


massung
2020-8-23 19:37:56

@mflatt Thanks! This was able to get me going! A question if you don’t mind:

• What’s the purpose of the variable-reference-&gt;module-path-index and #%variable-reference?


spdegabrielle
2020-8-23 19:46:26

@plragde :point_up_2:


mflatt
2020-8-23 19:56:55

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.


plragde
2020-8-24 00:04:22

@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).


mflatt
2020-8-24 01:43:48

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


cris2000.espinoza677
2020-8-24 04:01:43

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


sorawee
2020-8-24 04:11:56

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


sorawee
2020-8-24 04:12:12

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


sorawee
2020-8-24 04:12:43

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


sorawee
2020-8-24 04:13:04

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


cris2000.espinoza677
2020-8-24 04:13:47

nono it does work thank you!