vector functions on vectors?

11 views
Skip to first unread message

Forrest Curo

unread,
Jul 27, 2021, 9:49:21 AM7/27/21
to scheme-for-max & scheme-for-pd

As a scheme newby, I'm having trouble trying to put straightforward functions into lispian knots...

I'm calling a 'scale' a vector (should be a list?) of 7 degrees, ie: #(0, 2, 3, 5, 7, 8, 11)

where scale 0 is 0,
scale 1 is >= 1 and < 4,
scale 2 is > scale 1 and < 5,
scale 3 is 5,
scale 4 is >5 and <10,
scale 5 is > scale 4 and < 11,
scale 6 is > scale 5 and <= 11.

There are six vectors (should be lists?) of two elements
#(1 2) #(1 3) #(1 4) ... #(3 4)
and ten of three elements from #(6 7 8) to #(9 10 11)
It's straightforward for me to randomly choose one of the six for degrees 1 and 2, one of the ten for degrees 4, 5, and 5 --
but I get into tangles of ()'s trying to make a function to do this.

How? (Would it be better to go "(begin (set scale 0) (set scale 1) etc)" instead?


Forrest Curo
San Diego

Forrest Curo

unread,
Jul 29, 2021, 9:16:05 AM7/29/21
to scheme-for-max & scheme-for-pd
What I hadn't understood was (begin): how "All expressions in the body of the begin are evaluated, but only the last expression is returned."

So the side effects of something like this all take place, and affect the degrees of "scale", just not the "value" returned by the chain of instructions:

(define scale #(0 2 3 5 7 8 11));
(begin (set! (scale 1) (+ 1 (random 3))) (post (scale 1)) (set! (scale 2) (+ (scale 1) (+ 1 (random (- 3 (scale 1)))))) (post (scale 2)));
(post scale);

which resets the 2nd and 3rd degrees (not getting a perfectly even distribution, but one that will do.)
Repeating a few times,  with a  )line 1, step, step |     message box in Pure Data:
s4pd: 3
s4pd: 4
s4pd: #(0 3 4 5 7 8 11)
s4pd: 1
s4pd: 2
s4pd: #(0 1 2 5 7 8 11)
s4pd: 3
s4pd: 4
s4pd: #(0 3 4 5 7 8 11)
s4pd: 2
s4pd: 3
s4pd: #(0 2 3 5 7 8 11)

and setting the rest of the vector should work much the same.

Forrest Curo

unread,
Jul 31, 2021, 2:02:13 PM7/31/21
to scheme-for-max & scheme-for-pd
Much more intelligible way to do it:

(define scale #(0 2 3 5 7 8 11));
(define sc1 (lambda (sc) (set! (sc 1) (+ 1 (random 3)))));
;(post (sc1 scale))                                                                ;  just for debugging...
(define sc2 (lambda (sc) (set! (sc 2) (+ (sc 1) 1 (random (- 3 (sc 1)))))));
;(post (sc1 scale) (sc2 scale));
(define sc4 (lambda (sc) (set! (sc 4) (+ 6 (random 3)))));
;(post (sc4 scale));
(define sc5 (lambda (sc) (set! (sc 5) (+ (sc 4) 1 (random (- 10 (sc 4)))))));
;(post (sc4 scale) (sc5 scale));
(define sc6 (lambda (sc) (set! (sc 6) (+ (sc 5) 1 (random (- 11 (sc 5)))))));
;(post (sc4 scale) (sc5 scale) (sc6 scale));
(define newscale (lambda (sc) (begin (sc1 sc) (sc2 sc) (sc4 sc) (sc5 sc) (sc6 sc))));
(begin (newscale scale) (post scale));
Reply all
Reply to author
Forward
0 new messages