<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>About the implementation of sturms function in Notes from the Metalevel</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>I came to the 12. Chapter of Notes from the Metalevel<BR>
book and while I was trying to compile the sturms function<BR>
I had some warning from SBCL:<BR>
<BR>
The details are at:<BR>
<BR>
<A HREF="http://paste.lisp.org/display/12980">http://paste.lisp.org/display/12980</A><BR>
<BR>
;; the code below (which is taken from Common Music<BR>
;; application produces an error:<BR>
;;<BR>
;;-+ Warnings (1)<BR>
;; `-- ==><BR>
;; -1<BR>
;; This is not a (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) (RATIONAL (0))):<BR>
;; -1<BR>
;; See also:<BR>
;; SBCL Manual, Handling of Types [node]<BR>
<BR>
<BR>
(define (strums key1 key2 rate dur amp)<BR>
(let ((step (if (< key2 key1) -1 1)) ;; e.g. 1 2 gives no warn.<BR>
(diff (abs (- key1 key2))))<BR>
(loop repeat (+ diff 1)<BR>
for key from key1 by step<BR>
for beg from 0 by rate<BR>
collect (new midi<BR>
:time beg<BR>
:duration dur<BR>
:amplitude amp<BR>
:keynum key))))<BR>
<BR>
<BR>
<BR>
One of the possible solutions was to use a slightly different for in<BR>
the loop:<BR>
<BR>
<BR>
; this seems to solve the problem of<BR>
;; a potential *negative* stepping value<BR>
<BR>
(define (strums key1 key2 rate dur amp)<BR>
(let ((step (if (< key2 key1) -1 1))<BR>
(diff (abs (- key1 key2))))<BR>
(loop repeat (+ diff 1)<BR>
for key = key1 then (+ key step)<BR>
for beg from 0 by rate<BR>
collect (new midi<BR>
:time beg<BR>
:duration dur<BR>
:amplitude amp<BR>
:keynum key))))<BR>
<BR>
Another proposed solution is to to do a conditional rotatef of key1 and key2<BR>
and then do a for key from key1 to key2.<BR>
<BR>
PS: Maybe this is already corrected in the CD that came with the<BR>
book (I couldn't find scores.cm in CVS version of CM) but I'm just the type of<BR>
guy who likes to type code from the book and I just wanted to share this<BR>
just in case somebody else is stuck in the same place.<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>