• pair: consider only nonnegative integers.
  • rel: a list of numbers, could be empty.
  • finite function: a list of numbers, could be empty.
Scheme PHP [Source Code]
set?
function is_set
($l)
{return
    is_nulll($l) ? TRUE
    : (is_member(car($l), cdr($l)) ? FALSE
      : is_set(cdr($l)));
}
makeset
function makeset
($l)
{return
    is_nulll($l) ? []
    : (is_member(car($l), cdr($l)) ? makeset(cdr($l))
      : cons(car($l), makeset(cdr($l))));
}
function makeset
($l)
{return 
    is_nulll($l) ? []
    : cons(car($l), makeset(multirember(car($l), cdr($l))));
}
subset?
function is_subset
($set1, $set2)
{return 
    is_nulll($set1) ? TRUE
    : is_member(car($set1), $set2) && is_subset(cdr($set1), $set2);
}
eqset?
function is_eqset
($set1, $set2)
{return 
    is_subset($set1, $set2) && is_subset($set2, $set1);
}
intersect?
function is_intersect
($set1, $set2)
{return 
    is_nulll($set1) ? FALSE
    : is_member(car($set1), $set2) || is_intersect(cdr($set1), $set2);
}
intersect
function intersect
($set1, $set2)
{return 
    is_nulll($set1) ? $set1
    : (is_member(car($set1), $set2) ? 
        cons(car($set1), intersect(cdr($set1), $set2))
      : intersect(cdr($set1), $set2));
}
union
function union
($set1, $set2)
{return 
    is_nulll($set1) ? $set2
    : (is_member(car($set1), $set2) ? union(cdr($set1), $set2)
      : cons(car($set1), union(cdr($set1), $set2)));
}
difference
function difference
($set1, $set2)
{return 
    is_nulll($set1) ? []
    : (is_member(car($set1), $set2) ? difference(cdr($set1), $set2) 
      : cons(car($set1), difference(cdr($set1), $set2)));
}
intersectall
function intersectall
($l_set)
{return
    is_nulll(cdr($l_set)) ? car($l_set)
    : intersect(car($l_set), intersectall(cdr($l_set)));
}
a-pair?
function is_pair
($x)
{return 
    is_atom($x) ? FALSE 
    : (is_nulll($x) ? FALSE
      : (is_nulll(cdr($x)) ? FALSE 
        : (is_nulll(cdr(cdr($x))) ? TRUE
          : FALSE)));
}
first
use function car as first;
second
function second
($l)
{return 
    car(cdr($l));
}
build
function build
($s1, $s2)
{return 
    cons($s1, cons($s2, []));
}
third
function third
($l)
{return
    car(cdr(cdr($l)));
}
fun?
function is_fun
($rel)
{return
    is_set(firsts($rel));
}
revpair
function revpair
($pair)
{return
    build(second($pair), first($pair));
}
revrel
function revrel
($rel)
{return 
    is_nulll($rel) ? $rel
    : cons(revpair(car($rel)), revrel(cdr($rel)));
}
seconds
function seconds
($l)
{return 
    is_nulll($l) ? []
    : cons(second(car($l)), seconds(cdr($l)));
}
fullfun?
function is_fullfun
($fun)
{return 
    is_set(seconds($fun));
}
one2one?
function is_one2one
($fun)
{return
    is_fun(revrel($fun));
}