Change object-property-value in Scheme
I have been dealing many days with a problem without any success. In my programm I define a list, let's call it "L", by shifting a single geometrical object, a circle, many times. So L is composed by manu circles. The object circle is also a list which contains its properties: center (center . #V), (height . H), radius (radius . R), and so on. So, th开发者_如何学Pythone property radius is a pair in the 3rd position of the list circle. If I do (object-property-value circle 'radius) = R. Now, what I want to do is to create a new list, L-disorder, composed by circles with the same positions of those of L but each with different (random) radius. Then, I try this:
(define L-disorder (map
(lambda(obj)
(set-cdr! (list-ref obj 3) (random:normal))
obj)
L))
My problem is that it changes the radius of all the circles the same way! And I want a different (random) value for all of them.
I would really thank any help or advise!!
If you want to create new list, you shouldn't use mutation functons (set-cdr!).
(map )
functions do all the magic for you: it iterates over source list, and creates new list.
(define L-disorder
(map (lambda (circle)
; here we creating new circle
(list (car circle) (cadr circle) (random:normal)))
L))
精彩评论