cas_expand_term   xtlang


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

Implementation

(bind-func cas_expand_term
  (lambda (t:String*)
    ;; (println "t:" t)
    (set! cas_cntterms (+ cas_cntterms 1))
    (cond ((> cas_cntterms 50) t)
          ((regex_match "^\\(\\(.*\\)\\)$" t)
           (cas_expand_term (trim_brackets t)))
          ((and
            (regex_match "^\\(.*\\)$" t)
            (= 1 (length (find_sexprs t))))
           t)
          ((and
            (regex_match "^\\[.*\\]$" t)
            (= 1 (length (find_sqr_exprs t))))
           (let ((r (regex_split "," (substring t 1 (- (length t) 1)))))
             (if (null? r)
                 (cas_expand_term (substring t 1 (- (length t) 1)))
                 (cat (Str "(vector")
                      (concat (map (lambda (x) (cat (Str " ") (cas_expand_term x))) r))
                      (Str ")")))))
          ((regex_match "^[a-zA-Z]+\\(" t) ;;[^)]*\\)*$" t)
           (let ((matches (regex_matches "\\([^()]*\\)" t))
                 (newt (cas_expand_term (car matches)))
                 (s1 (replace t (car matches) newt))
                 (r1 (regex_replace "^([^(]*).*" s1 "$1"))
                 (r2 (regex_replace "^([^(]*)(\\(+[^)]*\\)+)(.*)" s1 "$2"))
                 (r3 (regex_replace "^([^(]*)(\\(+[^)]*\\)+)(.*)" s1 "$3")))
             ;; (println "s1:" s1 "r1:" r1 "r2:" r2 "r3:" r3)
             (cas_expand_term (cat (Str "(") r1 (Str " ")
                                   (cas_expand_term (trim_brackets r2))
                                   (Str ")") r3))))
          ((regex_match "[^(]/" t)
           (let ((r1 (regex_replace "^(.*)([^(])(/)(.*)$" t "$1$2"))
                 (r2 (regex_replace "^(.*)([^(])(/)(.*)$" t "$4"))
                 (r3 (cat (Str "(/ ")
                          (cas_expand_term (trim r1)) (Str " ")
                          (cas_expand_term (trim r2)) (Str ")"))))
             r3))
          ((regex_match "[^(]\\*" t)
           (let ((r1 (regex_replace "^(.*)([^(])(\\*)(.*)$" t "$1$2"))
                 (r2 (regex_replace "^(.*)([^(])(\\*)(.*)$" t "$4"))
                 (r3 (cat (Str "(* ")
                          (cas_expand_term (trim r1)) (Str " ")
                          (cas_expand_term (trim r2)) (Str ")"))))
             ;; (println "multi:" r1 r2 r3)
             r3))
          ((regex_match "e\\^" t)
           (let ((p (regex_split "e\\^" t)))
             (cat (Str "(exp ") (cas_expand_term (trim (nth p 1))) (Str ")"))))
          ((regex_match "\\^" t)
           (let ((p (regex_split "\\^" t)))
             (cat (Str "(pow ")
                  (cas_expand_term (trim (nth p 0))) (Str " ")
                  (cas_expand_term (trim (nth p 1))) (Str ")"))))
          ((regex_match "^[0-9]*$" t)
           (cat t (Str ".0:double")))
          (else t))))


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_parse_terms    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
  • cond-expand    macro    /digego/extempore/tree/v0.8.9/runtime/init.xtm
  • cond-expand-runtime    scheme    /digego/extempore/tree/v0.8.9/runtime/init.xtm
  • cpBBExpand    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/libchipmunk/cpBB.xtm
  • determinant    xtlang    /digego/extempore/tree/v0.8.9/libs/core/math_ext.xtm
  • expand    macro    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • glfw_terminate    xtlang    /digego/extempore/tree/v0.8.9/libs/external/glfw3.xtm
  • impc:compiler:print-cannot-expand-non-generic-error    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ir:compiler:bitcast    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmir.xtm
  • impc:ir:get-type-expand-poly    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:expand-generic-type    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:expand-generic-type-func-gpoly-arity    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:expand-generic-types    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:reify-generic-type-expand    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
  • ivl:expand/contract    scheme    /digego/extempore/tree/v0.8.9/libs/core/pc_ivl.xtm
  • macro-expand    scheme    /digego/extempore/tree/v0.8.9/runtime/init.xtm
  • mdeterminant    xtlang    /digego/extempore/tree/v0.8.9/libs/core/math.xtm
  • mdeterminant    xtlang    /digego/extempore/tree/v0.8.9/libs/core/math.xtm
  • pc:expand/contract    scheme    /digego/extempore/tree/v0.8.9/libs/core/pc_ivl.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
  • xtmcas    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm