[CM] Grace: Scheme and SAL differences

Heinrich Taube taube at uiuc.edu
Sun Oct 25 05:17:09 PDT 2009


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 repeat 5
>       (random 128))
> # gives: >>> Error: Found 'repeat' where operator expected.
> clause context: 'repeat 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




More information about the Cmdist mailing list