jagen315
2021-5-8 09:36:18

How to debug colorer for #lang? All the feedback I get is the #lang line turns red


soegaard2
2021-5-8 09:39:25

One advice:

; REMEMBER to restart DrRacket to test any changes in the ; color-lexer. The lexer is only imported into DrRacket ; at startup. found in

https://github.com/soegaard/minipascal/blob/master/minipascal/mini-pascal-lexer.rkt


rp
2021-5-8 12:11:07

If I run (system “sudo whoami”) in DrRacket, I get an error because a terminal is required to read the password for sudo. Is there a simple way to make the DrRacket REPL so that it will ask me for the password? If not, perhaps I need to create run a terminal like xterm, and run the command in that?


soegaard2
2021-5-8 12:14:58

@rp Check man sudo to see if there is a suitable option available. On macOS I see one can do: -A, --askpass Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program. Otherwise, if sudo.conf(5) contains a line specifying the askpass program, that value will be used. For example: # Path to askpass helper program Path askpass /usr/X11R6/bin/ssh-askpass If no askpass program is available, sudo will exit with an error.


soegaard2
2021-5-8 12:16:37

Or perhaps: -S, --stdin Write the prompt to the standard error and read the password from the standard input instead of using the terminal device.


soegaard2
2021-5-8 12:17:47

But, maybe it is easier if you do: sudo racket your-program.rkt instead of asking for a password later?


rp
2021-5-8 12:18:05

OK, that’s great. I guess trying to turn the REPL into a “proper” tty is the wrong way to tackle this problem. I’ll have a look into the other options like you suggest.


rp
2021-5-8 12:18:14

Thanks for the suggestions - I appreciate your help.


laurent.orseau
2021-5-8 12:29:20

Also, it’s better practice to let the user type sudo themselves, which asks for the password straight away, so that they know they’re not entering their password in a random program


rp
2021-5-8 12:30:17

Laurent, that’s a good point, thanks.


jjsimpso
2021-5-8 14:23:24

Are prefab structures considered unreadable? In the past I’ve serialized them without issue, but put-preferences is complaining: “printf: printing disabled for unreadable value” EDIT: to be clear, in this case I’m not using serialize, I’m just passing a list of structs to put-preferences. I could serialize them first if that is the norm for putting structs in preferences files.


jjsimpso
2021-5-8 14:38:41

Re-reading the docs I think it is clear that prefab structs aren’t readable and I do need to serialize them first before sending to put-preferences. Is that the best approach? If there is a convention for storing data in preferences files I’d like to stick to it. Would it be better to provide a prop:cust-write function for my structs?


samth
2021-5-8 15:05:39

Prefab structs are definitely readable


ryanc
2021-5-8 15:05:55

Prefab structs are readable (and writable). See https://docs.racket-lang.org/reference/structures.html#(tech._prefab), "…can be parsed and written…". But it looks like print-unreadable (wrongly, I think) disables writing prefab struct instances, and put-preferences sets print-unreadable to #f to protect the preferences file. That looks like a bug to me.


jjsimpso
2021-5-8 15:27:34

Interesting! That is the way that I hoped it would work before I wrote the code. I have it working with serialize/deserialize for now but if it is indeed a bug, it would be nice not to have to do that.


ryanc
2021-5-8 15:33:13

I just filed a <https://github.com/racket/racket/issues/3827|bug report>. I don’t know of a workaround better than using serialize, unfortunately.


jjsimpso
2021-5-8 15:36:24

Thank you! Serializing will be fine for me until this is fixed.,


sschwarzer
2021-5-8 17:29:33

I want a function that returns a function that returns consecutive integers when called repeatedly. Here’s one possibility: (define (sequence-generator) (define count 0) (lambda () (set! count (add1 count)) count)) &gt; (define a-generator (sequence-generator)) &gt; (a-generator) 1 &gt; (a-generator) 2 &gt; (a-generator) 3 I had read about streams and thought that in-naturals would be a natural :wink: way to provide such an infinite integer sequence. But then I also noticed that if I create a stream with (in-naturals) and call (stream-first ...) on that, I always get the same number. Now I’m sure it’s supposed to work that way, but I also wonder if there’s a way to do with in-naturals in a simpler way than I’m using in my closure function above.

In other words, is there a pattern using streams to get a sequence of values on repeated calls, similar to how generators work in Python: &gt;&gt;&gt; sequence_generator = iter(range(1, 1000)) &gt;&gt;&gt; next(sequence_generator) 1 &gt;&gt;&gt; next(sequence_generator) 2 &gt;&gt;&gt; next(sequence_generator) 3 (I know that this range call doesn’t give an infinite sequence; this code is just for illustration.)


soegaard2
2021-5-8 17:31:07

I believe you can use (sequence-&gt;generator _s_) to turn (in-naturals) into a generator.


sschwarzer
2021-5-8 17:35:05

Yep, that works. Thanks! &gt; (require racket/generator) &gt; (define (sequence-generator) (sequence-&gt;generator (in-naturals))) &gt; (define my-generator (sequence-generator)) &gt; (my-generator) 0 &gt; (my-generator) 1 &gt; (my-generator) 2 &gt; (my-generator) 3 I thought that streams were already so similar to Python generators that I didn’t think of the possibility that there might be yet another concept/library for that. :slightly_smiling_face:


sschwarzer
2021-5-8 17:56:22

In the end I needed something slightly more complicated, but a generator helped here as well: (define (make-node-id-generator) (generator () (for ([i (in-naturals 1)]) (yield (format "n~a" i)))))


ben.knoble
2021-5-8 18:40:03

Otoh, if the whole program does not need sudo privileges, it should not have them…


laurent.orseau
2021-5-8 19:40:56

Won’t work if the prefab struct is mutable though, for some reason


soegaard2
2021-5-8 19:49:06

I have run into a problem. Can you spot the solution? #lang racket (require (for-syntax syntax/parse racket/syntax)) (define-syntax (cache stx) (syntax-parse stx [(_cache e:expr) (with-syntax ([cached (format-id stx "cached")]) (syntax-local-lift-module-end-declaration (syntax/loc stx (define cached #f))) (syntax/loc stx (cond [cached cached] [else (set! cached e) cached])))])) (define (foo) (cache (random 42))) (foo) (foo) I get the error “cached: unbound identifier in: cached”.


shu--hung
2021-5-8 20:33:46

I tried the macro stepper with two things to see when the lift forms are introduce: 1. Place (cache (random 42)) at module-level instead of inside (foo). 2. Expands to something like (identifier-binding #'cached)


shu--hung
2021-5-8 20:36:15

As I see the results suggest that (1) the lifted forms are introduced after all module-level forms are partially expanded (2) Lifted forms cannot introduce new module-level bindings once the partial expansion is finished

So (cache ...) inside (foo) cannot introduce a new module-level definition


shu--hung
2021-5-8 20:39:29

The expander guarantees (2) by imposing this behavior upon syntax-local-lift-module-end-declaration: > If the current expression being transformed is in <https://docs.racket-lang.org/reference/syntax-model.html?q=syntax-local-lift-module-end-declaration#%28tech._phase.level%29|phase level> 0 and not in the module top-level, then _stx is eventually expanded in an expression context.


ryanc
2021-5-8 21:07:37

Use syntax-local-lift-expression instead. You don’t get to control the variable name; the macro expander generates one for you that won’t cause problems for the rest of the module.


philip.mcgrath
2021-5-8 21:59:31

When setting up a config.rktd file with a config-tethered-console-bin-dir, what is the right thing to put for bin-dir? (I am trying to chain to an existing installation as a wider scope, as in <https://groups.google.com/g/racket-dev/c/dHAFwzlFwNA/m/xfVGxIYaAgAJ|this message>.)


mflatt
2021-5-8 22:11:36

I’m not sure I remember how this is supposed to work, but I think the idea is that a “config.rktd” in the addon space would have just the tethered entries and not others.

In case another reference helps. the relevant commit was 6369e567097866d6a65a3da32c8125131fabdd73.


mflatt
2021-5-8 22:13:06

No, I’m pretty sure I don’t remember how this was supposed to work.


mflatt
2021-5-8 22:15:36

Maybe it’s that that “config.rktd” for a sandbox area is supposed to point at all the directories that the installation would point to, plus the directories for tethered binaries. So, you’d set bin-dir to whatever the next layer’s “config.rktd” says or whatever it would default to.


mflatt
2021-5-8 22:17:26

On Nth thought, that doesn’t sound right either. Maybe it should be just some other directory that you don’t really use, because you’ll want to use the tethered ones.


philip.mcgrath
2021-5-9 00:08:20

A bogus bin-dir seems to work, in that it isn’t used, but nothing is getting written to config-tethered-console-bin-dir, either. A possible-related earlier problem is that, before I configured a new lib-dir plus lib-search-dirs, raco setup was trying to write to launchers.rktd in the original lib-dir (which failed, because the original installation is read-only). Now it is writing mans.rktd to the new lib-dir, but no launchers.rktd that I can find.


philip.mcgrath
2021-5-9 00:09:01

Specifically, I ran this command: /gnu/store/7vy0ikhd3ws5v6jydzx7aipvs4jv7rb9-racket-minimal-8.1/bin/racket \ --config /home/philip/code/tmp/racket-config-tethered/etc/racket/ \ -l raco -- setup --no-user


jagen315
2021-5-9 01:02:05

ah. as it turns out, my get-info didn’t have the right signature. I was copying it from a #lang that used syntax/module-reader, which must do some automatic wrapping


aymano.osman
2021-5-9 01:17:12

Has there been any changes to racket’s ffi between 8.0 and 8.1 cs? I have some programs that use the ffi that stopped working. They are rather complicated so I came up with an example using the pict3d library.

#lang racket/base (require pict3d) (pict3d-&gt;bitmap (sphere origin 1/2)) Error message: gl-create-program: ERROR: Compiled vertex shader was corrupt. ERROR: Compiled geometry shader was corrupt. ERROR: Compiled fragment shader was corrupt. context...: /Users/ayman/Library/Racket/8.1/pkgs/pict3d/pict3d/private/memo.rkt:83:2 /Users/ayman/Library/Racket/8.1/pkgs/pict3d/pict3d/private/engine/draw/draw-pass.rkt:310:0: send-draw-params /Users/ayman/Library/Racket/8.1/pkgs/pict3d/pict3d/private/engine/draw/draw-pass.rkt:364:4: draw-opaque-material-pass /Users/ayman/Library/Racket/8.1/pkgs/pict3d/pict3d/private/engine/draw/draw-passes.rkt:429:0: draw-draw-passes* /Users/ayman/Library/Racket/8.1/pkgs/pict3d/pict3d/private/gui/typed-pict3d-bitmap.rkt:11:0: pict3d-set-bytes! .../gl/context.rkt:20:24 /Users/ayman/Library/Racket/8.1/pkgs/pict3d/pict3d/private/gui/untyped-pict3d-bitmap.rkt:42:0: pict3d-&gt;bitmap /Applications/Racket v8.1/collects/racket/contract/private/arrow-val-first.rkt:489:18 body of "/Users/ayman/git/github.com/aymanosman/concept/Untitled.rkt" Not sure where to post this? Should it go in racket/racket Github repo issues?


jagen315
2021-5-9 01:26:01

also, re: this, there’s a “Reload #lang extensions” button under the “Racket” submenu which will let you see the changes to lexer w/o restart


mflatt
2021-5-9 01:27:03

I see that after today’s changes, the error is foreign-call: cannot pass non-atomic pointer to a function pointer: #&lt;cpointer&gt; function: 'glShaderSource context...: There have been corrections to the FFI realted to _cast that could potentially change something from seeming to work (as long as you’re lucky about GC timings) to a crash in 8.1 to this error in Git HEAD.

Or it could be a different kind of bug introduced in v8.1.

I’ll investigate more.


mflatt
2021-5-9 01:30:58

The crash seems in the vicinity of glShaderSource, which takes an array of strings — so, I think my initial guess may be right.


mflatt
2021-5-9 01:32:13

In v8.0, an array to hold bytes strings in CS was allocated as atomic memory. That’s wrong, because the byte-string references don’t get moved if a GC happened.


mflatt
2021-5-9 01:32:39

In v8.1, the array is corrected allocated as non-atomic. But, then, passing non-atomic memory to C just isn’t right, hence the crash.


mflatt
2021-5-9 01:33:06

And HEAD restores the error message that was supposed to catch problems passing non-atomic memory for C functions.


aymano.osman
2021-5-9 01:39:20

OK. I’m working with my own bindings to opengl, so any pointers to how I can fix those would be helpful, thanks.


aymano.osman
2021-5-9 01:40:32

Maybe I can run HEAD to test the fix. I’ve never done that before, I assume I just follow the build instructions.


mflatt
2021-5-9 01:42:33

In HEAD, (_vector i _string*/utf-8) can be replaced by _vector-of-string*/utf-8 defined as (require ffi/unsafe/string-list) (define _vector-of-string*/utf-8 (make-ctype _string-list/utf-8 vector-&gt;list list-&gt;vector)) As it happens, ffi/unsafe/string-list is new just today.


aymano.osman
2021-5-9 01:43:25

Cheers :)


mflatt
2021-5-9 01:44:02

I can imagine changing _vector and _list to treat _string*/utf-8 and related element type specially, but I’m not sure that hiding the general issue like that is a good idea.



aymano.osman
2021-5-9 02:42:09

Using the approach you showed above worked (using _string-list/utf-8). I see from your Github issue comments that you are going to explore some other options, so I’ll wait to hear about that. Cheers.


xh
2021-5-9 04:45:23

@xh has joined the channel