Has anyone got any experience with RSound https://docs.racket-lang.org/rsound/index.html , would it be any use for simple games written with big bang (from 2htdp/universe)?
@mark.warren I never used it, but it looks like it has builtin ways to handle frames, streaming and framerate, which is cool for games.
@jerome.martin.dev Thanks, yes, it looked good to me, but I have little experience with either games or sound.
Then if sound is not the main aspect of your game my advice would be to develop without sound first, then add it later when you have more experience :wink:
I’ve been there and failed hard by trying too much at the same time :stuck_out_tongue:
@jerome.martin.dev Hehe, that sounds like sage advice.
A bit of a trivial question, but is there anything like a for/count
?
there is a for/sum
ah return 1
i see
@slack1 I’ve wanted it a number of times and drag this along:
(define-syntax for/count
(syntax-rules ()
[(_ (vars ...) body ...+) (for/count (vars ...) (begin body ...+))] ; =>
[(_ (vars ...) body) (for/sum (vars ... #:when body) 1)]))
Is the main way to use in-value
for the *
version of for
iterations?
(for*/fold ([best 0] [seen-at 0] #:result (list best seen-at))
([t tuples]
[index (in-naturals)]
[now (in-value (log-identity (first t) (second t)))]
#:when (< best now))
(values now index))
I was trying to do this
But I can’t see the value of t
unless I do *
And once I do *
, it will iterate down (in-naturals)
forever, which makes me do (in-range max)
instead
that’s how I would use in-value
too iterate down forever could be solved by using #:break
, but is using *
for [t tuple]
and [index (in-naturals)]
really what you intended for?
Admittedly not, I did it to use [n (in-value)]
I think though *
would make t
visible to [n (in-value)]
, it would break indexing
Am I perhaps abusing for/fold
and should just do recursion?
Or should I have an index state variable?
@slack1 what are you actually trying to do?
This is a toy project euler problem where I’m running down a list of base-exponent pairs, and trying to find the index location of the largest power
I don’t have an answer for that, this is probably a case that can’t be elegantly written using for
(but recursion is more ad-hoc IMHO)
might want to look at argmin
and argmax
?
which problem number?
Euler #99
argmin or argmax sounds nice
otherwise the best I could think of is (for/fold ([best 0] [seen-at 0] #:result (list best seen-at))
([t tuples]
[index (in-naturals)])
(define now (log-identity (first t) (second t)))
(cond [(> now best) (values now index)]
[else (values best seen-at)]))
ah I see, I didn’t even know about argmin
and argmax
thanks for help
I also didn’t know you could do a define
statement in the middle of for/fold
define
is allowed almost everywhere — inside for
, lambda
, let
and cond
the notation body
hints that define
is allowed https://docs.racket-lang.org/reference/notation.html > A metavariable that ends with body stands for any form; the form will be parsed as either a local definition or an expression … and from the doc, for
is: (for/fold ([accum-id init-expr] ... maybe-result) (for-clause ...)
body-or-break ... body)