cas_parse_terms   xtlang


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

Implementation

(bind-func cas_parse_terms
  (lambda (ein:String*)
    ;; (println "Parse:" ein)
    (set! cas_cntterms 0)
    (let ((e (replace ein "ln" "log"))
          (m1 (find_sexprs e))
          (m2 (map (lambda (x:String*)
                     (if (regex_match "(\\+|\\-)" x)
                         (cas_parse_terms (trim_brackets x))
                         (list (cat (Str "(") (cas_expand_term (trim_brackets x)) (Str ")")))))
                   m1))
          (m3 (map (lambda (l)
                     (if (null? l) (Str "")
                         (if (= (length l) 1) (car l)
                             (cat
                              (Str "(plus")
                              (concat (map (lambda (x:String*)
                                             (cat
                                              (Str " ")
                                              (if (regex_match "^\\-" x)
                                                  (cas_expand_term
                                                   (cat (Str "(neg ")
                                                        (substring x 1 (length x))
                                                        (Str ")")))
                                                  (cas_expand_term (replace x "+" "")))))
                                           l))
                              (Str ")")))))
                   m2))
          (m4 (reverse (map (lambda (s1 s2)
                              (set! e (replace e s1 (replace_all s2 "+" "plus")))
                              e)
                            m1 m3)))
          (m8 (regex_matches "(^|\\+|\\-)([^+-]|\\(plus)+" (if (> (length m4) 0) (car m4) e)))
          (res (map (lambda (x:String*)
                      (if (regex_match "^\\-" x)
                          (let ((r1 (cas_expand_term (substring x 1 (length x))))
                                (r2 (cat (Str "(neg ") r1 (Str ")"))))
                            r2)
                          (if (regex_match "^\\+" x)
                              (cas_expand_term (substring x 1 (length x)))
                              (cas_expand_term x))))
                    m8)))
      ;;(println "out:" res "in:" ein "\n")
      res)))


Back to Index

Similar Entries

  • Casec    xtlang
  • Casech    xtlang
  • Casin    xtlang
  • Casinh    xtlang
  • cas    macro
  • cas-xtm-to-string    scheme
  • cas2sexpr    scheme
  • cas2xtm    xtlang
  • cas2xtm_scm    xtlang
  • cas_expand_term    xtlang
  • caspp    xtlang
  • casppoff    xtlang
  • casppon    xtlang
  • casq    macro
  • godot_string_parse_utf8    xtlang
  • impc:ir:compiler:bitcast    scheme
  • impc:ti:bitcast-check    scheme
  • impc:ti:numeric-cast-operator    scheme
  • impc:ti:word-downcase    scheme
  • impc:ti:word-upcase    scheme
  • sampler-parse-filename    scheme
  • sampler-parse-midinote-filename    scheme
  • sampler-parse-spn-filename    scheme
  • scmcas    scheme
  • sexpr2cas    scheme
  • svm_parse_line    xtlang
  • xtmcas    scheme