# Thank you very much! Now I understand the loop macro. I forgot &quot;do&quot; keywords.<div># And now I have another problem about sprouting process&#39;.</div><div># This is the SAL example of a process:</div><div><br></div>
<div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">define process simple()</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  run repeat 20</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    send &quot;mp:midi&quot;, key: between(60, 96)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    wait .1</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  end</font></div><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, 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: &#39;courier new&#39;, monospace; ">(define simple2</span></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  (process repeat 20 do</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">           (send &quot;mp:midi&quot; :key (between 60 96))</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">           (wait 0.1)))</font></div>
<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, 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">&lt;<a href="mailto:taube@uiuc.edu">taube@uiuc.edu</a>&gt;</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 &quot;SAL tutorials&quot; and tried to convert them to Scheme code. But I think some SAL commands does not exist in Scheme version. Like:<br>

<br>
print &quot;Hello, world!&quot; -&gt; (print &quot;Hello, world!&quot;)<br>
# gives &quot;print: unbound variable&quot; error. I can just evaluate<br>
&quot;Hello, world!&quot;<br>
# or try<br>
(display &quot;Hello, world!&quot;)<br>
# But the output of (display) is yellow, not green and does not have &quot;\n&quot; character at the end.<br>
</blockquote>
<br></div>
you can use s7&#39;s  &#39;format&#39;  function. that function will both print the message to the terminal and return the string it printed:<br>
<br>
<br>
cm&gt; (format #t &quot;hello world~%&quot;)<br>
hello world<br>
&quot;hello world<div class="im"><br>
&quot;<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
print &quot;my key number: &quot;, between(60, 90) -&gt; (display &quot;my key number: &quot;  (between 60 90))<br>
# gives &quot;display argument 2, 66, is an integer, but should be an output port&quot; error. I have to write<br>
(string-append &quot;my key number: &quot; (number-&gt;string (between 60 90)))<br>
</blockquote>
<br></div>
(format #t &quot;my key number: ~S~%&quot; (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 &quot;a random keynum: &quot;, random(128)<br>
end<br>
---&gt;<br>
(loop re peat 5<br>
      (random 128))<br>
# gives: &gt;&gt;&gt; Error: Found &#39;re peat&#39; where operator expected.<br>
clause context: &#39;re peat 5 (random 128)&#39;<br>
</blockquote>
<br></div>
(loop repeat 5 do (format #t &quot;a random keynum: ~S~%&quot; (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>
---&gt;<br>
(loop for c in &#39;(a b c d e f g)<br>
      (display c))<br>
# gives: &gt;&gt;&gt; Error: Expression expected but source code ran out.<br>
<br>
</blockquote>
<br></div>
(loop for c in &#39;(a b c d e f g) do (format #t &quot;~S~%&quot; c))<br>
<br>
or better<br>
<br>
(loop for c in &#39;(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 &quot;x=&quot;, x<br>
end<br>
----&gt;<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&#39;s and cdr&#39;s works.<br>
(define (play-chord chd)<br>
  (if (not (equal? chd &#39;()))<br>
    (begin (send &quot;mp:midi&quot; :key (car chd))<br>
           (play-chord (cdr chd)))))<br>
(play-chord &#39;(50 55 60))<br>
</blockquote>
<br></div>
(define (play-chord chd)<br>
  (loop for x in chd do (send &quot;mp:midi&quot; :key x)))<div class="im"><br>
<br>
(play-chord &#39;(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&#39;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>