diff --git a/src/env.c b/src/env.c index ea4d16f..c4df943 100644 --- a/src/env.c +++ b/src/env.c @@ -283,12 +283,16 @@ void printColored(const char* code) } 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\"" + "Gets a string with help text for the given function.\n" + "For example:\n" + " (? islist) => \"(islist (1 2 3)) => T\"" ) { - const char* symbol = params[0].string; + const char* symbol; + if (!length || !params[0].string || params[0].string[0] == '\0') { + symbol = "?"; + } else { + symbol = params[0].string; + } for (int i = 0; i < currentHelp; i++) { struct helpText h = helpTexts[i]; if (strcmp(symbol, h.symbol) == 0) { @@ -308,6 +312,7 @@ fn(help, return text; } } + return nullTerminated("Help not found!"); } diff --git a/src/pebblisp.c b/src/pebblisp.c index 2934e99..a01464a 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -606,6 +606,12 @@ void repl(struct Environment* env) break; } add_history(buf); + if (buf[0] == '?' && (buf[1] == ' ' || buf[1] == '\0')) { + char* oldBuf = buf; + buf = malloc(sizeof(char) * strlen(buf + 3)); + sprintf(buf, "(%s)", oldBuf); + free(oldBuf); + } Object o = parseEval(buf, env); size_t length; char *output = stringObj(&o, &length); diff --git a/src/web.h b/src/web.h index 9c539d7..6bd243f 100644 --- a/src/web.h +++ b/src/web.h @@ -9,16 +9,17 @@ fn(startServer, ); fn(addGetRoute, - "Note: Implementation bugs currently prevent using an inline lambda.\n" - " (def homepage (fn () (\"Hello, world!\")))\n" - " (get \"/\" homepage)\n" - " (def queryPage (fn (req) (req's queryParams)))\n" - " (get \"/x\" queryPage)\n" + "Adds a GET route at the given path with the given function.\n" + " (get \"/\" (fn () (\"Hello, world!\")))\n" + " (get \"/parampath\" (fn (req) (req's queryParams)))\n" " (serve)\n" + "Also see: (serve)\n" ); fn(addPostRoute, - "Note: Implementation bugs currently prevent using an inline lambda.\n" - " (def homepage (fn () (\"Hello, world!\")));(post \"/\" homepage)\n" + "Adds a POST route at the given path with the given function.\n" + "Note: Can't do anything with POSTed data yet.\n" + " (post \"/\" (fn () (\"Hello, world!\")))\n" " (serve)\n" + "Also see: (serve)\n" );