diff options
| author | 2021-08-21 13:12:19 -0500 | |
|---|---|---|
| committer | 2021-08-21 13:16:41 -0500 | |
| commit | 846c9e5e129ecc77015da456cdcce880f437d639 (patch) | |
| tree | 608c761f2625bfaea295666750b1efc49fd27fc5 | |
| parent | Address #765. Make `assert` into a macro. (diff) | |
Fix #759 - Add -E flag for one-liners.
Use the `short-fn` DSL here for argument passing.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | janet.1 | 6 | ||||
| -rw-r--r-- | src/boot/boot.janet | 12 |
3 files changed, 18 insertions, 1 deletions
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. @@ -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] @@ -163,6 +164,11 @@ Execute a string of Janet source. Source code is executed in the order it is enc 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 cause the debugger to come up in the REPL. Same as calling (setdyn :debug true) in a 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) |
