summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parser.c11
-rw-r--r--stdlib/doc-syms.tl1
-rw-r--r--txr.129
3 files changed, 39 insertions, 2 deletions
diff --git a/parser.c b/parser.c
index 96fb4cde..30c63f03 100644
--- a/parser.c
+++ b/parser.c
@@ -76,7 +76,7 @@
val parser_s, unique_s, circref_s;
val listener_hist_len_s, listener_multi_line_p_s, listener_sel_inclusive_p_s;
-val listener_pprint_s, listener_greedy_eval_s;
+val listener_pprint_s, listener_greedy_eval_s, listener_auto_compound_s;
val rec_source_loc_s, read_unknown_structs_s, read_bad_json_s;
val json_s;
val intr_s;
@@ -1618,6 +1618,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
#endif
val pprint_var = lookup_global_var(listener_pprint_s);
val greedy_eval = lookup_global_var(listener_greedy_eval_s);
+ val auto_parens = lookup_global_var(listener_auto_compound_s);
val rw_f = func_f1v(out_stream, repl_warning);
val saved_dyn_env = set_dyn_env(make_env(nil, nil, dyn_env));
val brackets = mkstring(num_fast(repl_level), chr('>'));
@@ -1749,8 +1750,12 @@ val repl(val bindings, val in_stream, val out_stream, val env)
hist_save(ls, in_stream, out_stream, histfile, histfile_w, hist_len_var);
counter = prev_counter;
} else {
+ val expr = if2(form != read_k,
+ if3(auto_parens && cdr(forms),
+ forms,
+ cons(progn_s, forms)));
val value = if3(form != read_k,
- eval_intrinsic(cons(progn_s, forms), nil, env),
+ eval_intrinsic(expr, nil, env),
read_eval_ret_last(nil, prev_counter,
in_stream, out_stream));
val pprin = cdr(pprint_var);
@@ -2021,6 +2026,7 @@ void parse_init(void)
listener_sel_inclusive_p_s = intern(lit("*listener-sel-inclusive-p*"), user_package);
listener_pprint_s = intern(lit("*listener-pprint-p*"), user_package);
listener_greedy_eval_s = intern(lit("*listener-greedy-eval-p*"), user_package);
+ listener_auto_compound_s = intern(lit("*listener-auto-compound-p*"), user_package);
rec_source_loc_s = intern(lit("*rec-source-loc*"), user_package);
read_unknown_structs_s = intern(lit("*read-unknown-structs*"), user_package);
read_bad_json_s = intern(lit("*read-bad-json*"), user_package);
@@ -2044,6 +2050,7 @@ void parse_init(void)
reg_var(listener_sel_inclusive_p_s, t);
reg_var(listener_pprint_s, nil);
reg_var(listener_greedy_eval_s, nil);
+ reg_var(listener_auto_compound_s, nil);
reg_var(rec_source_loc_s, nil);
reg_var(read_unknown_structs_s, nil);
reg_var(read_bad_json_s, nil);
diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl
index d1f31708..42f92032 100644
--- a/stdlib/doc-syms.tl
+++ b/stdlib/doc-syms.tl
@@ -14,6 +14,7 @@
("*filters*" "N-00E6A902")
("*gensym-counter*" "N-0387B1B1")
("*hash-seed*" "N-0041D85A")
+ ("*listener-auto-compound-p*" "N-03717672")
("*listener-greedy-eval-p*" "N-002B819C")
("*listener-hist-len*" "N-007B676F")
("*listener-multi-line-p*" "N-02C5CACF")
diff --git a/txr.1 b/txr.1
index 61355fff..6edd9efb 100644
--- a/txr.1
+++ b/txr.1
@@ -91830,6 +91830,35 @@ The object
.code 4
is self-evaluating, and so the greedy evaluation process stops.
+.coNP Special variable @ *listener-auto-compound-p*
+.desc
+The special variable
+.code *listener-auto-compound-p*
+controls whether or the listener is operating in "auto compound
+expression" mode. The default value is
+.codn nil ,
+disabling the feature.
+
+Normally, an input line can contain multiple expressions, which
+are treated as if they were combined into a single expression by
+.codn progn .
+Thus all the expressions are evaluated, and the value from
+the last one is printed.
+
+In auto compound mode, the behavior changes. An input line
+which consists of multiple expressions is turned into a compound
+form whose constituents are those items. Thus, for instance,
+the input
+.code "+ 2 2"
+is treated as the compound expression
+.code "(+ 2 2)"
+resulting in
+.code 4
+being calculated.
+
+When a single expression is input, it is evaluated as-is, and thus
+in that case auto compound expression mode makes no difference.
+
.coNP Special variable @ *doc-url*
.desc
The special variable