Added concat example

This commit is contained in:
Devine Lu Linvega 2024-03-31 14:27:55 -07:00
parent 9d3384805b
commit 77655f3b7f
2 changed files with 149 additions and 0 deletions

8
concat.modal Normal file
View File

@ -0,0 +1,8 @@
define (: ?x ?y ;) (define ?x ?y)
: (?x dup) (?x ?x) ;
: (?x ?y swap) (?y ?x) ;
: (?x drop) () ;
: (?x ?y p*) (?x * ?y) ;
: square (dup p*) ;
10 square

141
prelude2.modal Normal file
View File

@ -0,0 +1,141 @@
define [-- ?x] {}
define [form ?x ?y] {
define ?x ?y
}
define [rule ?x ?y] {
define ?x ?y
}
define [?x -> ?y] {
define ?x ?y
}
[(?x) = (?x)] -> {
true
}
[(?x) = (?y)] -> {
false
}
[false or false] -> {
false
}
[true or false] -> {
true
}
[false or true] -> {
true
}
[true or true] -> {
true
}
[quote ?x] -> {
quote ?x
}
[unquote (quote ?x)] -> {
?x
}
form [
if ?condition
?true
else
?false
]
{
if/else ?condition {
quote ?true
} {
quote ?false
}
}
form [
if ?condition
?branch
]
{
if/q ?condition {
quote ?branch
}
}
rule [
if/q (true)
?branch
]
{
unquote ?branch
}
rule [
if/q (false)
?branch
]
{}
rule [
if/else (true)
?true
?false
]
{
unquote ?true
}
rule [
if/else (false)
?true
?false
]
{
unquote ?false
}
[factorial (?x)] -> {
if ((?x) = (1)) {
1
}
else {
?x * factorial (?x - 1)
}
}
[fibonacci (?number)] -> {
if((?number) = (0) or (?number) = (1)) {
?number
}
else {
fibonacci (?number - 1) + fibonacci (?number - 2)
}
}
[range (?low) (?high)] -> {
if((?low) = (?high + 1)) {
nil
}
else {
?low : range (?low + 1) (?high)
}
}
[fold (?operation) (?initial) (nil)] -> {
?initial
}
[fold (?operation) (?initial) (?head : ?tail)] -> {
?operation ?head (fold (?operation) (?initial) ?tail)
}
[sum ?list] -> {
fold (add) (0) ?list
}