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    /digego/extempore/tree/v0.8.9/libs/contrib/gsl.xtm
  • Casech    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/gsl.xtm
  • Casin    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/gsl.xtm
  • Casinh    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/gsl.xtm
  • cas    macro    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • cas-xtm-to-string    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • cas2sexpr    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • cas2xtm    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • cas2xtm_scm    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • cas_expand_term    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • caspp    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • casppoff    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • casppon    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • casq    macro    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • godot_string_parse_utf8    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/libgodot.xtm
  • impc:ir:compiler:bitcast    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmir.xtm
  • impc:ti:bitcast-check    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:numeric-cast-operator    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:word-downcase    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:word-upcase    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • sampler-parse-filename    scheme    /digego/extempore/tree/v0.8.9/libs/external/instruments_ext-scm.xtm
  • sampler-parse-midinote-filename    scheme    /digego/extempore/tree/v0.8.9/libs/external/instruments_ext-scm.xtm
  • sampler-parse-spn-filename    scheme    /digego/extempore/tree/v0.8.9/libs/external/instruments_ext-scm.xtm
  • scmcas    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • sexpr2cas    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • svm_parse_line    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/svm.xtm
  • xtmcas    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm