[CM] About the implementation of sturms function in Notes from the Metalevel

Rick Taube taube@uiuc.edu
Sat, 29 Oct 2005 07:04:20 -0500


> I came to the 12. Chapter of Notes from the Metalevel
>  book and while I was trying to compile the sturms function
>  I had some warning from SBCL:

Emre - thank you for taking the effort to note the problem and provide 
a solution. that was not a very robust example! i debated about adding 
error checks to code but decided against it to keep things as simple as 
possible.

it would be great if you would keep track of any/all problems you note 
as you work your way through the book, then we could then post the 
collection for others to take advantage of. There are other issue (like 
playback) that have arisen due to changes in more recent releases of 
the software.



>  The details are at:
>
> http://paste.lisp.org/display/12980
>
>  ;; the code below (which is taken from Common Music
>  ;; application produces an error:
>  ;;
>  ;;-+  Warnings (1)
>  ;; `-- ==>
>  ;;       -1
>  ;;     This is not a (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) 
> (RATIONAL (0))):
>  ;;       -1
>  ;;     See also:
>  ;;       SBCL Manual, Handling of Types [node]
>
>
>  (define (strums key1 key2 rate dur amp)
>    (let ((step (if (< key2 key1) -1 1)) ;; e.g. 1 2 gives no warn.
>          (diff (abs (- key1 key2))))
>      (loop repeat (+ diff 1)
>            for key from key1 by step
>            for beg from 0 by rate
>            collect (new midi
>                      :time beg
>                      :duration dur
>                      :amplitude amp
>                      :keynum key))))
>
>
>
>  One of the possible solutions was to use a slightly different for in
>  the loop:
>
>
>  ; this seems to solve the problem of
>  ;; a potential *negative* stepping value
>
>  (define (strums key1 key2 rate dur amp)
>    (let ((step (if (< key2 key1) -1 1))
>          (diff (abs (- key1 key2))))
>      (loop repeat (+ diff 1)
>            for key = key1 then (+ key step)
>            for beg from 0 by rate
>            collect (new midi
>                      :time beg
>                      :duration dur
>                      :amplitude amp
>                      :keynum key))))
>
>  Another proposed solution is to to do a conditional rotatef of key1 
> and key2
>  and then do a for key from key1 to key2.
>
>  PS: Maybe this is already corrected in the CD that came with the
>  book (I couldn't find scores.cm in CVS version of CM) but I'm just 
> the type of
>  guy who likes to type code from the book and I just wanted to share 
> this
>  just in case somebody else is stuck in the same place.
>
>