mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 13:55:55 +03:00
equality.mal: - fix typos - let and2 and or2 always return booleans - when looping in sequences, compare lengths only once - empty? instead of an equality test - when looping on a keys, do not check if a contains the current key - change the `cond` logic: when a is a sequence and b a map, return false instead of delegating to scalar-equal?. - add tests memoize.mal: - make explicit that the function name must be kept - fix typo in tests protocols.mal: - document - add a function mapping an object to its type - add default types for remaining built-in MAL values - let defprotocol return the new protocol instead of last method - set the right profile for abstract methods, improving error messages - replace incomplete example with lots of tests pprint: - escape parenthesis in expected test results [kanaka] - explain in lib/README.md how to run tests/lib/*. - rename folds to reducers and composition to threading - move fib and sumdown from lib/ to tests/
20 lines
507 B
Plaintext
20 lines
507 B
Plaintext
;; Some inefficient arithmetic computations for benchmarking.
|
|
|
|
;; Unfortunately not yet available in tests of steps 4 and 5.
|
|
|
|
;; Compute n(n+1)/2 with a non tail-recursive call.
|
|
(def! sumdown
|
|
(fn* [n] ; non-negative number
|
|
(if (= n 0)
|
|
0
|
|
(+ n (sumdown (- n 1))))))
|
|
|
|
;; Compute a Fibonacci number with two recursions.
|
|
(def! fib
|
|
(fn* [n] ; non-negative number
|
|
(if (<= n 1)
|
|
n
|
|
(+ (fib (- n 1)) (fib (- n 2))))))
|
|
|
|
nil
|