\command[option1,option2]{arg1}{arg2}
This can easily be translated into Lisp:
(command [option1 option2] arg1 arg2)
That way I can use Lisp to produce Latex.
\command[option1,option2]{arg1}{arg2}
(command [option1 option2] arg1 arg2)
That way I can use Lisp to produce Latex.
(function factorial [n]
(return
(ternary-operator (== n 0)
1
(* n (factorial (- n 1))))))
The above code directly translates into the JavaScript factorial function. Along with prxml, this allows me to create entire web pages entirely in Lisp:
[:html
[:head
[:title "Welcome"]]
[:body
[:script {:type "text/javascript"}
[:raw! (to-js '(alert "Hello World"))]]]]
I look forward to being able to use this to develop lots of webpages.
(defn evaluate-numeral
[numerals radix]
(apply +
(map-indexed
(fn [i v]
(* v (Math/pow radix (- (dec (count numerals)) i))))
numerals)))
(= (evaluate-numeral '(1 0 1 0 1) 2)
21)
You can also evaluate the amount of digits needed for a number in any numeral system:
(defn digits-in-number
[num radix]
(inc (Math/floor (/ (Math/log num) (Math/log radix)))))
(= (digits-in-number 255 2)
8)
(def every-true? (partial every? true?))
(def some-true? (comp not nil? (partial some #{true})))
(defn union
[& predicates]
(fn [& obj]
(every-true? (map (fn [predicate] (apply predicate obj)) predicates))))
(defn intersection
[& predicates]
(fn [& obj]
(some-true? (map (fn [predicate] (apply predicate obj)) predicates))))
(defn cartesian-product
[& predicates]
(fn [& obj]
(and
(= (count obj) (count predicates))
(every-true?
(map
(fn [i]
(apply (nth predicates i) (nth obj i)))
(range 0 (count obj)))))))
#{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
#{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20}
Here are the same things as predicates:
(fn [n] (<= 0 n 10))
(fn [n] (and (even? n) (<= 0 n 20)))
Some means must be developed to deal with these two different presentations of classes.
(defn expand-number*
[n]
(if (zero? n)
0
(cons inc (list (expand-number* (dec n))))))
(defmacro expand-number
[n]
(expand-number* n))
We can also define them in terms of the unary numeral system:
(defmacro tally-marks
[n]
(cons + (map (constantly 1) (range 0 n))))
Here is how these functions work:
(= (macroexpand-1 '(expand-number 5))
`(inc (inc (inc (inc (inc 0))))))
(= (macroexpand-1 '(tally-marks 5))
`(+ 1 1 1 1 1))