1.2.3-SNAPSHOT Arrow_down_16x16



  • (infix-to-prefix col)
Convert from infix notation to prefix notation

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/infix.clj:99 top

(defn infix-to-prefix
  "Convert from infix notation to prefix notation"
      ;; handle term only
      (not (seq? col)) col
      ;; handle sequence containing one term (i.e. handle parens)
      (= (count col) 1) (infix-to-prefix (first col))
      ;; handle all other cases
      true (let [lowest (find-lowest-precedence col)]
	     (if (nil? lowest) ;; nothing to split
	       ;; (a b c) bind a to hd, c to tl, and b to op
	       (let [[hd [op & tl]] (split-at lowest col)]
		 ;; recurse
		 (list (translate-op op)
		       (infix-to-prefix hd) 
		       (infix-to-prefix tl))))))))
Vars in incanter.infix/infix-to-prefix: = cond count defn first let list nil? not seq?
Used in 0 other vars

Comments top

No comments for infix-to-prefix. Log in to add a comment.