diff --git a/CHANGELOG.md b/CHANGELOG.md index d16b76cb..a1f1cb56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## 1.17.0 - 2021-08-21 +- Add the `-E` flag for one-liners with the `short-fn` syntax for argument passing. - Add support for threaded abstract types. Threaded abstract types can easily be shared between threads. - Deprecate the `thread` library. Use threaded channels and ev instead. - Channels can now be marshalled. diff --git a/janet.1 b/janet.1 index 448a8ae5..bd4ee7f3 100644 --- a/janet.1 +++ b/janet.1 @@ -5,6 +5,7 @@ janet \- run the Janet language abstract machine .B janet [\fB\-hvsrpnqk\fR] [\fB\-e\fR \fISOURCE\fR] +[\fB\-E\fR \fISOURCE ...ARGUMENTS\fR] [\fB\-l\fR \fIMODULE\fR] [\fB\-m\fR \fIPATH\fR] [\fB\-c\fR \fIMODULE JIMAGE\fR] @@ -162,6 +163,11 @@ Read raw input from stdin and forgo prompt history and other readline-like featu Execute a string of Janet source. Source code is executed in the order it is encountered, so earlier arguments are executed before later ones. +.TP +.BR \-E\ code arguments +Execute a single Janet expression as a Janet short-fn, passing the remaining command line arguments to the expression. This allows +more concise one-liners with command line arguments. + .TP .BR \-d Enable debug mode. On all terminating signals as well the debug signal, this will diff --git a/src/boot/boot.janet b/src/boot/boot.janet index cf311c12..a7828158 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2425,7 +2425,7 @@ (def res (compile form (fiber/getenv (fiber/current)) "eval")) (if (= (type res) :function) (res) - (error (res :error)))) + (error (get res :error)))) (defn parse `Parse a string and return the first value. For complex parsing, such as for a repl with error handling, @@ -3540,6 +3540,7 @@ -v : Print the version string -s : Use raw stdin instead of getline like functionality -e code : Execute a string of janet + -E code arguments... : Evaluate an expression as a short-fn with arguments -d : Set the debug flag in the REPL -r : Enter the REPL after running all scripts -R : Disables loading profile.janet when JANET_PROFILE is present @@ -3578,6 +3579,15 @@ (set *no-file* false) (eval-string (in args (+ i 1))) 2) + "E" (fn E-switch [i &] + (set *no-file* false) + (def subargs (array/slice args (+ i 2))) + (def src ~|,(parse (in args (+ i 1)))) + (def thunk (compile src)) + (if (function? thunk) + ((thunk) ;subargs) + (error (get thunk :error))) + math/inf) "d" (fn [&] (set *debug* true) 1) "w" (fn [i &] (set *warn-level* (get-lint-level i)) 2) "x" (fn [i &] (set *error-level* (get-lint-level i)) 2)