# This is a tool that compiles a ML-like program into Integrated Dynamics
# variables. Below is an example program. Click "Compile" to try it out.
# There is no infix operator. To express "x plus y", write "+ x y".
# Last updated: 8/17/2023.
# Example Program
# Define an operator that takes in a list and a number. It adds the number to
# each element in the list, and then insert the number itself to front and back
# of the list.
let modifyList list num =
let mappedList = map (fun x -> + x num) list in
concat (append [] num) (append mappedList num)
;
# Example usage of the "modifyList" operator we just defined. This is another
# top-level definition. Note that all top-level definitions end in a semicolon.
let exampleList = modifyList [1,2,3] 5;
# Recursion can be implemented using the U combinator. For example, below is a
# recursive definition of the factorial function.
let U f = f f;
let fac = U (fun fac n ->
? (eq n 0) (
fun fac -> 1
) (
fun fac -> mul n (U fac (decr n))
) fac
);
# Should output 120.
let test = fac 5;