Maybe racket has something like python’s textwrap.dedent ? In python you’d write a multiline string, indented as normal, and then use dedent(s)
That sounds like what @-exp does already
Just spent an hour reading about @-exp syntax
#lang at-exp racket
(displayln @string-append{
This is a long string.
No worries about escaping
"quotes" or \escapes. It's
also okay to have λ, γ, θ, ...
Embed code: @(number->string (+ 3 4))
})
becomes #lang at-exp racket
(displayln @string-append{
This is a long string.
No worries about escaping
"quotes" or \escapes. It's
also okay to have λ, γ, θ, ...
Embed code: @(number->string (+ 3 4))
})
when indented with Racket Mode in Emacs….. why……
guess I’ll manually indent this file
In DrRacket, indentation is wrong after typing a newline, but then reindenting (tab) works well (better at least).
Small tip: You can write ~a instead of string-append here.
Nice! Thanks
Though, similarly to scribble, you may prefer to use something like flat-strap
(name to be refined to your taste) instead of ~a
or string-append
so you can use nested lists and remove all parentheses: #lang at-exp racket
(define (flat-strap . l)
(string-append* (map ~a (flatten l))))
(displayln
@flat-strap{
Here's a sequence:
@(for/list ([i (in-range 10)])
(list i ": " (sqr i) ", "))
Cool, eh?})
Renders:
Here's a sequence:
0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81,
Cool, eh?
The nice thing about ~a
is that it will turn non-strings into strings.
How is it possible that this is exactly what I was looking for?
Thanks!
I guess I needed to realize that pretty much everything can come after the @
, even things like for
, if
, cond
etc
how would I do that?
(require (only-in racket define))
Why: So it looks good. :smile: Note that at-expressions strip the leading spaces, so it’s fine.
As for at-expressions in general, you’ve probably already discovered all this in other docs, but here’s a blog post I wrote with a few ideas and tips. https://www.greghendershott.com/2015/08/at-expressions.html
@phanthero ^
Are there any mnemonics to not confuse between how module
, module*
and module+
work?
Is there a way to disable garbage collector? I want to see how much time it takes to run a piece of code without collecting garbage.
There’s an environment variable which is probably mentioned in the reference page on garbage collection
PLTDISABLEGC
I tried using (putenv "PLTDISABLEGC" "Y")
, but the time
procedure still shows gc time.
Yes, I like how you’re doing this as well: (define px pregexp)
@px{\d\.\d} ; #px"\\d\\.\\d"
lol. Yeah, just using functions with smaller names seems to fix up the indentation issue, so using ~a
is better than using string-append
probably. Thanks. I know there’s no good solution to this and you probably thought about this a lot when implementing this kind of indentation.
Are there require
and provide
shorthands for several modules from the same collection/subcollection? That is, instead of (require mycollect/subcollect/mod1
mycollect/subcollect/mod2
mycollect/subcollect/mod3
mycollect/subcollect/mod4)
I could just have something like (require (many mycollect/subcollect
mod1
mod2
mod3
mod4))
you need to set it on the command line when racket starts up
you can’t pause GC for a period of time
Yes, see multi-in
Will that work in an (all-from-out ...)
form?
I’m confused. You are talking about require
-ing, right? But all-from-out
is a provide
-ing form.
I was looking for shorthands to use in both require
and all-from-out
.
Sorry, I should’ve been more clear.
AFAIK there’s no shorthand for all-from-out
, but you should be able to write one yourself using the provide transformer protocol (and this is actually how multi-in
was written: as a require transformer)
Gotcha, thanks!