Monday, November 29, 2010

An extensive example of code



function ? (predicate result1 result2) {
if predicate {
! result1
} {
! result2
}
}

function <= (value1 value2) {
if [< value1 value2] { true } {
= value1 value2
}
}

function incr(x) {
+ x 1
}

function decr(x) {
- x 1
}

/*
* inclusive range
*/
function .. (begin end) {
set func [? [<= begin end] incr decr ]
if [= begin end] {
append () begin
} {
append [.. [func begin] end] begin
}
}

/**
* iterates through a list and executes
* the passed in block
*/

function foreach(list block) {
if [not [empty? list]] {
set item [head list]
eval block
foreach [rest list] block
}
}


All of the above code is needed to prepare for the following


foreach [ .. 1 12] {
println "hi! number " item
}

No comments: