[CM] Grace: Scheme and SAL differences

David Rush kumoyuki at gmail.com
Tue Oct 27 06:59:30 PDT 2009


I just wanted to throw out a quick "Thank you" for this work. I've
been a Scheme programmer for a long time now, and I really wanted to
stay in Scheme while working with CM and was feeling frustrated by the
need to translate. AFAICT there is a definite lack of tutorials
published on the web for CM (perhaps they have expired?).

Thanks again.

2009/10/27 Uğur Güney <ugurguney at gmail.com>:
> # Hi!
> # After so much questions I asked, I wanted to share what I have learned. I
> translated the first 4 SAL tutorials to Scheme and attached them.
> # When a comment needs to be changed I erased it and put a "...". I did not
> to try change them :-)
> # I you think that this maybe helpful I can complete the translation of the
> tutorials.
> # Have a nice day!
> v.u.g
>
> 2009/10/26 Uğur Güney <ugurguney at gmail.com>
>>
>> # Thank you very much! Now I understand the loop macro. I forgot "do"
>> keywords.
>> # And now I have another problem about sprouting process'.
>> # This is the SAL example of a process:
>> define process simple()
>>   run repeat 20
>>     send "mp:midi", key: between(60, 96)
>>     wait .1
>>   end
>> sprout simple()
>> # Every time I evaluate sprout line, grace plays midi notes.
>> # And here is my Scheme version:
>> (define simple2
>>   (process repeat 20 do
>>            (send "mp:midi" :key (between 60 96))
>>            (wait 0.1)))
>> (sprout simple2)
>> # 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.
>> # 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 :-)
>> # Regards,
>> v.u.g
>>
>> 2009/10/25 Heinrich Taube <taube at uiuc.edu>
>>>
>>> On Oct 23, 2009, at 2:49 AM, Uğur Güney wrote:
>>>
>>>> # Dear list and Mr. Taube
>>>> # 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:
>>>>
>>>> print "Hello, world!" -> (print "Hello, world!")
>>>> # gives "print: unbound variable" error. I can just evaluate
>>>> "Hello, world!"
>>>> # or try
>>>> (display "Hello, world!")
>>>> # But the output of (display) is yellow, not green and does not have
>>>> "\n" character at the end.
>>>
>>> you can use s7's  'format'  function. that function will both print the
>>> message to the terminal and return the string it printed:
>>>
>>>
>>> cm> (format #t "hello world~%")
>>> hello world
>>> "hello world
>>> "
>>>
>>>
>>>> print "my key number: ", between(60, 90) -> (display "my key number: "
>>>>  (between 60 90))
>>>> # gives "display argument 2, 66, is an integer, but should be an output
>>>> port" error. I have to write
>>>> (string-append "my key number: " (number->string (between 60 90)))
>>>
>>> (format #t "my key number: ~S~%" (between 60 90))
>>>
>>>
>>>> # Another component I could not find (which is, I think, more important)
>>>> is the loop macro.
>>>> loop repeat 5
>>>>  print "a random keynum: ", random(128)
>>>> end
>>>> --->
>>>> (loop re peat 5
>>>>      (random 128))
>>>> # gives: >>> Error: Found 're peat' where operator expected.
>>>> clause context: 're peat 5 (random 128)'
>>>
>>> (loop repeat 5 do (format #t "a random keynum: ~S~%" (random 128))
>>>
>>>
>>>> # and
>>>>
>>>> loop for c in {a b c d e f g }
>>>>  print c
>>>> end
>>>> --->
>>>> (loop for c in '(a b c d e f g)
>>>>      (display c))
>>>> # gives: >>> Error: Expression expected but source code ran out.
>>>>
>>>
>>> (loop for c in '(a b c d e f g) do (format #t "~S~%" c))
>>>
>>> or better
>>>
>>> (loop for c in '(a b c d e f g) collect c)
>>>
>>>
>>>> # Similarly,
>>>> loop for x from 1 to 10
>>>>  print "x=", x
>>>> end
>>>> ---->
>>>> (loop for x from 1 to 10
>>>>      x)
>>>> # gives the same error.
>>>>
>>>
>>> (loop for i from 1 to 10 collect i)
>>>
>>>> # Of course a recursive approach using car's and cdr's works.
>>>> (define (play-chord chd)
>>>>  (if (not (equal? chd '()))
>>>>    (begin (send "mp:midi" :key (car chd))
>>>>           (play-chord (cdr chd)))))
>>>> (play-chord '(50 55 60))
>>>
>>> (define (play-chord chd)
>>>  (loop for x in chd do (send "mp:midi" :key x)))
>>>
>>> (play-chord '(50 55 60))
>>>
>>>
>>>> # But I think that the loop macro is not implemented in Grace. Am I
>>>> correct or making a mistake?
>>>
>>> you're making mistakes (plural)  ;)
>>>
>>> read the common lisp documentation on loop, most of it is supported.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> # Best regards,
>>>> -ugur guney-
>>>> _______________________________________________
>>>> Cmdist mailing list
>>>> Cmdist at ccrma.stanford.edu
>>>> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist
>>>
>>
>
>
> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist
>
>



-- 
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt



More information about the Cmdist mailing list