mirror of
https://github.com/janet-lang/janet
synced 2025-11-04 17:43:02 +00:00
Tweak apply and short-fn docstrings
This commit is contained in:
@@ -2345,17 +2345,11 @@
|
|||||||
|
|
||||||
(defmacro short-fn
|
(defmacro short-fn
|
||||||
```
|
```
|
||||||
Shorthand for `fn`. Arguments are given as `$n`, where `n` is the 0-indexed
|
Shorthand for `fn`. Arguments are given as `$n`, where `n` is the
|
||||||
argument of the function. `$` is also an alias for the first (index 0) argument.
|
0-indexed argument of the function. `$` is also an alias for the
|
||||||
The `$&` symbol will make the anonymous function variadic if it appears in the
|
first (index 0) argument. The `$&` symbol will make the anonymous
|
||||||
body of the function, and can be combined with positional arguments.
|
function variadic if it appears in the body of the function, and
|
||||||
|
can be combined with positional arguments.
|
||||||
Example usage:
|
|
||||||
|
|
||||||
(short-fn (+ $ $)) # A function that doubles its arguments.
|
|
||||||
(short-fn (string $0 $1)) # accepting multiple args.
|
|
||||||
|(+ $ $) # use pipe reader macro for terse function literals.
|
|
||||||
|(+ $&) # variadic functions
|
|
||||||
```
|
```
|
||||||
[arg &opt name]
|
[arg &opt name]
|
||||||
(var max-param-seen -1)
|
(var max-param-seen -1)
|
||||||
|
|||||||
@@ -1002,12 +1002,11 @@ static void make_apply(JanetTable *env) {
|
|||||||
janet_quick_asm(env, JANET_FUN_APPLY | JANET_FUNCDEF_FLAG_VARARG,
|
janet_quick_asm(env, JANET_FUN_APPLY | JANET_FUNCDEF_FLAG_VARARG,
|
||||||
"apply", 1, 1, INT32_MAX, 6, apply_asm, sizeof(apply_asm),
|
"apply", 1, 1, INT32_MAX, 6, apply_asm, sizeof(apply_asm),
|
||||||
JDOC("(apply f & args)\n\n"
|
JDOC("(apply f & args)\n\n"
|
||||||
"Applies a function to a variable number of arguments. Each element in args "
|
"Applies a function f to a variable number of arguments. Each "
|
||||||
"is used as an argument to f, except the last element in args, which is expected to "
|
"element in args is used as an argument to f, except the last "
|
||||||
"be an array-like. Each element in this last argument is then also pushed as an argument to "
|
"element in args, which is expected to be an array or a tuple. "
|
||||||
"f. For example:\n\n"
|
"Each element in this last argument is then also pushed as an "
|
||||||
"\t(apply + 1000 (range 10))\n\n"
|
"argument to f."));
|
||||||
"sums the first 10 integers and 1000."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint32_t error_asm[] = {
|
static const uint32_t error_asm[] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user