Add chrono dependency and example files
This commit introduces the `chrono` dependency to the project, enabling the use of time-related functionalities. Additionally, it adds several example files (`closure.myc`, `fib.myc`, `hof.myc`) to showcase the language's features like closures, recursion, and higher-order functions. The `Cargo.lock` and `Cargo.toml` files have been updated to reflect the new dependency. The `integration_test.rs` file now includes a test to run all `.myc` files found in the `examples` directory, ensuring their correctness. The `main.rs` file has also been updated to load and display these examples in the UI.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
;; Closure Scope Test
|
||||
;; Output: 15
|
||||
(do
|
||||
(def make-adder (fn [x]
|
||||
(fn [y] (+ x y))))
|
||||
|
||||
(def add5 (make-adder 5))
|
||||
|
||||
(add5 10)
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
;; Fibonacci Recursive
|
||||
;; Output: 55
|
||||
(do
|
||||
(def fib (fn [n]
|
||||
(if (< n 2)
|
||||
n
|
||||
(+ (fib (- n 1)) (fib (- n 2))))))
|
||||
|
||||
(fib 10)
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
;; Higher-Order Function Example
|
||||
;; Output: 25
|
||||
(do
|
||||
(def apply (fn [f x] (f x)))
|
||||
(def square (fn [x] (* x x)))
|
||||
|
||||
(apply square 5)
|
||||
)
|
||||
Reference in New Issue
Block a user