diff --git a/src/env.c b/src/env.c index a5be7c4..1752337 100644 --- a/src/env.c +++ b/src/env.c @@ -215,8 +215,6 @@ struct helpText { int currentHelp = 0; struct helpText helpTexts[100]; -#define pf(_func) buildFuncSym(_func ## Symbol, &(_func), _func ## Doc, _func ## Tests, array_length(_func ## Tests)) - /// For any instances (e.g. segfault recovery) where defaultEnv() may be called /// multiple times. int helpInitialized = 0; @@ -376,6 +374,8 @@ int runTests(int detailed) return failureCount; } +#define pf(_func) buildFuncSym(_func ## Symbol, &(_func), _func ## Doc, _func ## Tests, array_length(_func ## Tests)) + struct Environment defaultEnv() { if (!helpInitialized) { @@ -395,16 +395,16 @@ struct Environment defaultEnv() }; struct symFunc symFuncs[] = { - {"+", &add}, - {"-", &sub}, - {"*", &mul}, - {"/", &dvi}, - {"%", &mod}, - {"=", &equ}, - {">", &greaterThan}, - {"<", &lessThan}, - {"&", &and}, - {"|", &or}, + pf(add), + pf(sub), + pf(mul), + pf(dvi), + pf(mod), + pf(equ), + pf(greaterThan), + pf(lessThan), + pf(and), + pf(or), pf(catObjects), pf(filter), pf(len), diff --git a/src/plfunc.h b/src/plfunc.h index a621a92..ffbd2c4 100644 --- a/src/plfunc.h +++ b/src/plfunc.h @@ -3,30 +3,69 @@ #include "pebblisp.h" -#define BASIC_OP(_name) \ - Object _name(Object* params, int length, struct Environment* env) +fn(add, "+", + "Add numbers", + "(+ 1 2)", "3", + "(+ 1 2 3 4)", "10", +); -BASIC_OP(add); +fn(sub, "-", + "Subtract numbers", + "(- 3 2)", "1", + "(- 10 3 1)", "6", +); -BASIC_OP(sub); +fn(mul, "*", + "Multiply numbers", + "(* 3 2)", "6", + "(* 1 2 3 4)", "24", +); -BASIC_OP(mul); +fn(dvi, "/", + "Divide numbers", + "(/ 8 2)", "4", + "(/ 100 5 2)", "10", +); -BASIC_OP(dvi); +fn(mod, "%", + "Get the modulus of two numbers", + "(% 10 3)", "1", +); -BASIC_OP(mod); +fn(equ, "=", + "Check if two values are equal", + "(= (+ 2 2) 4)", "T", + "(= \"Hello\" (cat \"He\" \"llo\"))", "T", + "(= (1 2 3) (1 2 3))", "T", + "(= 10 \"10\")", "F", + "(= 2 5)", "F", +); -BASIC_OP(equ); +fn(greaterThan, ">", + "Check if one number is greater than another", + "(> 10 3)", "T", + "(> 2 5)", "F", +); -BASIC_OP(greaterThan); +fn(lessThan, "<", + "Check if one number is less than another", + "(< 2 5)", "T", + "(< 10 3)", "F", +); -BASIC_OP(lessThan); +fn(and, "&", + "Check if all conditions are true", + "(& T T)", "T", + "(& F T)", "F", + "(& T T T T T F)", "F", +); -BASIC_OP(and); - -BASIC_OP(or); - -#undef BASIC_OP +fn(or, "|", + "Check if any conditions are true", + "(| T F)", "T", + "(| F F)", "F", + "(| F F F F F T)", "T", +); tfn(catObjects, "cat", ({ NULL, isStringy }), @@ -152,9 +191,10 @@ fn(parseEvalO, "eval", /// STRUCT, STRING => ANY fn(possessive, "poss", - "(struct Post (title body))\n" - "(def p (Post \"TI\" \"BO\"))\n" - "p's title => TI" + "Get the value of a struct's field", + "(struct Post (title body))\n " + "(def p (Post \"TI\" \"BO\"))\n " + "p's title", "TI" ); #ifdef STANDALONE