cas-xtm-to-string   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm

Implementation

(define cas-xtm-to-string
  (lambda (e)
    (cond ((atom? e) (atom->string e))
          ((list? e)
           (cond ((string=? "*" (atom->string (car e)))
                  (string-append "("
                                 (string-join
                                  (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) "*") ")"))
                 ((string=? "+" (atom->string (car e)))
                  (string-append "("
                                 (string-join
                                  (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) "+") ")"))
                 ((string=? "/" (atom->string (car e)))
                  (string-append "("
                                 (string-join
                                  (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) "/") ")"))
                 ((string=? "-" (atom->string (car e)))
                  (string-append "("
                                 (string-join
                                  (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) "-") ")"))
                 ((string=? "=" (atom->string (car e)))
                  (string-join
                   (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) "="))
                 ((string=? "set!" (atom->string (car e)))
                  (string-join
                   (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) ":="))
                 ((string=? "vector" (atom->string (car e)))
                  (string-append "["
                                 (string-join
                                  (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) ",") "]"))
                 ((string=? "exp" (atom->string (car e)))
                  (string-append "e^" (cas-xtm-to-string (cadr e))))
                 ((string=? "pow" (atom->string (car e)))
                  (string-append (cas-xtm-to-string (cadr e)) "^" (cas-xtm-to-string (caddr e))))
                 (else
                  (string-append (atom->string (car e))
                                 "("
                                 (string-join
                                  (map (lambda (x) (cas-xtm-to-string x)) (cdr e)) ",")
                                 ")"))))
          (else e))))


Back to Index