
scribble/example with escape: I stumble on this issue every few months it seems. The behavior of #:escape
with examples
seems very strange to me. I start by wanting to compute something to be included in example code. First, I try the default escape identifier, unsyntax
and write something like: (examples (add1 #,(sub1 3)))
which results in a perplexing “unsyntax: illegal outside of quasisyntax”.
After struggling around for a while trying out different identifiers, I realize that there’s a kind of pun going on which is what’s causing the problem. The example is escaping for what’s shown, but not what’s evaluated, hence the unsyntax error. But I don’t see how to write something that escapes both what is rendered and what is evaluated so that the above shows Examples:
> (add1 2)
3
Am I missing something?

I don’t think there’s a way to escape in the evaluation construction, but you can use eval:alts
to do something different in the two cases, such as @(examples (eval:alts (add1 #,(sub1 3))
(add1 (sub1 3))))
In that example, (sub1 3)
is not escaped for evaluation.

Thanks, yes, this is the solution I usually settle on, but it’s painful when the add1
is replaced by something substantial which is duplicated.

Adding some option to examples
to make unsyntax
escape might make sense. Right now, the evaluation treatment boils down to quote
via base-quote-expr
in scribble/eval
.

a thought that occurred to me just now and works in my particular use case is to use #:escape identity
lol.

I’ve added #:callback-exns?
to _fun
. The intent for your example is that you’d add #:callback-exns? #t
to the _fun
for entry
.

so im trying to write to a file and (writeln (vector 1 2 3) out)
writes #(1 2 3)
but what I really want is something like: #(
1
2
3
)
currently im doing something like: (map (lambda (item) (writeln item out)) (vector 1 2 3))
(define final (string-append "#(" (get-output-string out) ")")))
(displayln final out) ;feels weird mixing wirteln and displayln
to hack around it. Is there an easier/better way or is this it?

I don’t think you need to bother going through a string; you can just print directly, e.g. > (define (write-vector v)
(displayln "#(")
(for ((x (in-vector v)))
(writeln x))
(displayln ")"))
> (write-vector #(1 2 3))
#(
1
2
3
)

sweet thanks!

awesome thanks! In the meantime, using the code from draw/unsafe
worked well.

syntax-case: unbound identifier;
also, no #%app syntax transformer is bound in the transformer phase in: syntax-case
https://docs.racket-lang.org/reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._syntax-case%29%29
how do i tell what the require statement is in order to import this?

I tried replacing my hacky, mutating, chess move iterator with a generator, but it made the program 3.3x slower. Given that the move iterator is a tiny part of the whole process, that indicates generators (or at least the way I used it) are way too inefficient for my purposes. Is there something similar that’s much faster? Both versions are <https://gist.github.com/lojic/381b8b94098fc57498b38b51737f28f8|in this gist> .

Assuming you are using #lang racket/base
, then you may want (require (for-syntax racket/base))
to require racket/base
at compile-time (technically, phase 1)

Is this CS or BC?

Racket v7.9 [cs]

I ended up hacking this together: https://gist.github.com/lojic/9f78e7789dc2829f74f776044e50dd3e

lol - while double checking that gist, I noticed line 42 should’ve been an else
- I suppose the set!
functioned as else/#t
since it’s not #f
:)

Does this tiny fragment capture what you need in the iterators?
If it is, it seems difficult to have a more abstracted construct that win over the let-over-lambda implementation. generator
is doing way more work and excels in other aspects. https://gist.github.com/shhyou/05b33363502014c25b77bab3004ebf22