[CM] Grace: Scheme and SAL differences
Heinrich Taube
taube at uiuc.edu
Tue Oct 27 10:49:57 PDT 2009
if anyone translates .sal examples to scheme ill certainly include it
in the distro and menu. i dont teach beginning algocomp in scheme so i
just have the .sal
> # 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,
yes its is wrong in the sense that you are trying to "reuse" someting
that is already finished.
never save and reuse (process...) descriptions.
instead define FUNCTIONS that return them:
(define (simple2 )
(process repeat 20 do
(send "mp:midi" :key (between 60 96))
(wait 0.1))))
(sprout (simple2 ))
On Oct 27, 2009, at 9:00 AM, Timothy Johnson wrote:
> Ugur,
>
> It would be very helpful for me if you would translate the tutorials
> into Scheme -- please do this, I would greatly appreciate it. I'm
> using a few different applications that are all Scheme-based and it
> would be really nice to include Grace in that group and be able to
> just have my students stay in one standard programming environment
> (Scheme). That way, they only have to learn one language (which is
> also happily of very broad applicability.)
>
> Tim
>
> 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
>
>
>
>
> --
> Dr. Timothy Ernest Johnson
> _______________________________________________
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist
More information about the Cmdist
mailing list