2016-10-22 18:07:12 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* Mes --- Maxwell Equations of Software
|
|
|
|
* Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
*
|
|
|
|
* This file is part of Mes.
|
|
|
|
*
|
|
|
|
* Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* Mes is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
greater_p (scm *x) ///((name . ">") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
int n = INT_MAX;
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
if (x->car->value >= n) return &scm_f;
|
|
|
|
n = x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return &scm_t;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
less_p (scm *x) ///((name . "<") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
int n = INT_MIN;
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
if (x->car->value <= n) return &scm_f;
|
|
|
|
n = x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return &scm_t;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
is_p (scm *x) ///((name . "=") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
if (x == &scm_nil) return &scm_t;
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
int n = x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
if (x->car->value != n) return &scm_f;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return &scm_t;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
minus (scm *x) ///((name . "-") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
scm *a = car (x);
|
|
|
|
assert (a->type == NUMBER);
|
|
|
|
int n = a->value;
|
|
|
|
x = cdr (x);
|
|
|
|
if (x == &scm_nil)
|
|
|
|
n = -n;
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
n -= x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return make_number (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
plus (scm *x) ///((name . "+") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
n += x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return make_number (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
divide (scm *x) ///((name . "/") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
int n = 1;
|
|
|
|
if (x != &scm_nil) {
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
n = x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
n /= x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return make_number (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
|
|
|
modulo (scm *a, scm *b)
|
|
|
|
{
|
|
|
|
assert (a->type == NUMBER);
|
|
|
|
assert (b->type == NUMBER);
|
|
|
|
return make_number (a->value % b->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
multiply (scm *x) ///((name . "*") (arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
int n = 1;
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
n *= x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return make_number (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm *
|
2016-11-03 20:28:05 +00:00
|
|
|
logior (scm *x) ///((arity . n))
|
2016-10-22 18:07:12 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
while (x != &scm_nil)
|
|
|
|
{
|
|
|
|
assert (x->car->type == NUMBER);
|
|
|
|
n |= x->car->value;
|
|
|
|
x = cdr (x);
|
|
|
|
}
|
|
|
|
return make_number (n);
|
|
|
|
}
|