mark.warren
2018-8-23 14:24:05

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)?


jerome.martin.dev
2018-8-23 14:26:54

@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.


mark.warren
2018-8-23 14:28:16

@jerome.martin.dev Thanks, yes, it looked good to me, but I have little experience with either games or sound.


jerome.martin.dev
2018-8-23 14:37:04

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:


jerome.martin.dev
2018-8-23 14:37:27

I’ve been there and failed hard by trying too much at the same time :stuck_out_tongue:


mark.warren
2018-8-23 14:44:37

@jerome.martin.dev Hehe, that sounds like sage advice.


slack1
2018-8-23 15:12:28

A bit of a trivial question, but is there anything like a for/count?


soegaard2
2018-8-23 15:12:45

there is a for/sum


slack1
2018-8-23 15:13:27

ah return 1


slack1
2018-8-23 15:13:28

i see


zenspider
2018-8-23 19:35:56

@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)]))

slack1
2018-8-23 21:53:47

Is the main way to use in-value for the * version of for iterations?


slack1
2018-8-23 21:55:54
(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))

slack1
2018-8-23 21:55:57

I was trying to do this


slack1
2018-8-23 21:56:25

But I can’t see the value of t unless I do *


slack1
2018-8-23 21:57:33

And once I do *, it will iterate down (in-naturals) forever, which makes me do (in-range max) instead


shu--hung
2018-8-23 22:03:07

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?


slack1
2018-8-23 22:04:49

Admittedly not, I did it to use [n (in-value)]


shu--hung
2018-8-23 22:06:50

I think though * would make t visible to [n (in-value)], it would break indexing


slack1
2018-8-23 22:06:50

Am I perhaps abusing for/fold and should just do recursion?


slack1
2018-8-23 22:07:08

Or should I have an index state variable?


zenspider
2018-8-23 22:08:34

@slack1 what are you actually trying to do?


slack1
2018-8-23 22:09:08

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


shu--hung
2018-8-23 22:09:19

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)


zenspider
2018-8-23 22:09:36

might want to look at argmin and argmax ?


zenspider
2018-8-23 22:10:00

which problem number?


slack1
2018-8-23 22:10:09

Euler #99


shu--hung
2018-8-23 22:10:29

argmin or argmax sounds nice


shu--hung
2018-8-23 22:10:37

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)]))


slack1
2018-8-23 22:11:18

ah I see, I didn’t even know about argmin and argmax


slack1
2018-8-23 22:12:41

thanks for help


slack1
2018-8-23 22:13:02

I also didn’t know you could do a define statement in the middle of for/fold


shu--hung
2018-8-23 22:14:00

define is allowed almost everywhere — inside for, lambda, let and cond


shu--hung
2018-8-23 22:16:01

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)