chansey97
2022-3-20 09:22:42

What is the difference betwen these two usage of parameterize: 1. #lang racket (define p (make-parameter #f)) (parameterize ([p 3]) (printf "p=~a\n" (p))) ;; p=3 2. #lang racket (define p (make-parameter #f)) (p 2) (printf "p=~a\n" (p)) ;; p=2 Is the 2nd one just a convenient way of 1st one for module scope?


chansey97
2022-3-20 09:23:54

Guide seems only mentioned the 1st one.


soegaard2
2022-3-20 09:24:27

So (parameterize ([p 3]) ...) is “temporarily set p to 3”. And (p 3) “set p to 3” [and keep using that value for p].


chansey97
2022-3-20 09:24:57

Thanks @soegaard2!


chansey97
2022-3-20 10:16:24

A racket-mode question: I found that racket-mode [f5] - racket-run launches large codebases very slow. I have set (setq racket-error-context 'low), but no help. However, DrRacket can launch very fast, because I set the Dyanmic Properties “No debugging or profiling”. Is there the same settings in racket-mode?


chansey97
2022-3-20 10:17:46

@greg


soegaard2
2022-3-20 10:18:48

soegaard2
2022-3-20 10:19:00

soegaard2
2022-3-20 10:19:21

The default run is similar to “No debugging or profiling”.


chansey97
2022-3-20 10:19:45

But I have set (setq racket-error-context 'low).


soegaard2
2022-3-20 10:20:04

That I don’t know about.


soegaard2
2022-3-20 10:20:34

Note: try raco setup large-project in the terminal to make sure everything is compiled.


chansey97
2022-3-20 10:22:05

Is there way to inspect the setting “No debugging or profiling” in REPL?


soegaard2
2022-3-20 10:22:51

To see the current setting in the repl?


chansey97
2022-3-20 10:23:08

Yes.


soegaard2
2022-3-20 10:23:08

I don’t think so.


chansey97
2022-3-20 10:24:45

raco setup large-project What does it do? I cant search this command in racket docs.


soegaard2
2022-3-20 10:27:50

It compiles all files in large-project.


chansey97
2022-3-20 10:40:39

I found that racket-mode never creates compiled folder in my project, but DrRacket creates it.


soegaard2
2022-3-20 10:41:26

Yes. racket-mode works differently. Only DrRacket creates compiled.


chansey97
2022-3-20 10:45:12

Oh… i guess that is why racket-mode is slow. BTW, even if I use DrRacket to create the compiled folder, racket-mode won’t be aware of it.


soegaard2
2022-3-20 10:45:34

No, it just don’t use a "compiled’ subfolder.


soegaard2
2022-3-20 10:46:39

When you start racket-mode a “backend” (a racket program) is started. I believe the backend keeps track of modules it has seen.


chansey97
2022-3-20 10:47:26

If racket-mode isn’t aware of the compiled folder, each time it will recompile in other temporary folder? Or just interpret mode?


soegaard2
2022-3-20 10:48:27

Ask Greg for details.


ben.knoble
2022-3-20 13:18:46

“Only DrRacket creates compiled” is not true, I think: raco setup and/or racket do too, I believe (based on ad-hoc observations)


greg
2022-3-20 13:33:55

Doesn’t DrRacket use a different compiled subdirectory name than the one used by command-line Racket and other things like Racket Mode?


soegaard2
2022-3-20 13:35:14

Yes. DrRacket uses compiled/drracket


greg
2022-3-20 13:35:14

I think DrRacket does this because it automatically populates it — the checkbox a few lines down from the one circled in that screen cap — and wants to avoid interfering with people doing the normal thing of running raco make (directly or via raco setup) if/when they choose to do so.


greg
2022-3-20 13:39:28

Racket Mode isn’t trying to be as automatic as DrRacket in this regard. However, if you manually raco make, which puts compiled files in the the standard compiled subdirectory, Racket Mode will use those to load faster. (Because the standard Racket loader looks there, and Racket Mode (like command-line Racket) just uses the standard loader.)


greg
2022-3-20 13:40:15

TL;DR in this regard Racket Mode works like command-line Racket, not DrRacket.


chansey97
2022-3-20 14:37:55

@greg You are right. After using raco make , racket-mode run as fast as DrRacket with “No debugging or profiling”. raco make also create compiled folders, but it seems a bit different from what DrRacket created, i.e. racket-mode is only aware of the compiled folders created by raco make, but not DrRacket, although they are both called complied .


chansey97
2022-3-20 14:41:03

Maybe racket-mode could add a new command something like racket-run-with-compile.


chansey97
2022-3-20 14:49:14

I opened compiled folder. Yes, DrRacket only creates .dep and .zo in the drracket subfolder, so they are different.


chansey97
2022-3-20 15:10:26

A quick impl: (defun racket-run-module-at-point-with-compile () (interactive) (let* ((racket (executable-find racket-program)) (rkt (racket--buffer-file-name) ) (command (format "%s -l raco make -v %s" (shell-quote-wildcard-pattern racket) (shell-quote-wildcard-pattern rkt)))) (shell-command command) (racket-run-module-at-point))) Stolen from racket-mode-start-faster in racket-mode.el.


greg
2022-3-20 15:25:14

That’s a possibility.


greg
2022-3-20 15:27:10

My assumption so far has been: When people have quite large projects, they already have some strategy for byte-compiling if/as/when they want to. If the project is a package, maybe they raco setup <pkg>. Maybe they have a Makefile and run raco make on certain *.rkt files. Or some other strategy.


greg
2022-3-20 15:27:39

So mostly I’ve just tried to stay out of the way, with Racket Mode.


greg
2022-3-20 15:28:27

Based on issues and feature requests (or lack thereof) to-date, I think that’s been mostly what people have wanted, so far?


greg
2022-3-20 15:30:07

Note that raco make-ing an individual .rkt file that you’re able to run doesn’t really save any time. It gets compiled on-demand, in memory, automatically by the Racket loader, anyway.


greg
2022-3-20 15:30:31

The benefits come from byte-compiling other files that the .rkt file requires.


greg
2022-3-20 15:31:39

So if you’re heavily editing one specific .rkt file, and running it, repeatedly, that file probably need not be byte compiled.


chansey97
2022-3-20 15:39:14

I updated shell-quote-wildcard-pattern , it is still need shell-quote-wildcard-pattern, otherwise in windows Emacs will complain c:/Program problem. I think the racket-run-module-at-point-with-compile is suitable for debugging large codebase (but no makefile). For small program, it is not necessary.


chansey97
2022-3-20 15:39:17

> Note that raco make-ing an individual .rkt file that you’re able to run doesn’t really save any time. @greg It definitely can save time (I have tried). Because if you only modify individual files, raco will only compile those modified files without recompiling all the files.


greg
2022-3-20 15:41:24

I mean including the time spent raco make-ing the file. :slightly_smiling_face:


chansey97
2022-3-20 15:41:33

raco make a-individual.rkt can automatically compile all the files which a-individual.rkt depends on.


chansey97
2022-3-20 15:42:00

raco make only spend time in first time.


chansey97
2022-3-20 15:42:50

Then you have decompiled folder, so if you only modify small piece of code, the 2nd time compiling will be fast.


chansey97
2022-3-20 15:44:43

If you don’t use raco make, the 2nd time will spend as much time as the first (because it re-compiles in memory, maybe…).


greg
2022-3-20 15:47:29

If you’re not editing the file, and the .zo file isn’t outdated, you’re right it could save time.


greg
2022-3-20 15:51:20

compiled (or also compiled/drracket) is a cache, with the usual pros and cons of caches


greg
2022-3-20 15:52:27

Slightly off-topic, and you probably already know this, but: Most of the time is the equivalent of raco expand.


chansey97
2022-3-20 15:52:28

Even if I editing some individual files, it could still save a lot of time. Because I found that Racket seemly supports separate compilation. It only compiles those outdated files.


greg
2022-3-20 15:52:47

In Racket BC, the .zo is byte code, not even machine code, that’s JITed quite quickly.


greg
2022-3-20 15:52:51

For CS it’s native code.


greg
2022-3-20 15:53:18

But either way, the time really depends on how long expansion takes, and that usually means how “macro heavy” the code and it’s dependents are.


greg
2022-3-20 15:53:38

So e.g. a large project using Typed Racket, you’ll feel the pain more.


greg
2022-3-20 15:54:01

But even a pretty large project that doesn’t heavily use macros, you might not even byte compiling at all and it’s just fine.


greg
2022-3-20 15:54:04

It really depends.


chansey97
2022-3-20 15:54:38

Yes. My codebase heavily uses macros.


greg
2022-3-20 15:55:58

The Racket back end part of Racket Mode? I routinely use that all the time with zero .zo files and it’s fine. I don’t bother raco make-ing. In fact doing so is a drawback when I’m switching among various versions of Racket while testing. I don’t want .zo file mismatch errors.


greg
2022-3-20 15:56:14

Whereas your project it’s definitely a must-have, it sounds like.


greg
2022-3-20 15:56:42

So again that’s why I’ve just tried to stay out of the way with Racket Mode and let people handle the raco make/setup aspect however they need/want.


greg
2022-3-20 17:23:26

greg
2022-3-20 17:23:54

By adding a function to racket-before-run-hook.


greg
2022-3-20 17:24:43

The edit buffer is current when this is called, you can use racket--buffer-file-name there.


greg
2022-3-20 17:24:57

And this will work for all flavors of the run command.


greg
2022-3-20 17:25:37

(Someone could also add a hook to do e.g. make compile if they have a Makefile set up to compile certain files, or whatever else.)


greg
2022-3-20 17:26:10

So I think that’s the existing self-service option for this, today, if that works for you @chansey97?


chansey97
2022-3-20 17:49:04

@greg Thanks. I use your solution because it is more flexible.


chansey97
2022-3-20 17:51:09

We can use var directly in template? #lang racket (require syntax/parse (for-syntax syntax/parse racket)) (define-syntax (define-var stx) (syntax-parse stx [(_ var:id x) #'(define var x)])) ; <---- only var? not var:id? (define-var foo 1) What is difference from #lang racket (require syntax/parse (for-syntax syntax/parse racket)) (define-syntax (define-var stx) (syntax-parse stx [(_ var:id x) #'(define var:id x)])) ; <---- var:id (define-var foo 1)


chansey97
2022-3-20 17:52:41

What is the id mean? The https://docs.racket-lang.org/syntax/Parsing_Syntax.html\|docs doesn’t say anything about :id .


ben.knoble
2022-3-20 17:52:59

See syntax classes in the syntax-parse documentations


sorawee
2022-3-20 17:53:37

soegaard2
2022-3-20 17:54:18

The pattern var:id means match only identifiers - and bind to var.


chansey97
2022-3-20 17:54:55

Thanks!


sorawee
2022-3-20 17:55:04

var:id is essentially a shorthand of {~var var id}


chansey97
2022-3-20 19:51:21

BTW, I think it is better to rename compiled to _compiled. The compiled folder looks a little weird, because it is on the same level as normal source folders. (Just a suggestion).


laurent.orseau
2022-3-20 19:56:47

I guess it’s one of these things where if you have ever written the formal definition you realise the generality of the concept. In my mind flatten was only about flattening trees, i realised only recently that it flattens pairs too— even though the docs are pretty explicit on this matter actually.


ben.knoble
2022-3-20 21:32:41

At that point it could be hidden on *nix (.compiled)


rokitna
2022-3-21 05:05:24

It’s not just pattern-matching, right? The order matters when passing arguments to the constructor. Personally, in order to reserve the ability to change details like the order of the fields, I don’t export the constructor; I define another function (and match expander) that looks like the constructor without technically being a struct-constructor-procedure?, and I export that.