#ifndef PEBBLISP_PLFUNC_H #define PEBBLISP_PLFUNC_H #include "pebblisp.h" #define BASIC_OP(_name) \ Object _name(Object* params, int length, struct Environment* env) BASIC_OP(add); BASIC_OP(sub); BASIC_OP(mul); BASIC_OP(dvi); BASIC_OP(mod); BASIC_OP(equ); BASIC_OP(gth); BASIC_OP(lth); BASIC_OP(and); BASIC_OP(or); #undef BASIC_OP fn(catObjects, "Concatenate string versions of the given objects.", "(cat \"Stuff: \" (1 2 3))", "Stuff: ( 1 2 3 )", ); // (Object obj1, Object obj2, struct Environment* env); fn(filter, "Filter a list based on the given condition.", "(fil (< 50) (25 60 100))", "( 60 100 )", ); // (Object condition, Object list, struct Environment* env); fn(append, "Append the given element. Creates a new list.", "(ap (1 2) 3)", "( 1 2 3 )", ); // (Object list, Object newElement, struct Environment* env); fn(prepend, "Prepend the given element. Creates a new list", "(pre (2 3) 1)", "( 1 2 3 )", ); // (Object list, Object newElement, struct Environment* env); fn(len, "Returns the length of the given list, or a NOT_A_LIST error if the expression is not a list.", "(len (2 3))", "2", "(len ())", "0", "(len \"string\")", "NOT_A_LIST", ); // (Object obj1, Object o_ignore, struct Environment* e_ignore); fn(reduce, "Performs a simple reduction. Does not currently work with lambdas.\n" "Takes two arguments:\n" " - A two-element list: (`values` `initial`)\n" " - A function to apply to each value.", "(reduce (5 6) +)", "11", "(reduce ((1 2 3) 0) +)", "6", ); // (Object listInitial, Object func, struct Environment* env); fn(at, "Get item at the given index in the given list.", "(at 1 (1 2 3))", "2", "(at 99 (1 2 3))", "INDEX_PAST_END", "(at 99 \"string\")", "INDEX_PAST_END", ); // (Object index, Object list, struct Environment* env); fn(rest, "Get the tail of a list. All but the first element.", "(rest (1 2 3))", "( 2 3 )", "(rest ())", "( )", "(rest \"string\")", "( )", ); // (Object list, Object ignore, struct Environment* env); fn(reverse, "Reverse a list.", "(rev (1 2 3))", "( 3 2 1 )", "(rev \"string\")", "NOT_A_LIST", ); // (Object _list, Object ignore, struct Environment* ignore2); fn(isNum, "Returns `T` only if the argument evaluates to a number.", "(isnum 1)", "T", "(isnum (+ 5 5))", "T", "(isnum '(+ 5 5))", "F", "(isnum \"Hello\")", "F", ); // (Object test, Object ignore, struct Environment* ignore2); fn(isList, "Returns `T` only if the argument is a list.", "(islist (1 2 3))", "T", "(islist ())", "T", "(islist \"Stringy\")", "F", ); // (Object test, Object ignore, struct Environment* ignore2); fn(isString, "Returns `T` only if the argument is a string.", "(isstr \"Heyo\")", "T", "(isstr \"\")", "T", "(isstr (cat 5 5))", "T", "(isstr 10)", "F", ); // (Object test, Object ignore, struct Environment* ignore2); fn(isErr, "Check if the argument is an error.", "(iserr (at 10 ()))", "T", "(iserr 5)", "F", ); // (Object test, Object ignore, struct Environment* ignore2); fn(charAt, "Get the char in the given string at the given index.", "(chat \"Hello\" 1)", "e", "(chat \"Hello\" 10)", "", ); // (Object string, Object at, struct Environment* ignore); fn(charVal, "Get the ascii integer representaton of the given character.", "(char \"h\")", "104", "(char \"hello\")", "104", "(char \"\")", "0", ); // (Object test, Object ignore, struct Environment* ignore2); fn(parseEvalO, "Evaluate the given string or quoted list.", "(eval \"(1 2 3)\")", "( 1 2 3 )", "(eval '(+ 5 5))", "10", ); // (Object text, Object ignore, struct Environment* env); fn(possessive, "(struct Post (title body))\n" "(def p (Post \"TI\" \"BO\"))\n" "p's title => TI" ); // (Object structo, Object field, struct Environment* env); #ifdef STANDALONE fn(print, "Prints the string representation of the given object to stdout."); //(Object p, Object ignore, struct Environment* ignore2); fn(pChar, "Prints the ascii character for the given number value."); //(Object c, Object i1, struct Environment* i2); fn(printEnvO, "Prints out the current scoped environment."); //(Object i1, Object i2, struct Environment* env); fn(systemCall, "Opens a shell and runs the given command, returning the command's exit code.\n" "(sys \"echo yee\")\n" "yee\n" "=> 0" ); // (Object process, Object _, struct Environment* env); fn(loadFile, "Loads and parses the given file.\n" "Returns 0 if the file was loaded and parsed successfully. Otherwise 1.\n" "(loadfile \"printdate.pl\")\n" "Mon 21 Mar 2022 10:35:03 AM EDT\n" "=> 0" ); // (Object filename, Object _, struct Environment* env); fn(takeInput, "Take console input with an optional prompt. For example:\n" "`(def x (input))` will wait for user input with no prompt.\n" "`(def x (input \">> \"))` wait for input, but prompt the user with '>> '.\n" ); // (Object i1, Object i2, struct Environment* i3); fn(help, "Displays help text for the given function.\n" "Currently requires the function name as a string, but future syntactic sugar may\n" "loosen this requirement.\n" "(? \"+\") => \"(+ 1 2) => 3\"" ); // (Object symbol, Object ignore, struct Environment* ignore2); fn(readFileToObject, "Read a file into a string object." ); // (Object filename, Object ignore, struct Environment* ignore2); #endif // STANDALONE #endif // PEBBLISP_PLFUNC_H