diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-07-11 14:44:19 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-07-11 14:44:19 -0700 |
commit | a6f6072761d124c60793325bc512048b0f31f5a3 (patch) | |
tree | d7cbb320dd5ffdd58afe9f2588c876141caca261 | |
parent | 812e63ca8f42637f6a856e66f57678cbb0472821 (diff) | |
download | txr-a6f6072761d124c60793325bc512048b0f31f5a3.tar.gz txr-a6f6072761d124c60793325bc512048b0f31f5a3.tar.bz2 txr-a6f6072761d124c60793325bc512048b0f31f5a3.zip |
listener: new *-1, *-2 ... *-20 macros.
* arith.h (minus_s): Declared.
* eval.c (reg_symacro): Changing to external linkage.
* eval.h (macro_time_s, reg_symacro): Declared.
* parser.c (repl): Bind the *-1 to *-20 symbol macros.
* txr.1: Documented.
-rw-r--r-- | arith.h | 2 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | eval.h | 2 | ||||
-rw-r--r-- | parser.c | 13 | ||||
-rw-r--r-- | txr.1 | 19 |
5 files changed, 36 insertions, 2 deletions
@@ -25,7 +25,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -extern val mod_s, bit_s; +extern val mod_s, bit_s, minus_s; val make_bignum(void); val bignum(cnum cn); val bignum_from_long(long l); @@ -6014,7 +6014,7 @@ void reg_var(val sym, val val) mark_special(sym); } -static void reg_symacro(val sym, val form) +void reg_symacro(val sym, val form) { loc pcdr = gethash_l(lit("internal initialization"), top_smb, sym, nulloc); val binding = deref(pcdr); @@ -28,6 +28,7 @@ extern val dwim_s, lambda_s, progn_s, vector_lit_s, vec_list_s, list_s; extern val hash_lit_s, hash_construct_s, struct_lit_s, qref_s, uref_s; extern val tree_lit_s, tree_construct_s; +extern val macro_time_s; extern val eval_error_s, if_s, call_s, identity_s; extern val eq_s, eql_s, equal_s, less_s; extern val car_s, cdr_s; @@ -66,6 +67,7 @@ val macro_form_p(val form, val menv); val func_get_name(val fun, val env); void reg_varl(val sym, val val); void reg_var(val sym, val val); +void reg_symacro(val sym, val val); void reg_fun(val sym, val fun); void reg_mac(val sym, val fun); val set_get_symacro(val sym, val form); @@ -60,6 +60,7 @@ #include "parser.h" #include "regex.h" #include "itypes.h" +#include "arith.h" #include "buf.h" #include "vm.h" #include "txr.h" @@ -1459,6 +1460,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) 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('>')); + cnum i; env_vbind(dyn_env, stderr_s, out_stream); @@ -1467,6 +1469,17 @@ val repl(val bindings, val in_stream, val out_stream, val env) reg_varl(car(binding), cdr(binding)); } + for (i = 1; i <= 20; i++) { + val name = format(nil, lit("*-~d"), num_fast(i), nao); + val sym = intern(name, user_package); + reg_symacro(sym, list(dwim_s, result_hash_sym, + list(macro_time_s, + list(mod_s, + list(minus_s, var_counter_sym, + num_fast(i), nao), + num_fast(100), nao), nao), nao)); + } + reg_varl(result_hash_sym, result_hash); lino_set_completion_cb(ls, provide_completions, 0); @@ -73541,6 +73541,25 @@ Thus, up to the previous hundred results can be referenced: 10 .brev +.coNP Symbol Macros @, *-1 @, *-2 @, ... @ *-20 +The listener provides small number of symbol macros for referencing the +results of previous commands in a relative. The macro +.code *-1 +refers to the value of the immediately previous command. The macro +.code *-2 +refers to the value of the command before that one and so on. + +Note: each of these macros expands to a reference to the +.code *r +vector, according to the following pattern: + +.mono + *-1 --> [*r (mod (- *v 1) 100)] + *-2 --> [*r (mod (- *v 2) 100)] + ... + *-20 --> [*r (mod (- *v 20) 100)] +.onom + .coNP Variable @ *n .desc The listener variable |