# Thank you very much! Now I understand the loop macro. I forgot "do" keywords.<div># And now I have another problem about sprouting process'.</div><div># This is the SAL example of a process:</div><div><br></div>
<div><div><font class="Apple-style-span" face="'courier new', monospace">define process simple()</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> run repeat 20</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> send "mp:midi", key: between(60, 96)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> wait .1</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> end</font></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">sprout simple()</span></div><div># Every time I evaluate sprout line, grace plays midi notes.</div>
<div><br></div><div># And here is my Scheme version:</div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">(define simple2</span></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> (process repeat 20 do</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> (send "mp:midi" :key (between 60 96))</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> (wait 0.1)))</font></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">(sprout simple2)</span></div></div><div># The evaluation (by CTRL+Enter) of sprout line plays only for once. After that I have to evaluate the process definition again, to play it again.</div>
<div># I suspect that second evaluation does not create a new process but tries to use the old one. But I am not sure. Or I am making mistakes again :-)</div><div># Regards,</div><div>v.u.g</div></div><div><br><br><div class="gmail_quote">
2009/10/25 Heinrich Taube <span dir="ltr"><<a href="mailto:taube@uiuc.edu">taube@uiuc.edu</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
<br>
On Oct 23, 2009, at 2:49 AM, Uğur Güney wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# Dear list and Mr. Taube<br>
# I want to use Grace with Scheme rather than SAL. I am using version 3.3.0 svn:1769. I looked at the "SAL tutorials" and tried to convert them to Scheme code. But I think some SAL commands does not exist in Scheme version. Like:<br>
<br>
print "Hello, world!" -> (print "Hello, world!")<br>
# gives "print: unbound variable" error. I can just evaluate<br>
"Hello, world!"<br>
# or try<br>
(display "Hello, world!")<br>
# But the output of (display) is yellow, not green and does not have "\n" character at the end.<br>
</blockquote>
<br></div>
you can use s7's 'format' function. that function will both print the message to the terminal and return the string it printed:<br>
<br>
<br>
cm> (format #t "hello world~%")<br>
hello world<br>
"hello world<div class="im"><br>
"<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
print "my key number: ", between(60, 90) -> (display "my key number: " (between 60 90))<br>
# gives "display argument 2, 66, is an integer, but should be an output port" error. I have to write<br>
(string-append "my key number: " (number->string (between 60 90)))<br>
</blockquote>
<br></div>
(format #t "my key number: ~S~%" (between 60 90))<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# Another component I could not find (which is, I think, more important) is the loop macro.<br>
loop repeat 5<br>
print "a random keynum: ", random(128)<br>
end<br>
---><br>
(loop re peat 5<br>
(random 128))<br>
# gives: >>> Error: Found 're peat' where operator expected.<br>
clause context: 're peat 5 (random 128)'<br>
</blockquote>
<br></div>
(loop repeat 5 do (format #t "a random keynum: ~S~%" (random 128))<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# and<br>
<br>
loop for c in {a b c d e f g }<br>
print c<br>
end<br>
---><br>
(loop for c in '(a b c d e f g)<br>
(display c))<br>
# gives: >>> Error: Expression expected but source code ran out.<br>
<br>
</blockquote>
<br></div>
(loop for c in '(a b c d e f g) do (format #t "~S~%" c))<br>
<br>
or better<br>
<br>
(loop for c in '(a b c d e f g) collect c)<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# Similarly,<br>
loop for x from 1 to 10<br>
print "x=", x<br>
end<br>
----><br>
(loop for x from 1 to 10<br>
x)<br>
# gives the same error.<br>
<br>
</blockquote>
<br></div>
(loop for i from 1 to 10 collect i)<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# Of course a recursive approach using car's and cdr's works.<br>
(define (play-chord chd)<br>
(if (not (equal? chd '()))<br>
(begin (send "mp:midi" :key (car chd))<br>
(play-chord (cdr chd)))))<br>
(play-chord '(50 55 60))<br>
</blockquote>
<br></div>
(define (play-chord chd)<br>
(loop for x in chd do (send "mp:midi" :key x)))<div class="im"><br>
<br>
(play-chord '(50 55 60))<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# But I think that the loop macro is not implemented in Grace. Am I correct or making a mistake?<br>
</blockquote>
<br></div>
you're making mistakes (plural) ;)<br>
<br>
read the common lisp documentation on loop, most of it is supported.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# Best regards,<br>
-ugur guney-<br>
_______________________________________________<br>
Cmdist mailing list<br>
<a href="mailto:Cmdist@ccrma.stanford.edu" target="_blank">Cmdist@ccrma.stanford.edu</a><br>
<a href="http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist</a><br>
</blockquote>
<br>
</blockquote></div><br></div>