From 9c1e2974fad18576c0051d046f03d799d2879fdc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 3 Oct 2022 22:10:32 -0700 Subject: New: %fun% mechanism for current function name. * eval.c (pct_fun_s): New symbol variable, holding the usr:%fun% symbol. (fun_macro_env): New static function. (do_expand): For defun and defmacro, use fun_macro_env to establish an environment binding the %fun% symbol macro, and expand everything in that environment. (eval_init): Intern the %fun% symbol, initializing pct_fun_s, and also register a global symbol macro in that name so that we can freely use %fun% everywhere without worrying that the code will blow up. E.g. a logging macro can use it to get the function name, but still be useful in a top-level form outside of a named function. * stdlib/struct.tl (sys:meth-lambda): New macro. (defstruct, defmeth): Use sys:meth-lambda as a replacement for lambda to set up the %fun% symbol macro. In the :init case which doesn't use a lambda, an open-coded symacrolet does the job. * tests/019/pct-fun.tl: New file. * tests/019/pct-fun.expected: Likewise. * txr.1: Documented. * stdlib/doc-syms.tl: Updated. --- tests/019/pct-fun.expected | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/019/pct-fun.expected (limited to 'tests/019/pct-fun.expected') diff --git a/tests/019/pct-fun.expected b/tests/019/pct-fun.expected new file mode 100644 index 00000000..d7da7ee4 --- /dev/null +++ b/tests/019/pct-fun.expected @@ -0,0 +1,18 @@ +(foo :init) +(foo :postinit) +(foo foo) +(foo bar) +(foo :fini) +(foo :postfini) +function +function2 +mac +(foo :init) +(foo :postinit) +(foo foo) +(foo bar) +(foo :fini) +(foo :postfini) +function +function2 +mac -- cgit v1.2.3