diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-08-28 06:44:21 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-08-28 06:44:21 -0700 |
commit | 89752b07ce3695fa4302b5db3788fed7b51873d5 (patch) | |
tree | 2e93e716ad830ea49a8f85ac582b77338975500e | |
parent | 1f7a1d489ebfd6b3ef784005b2a52b327979fc58 (diff) | |
download | txr-89752b07ce3695fa4302b5db3788fed7b51873d5.tar.gz txr-89752b07ce3695fa4302b5db3788fed7b51873d5.tar.bz2 txr-89752b07ce3695fa4302b5db3788fed7b51873d5.zip |
expander: do dot-to-apply for meta-expressions.
The dot-to-apply transformation is now applied when
meta-expressions like @foo and @(bar) apparently occur in the
dot position.
This change is made in anticipation of a rewrite of the op
macro, in which the @1, @2, and @rest arguments will be
implemented as macrolets, rather than the ad-hoc, hacky code
walk currently performed in the transform_op function.
* eval.c (dot_meta_list_p): New static function.
(dot_to_apply): Detect the presence of a sys:var or
sys:expr argument in a form. If found, then turn
it and the remaining forms into a single compound
form which replaces them.
* txr.1: Update doc under Dot Position in Function Calls.
-rw-r--r-- | eval.c | 39 | ||||
-rw-r--r-- | txr.1 | 35 |
2 files changed, 65 insertions, 9 deletions
@@ -2883,18 +2883,49 @@ static val imp_list_to_list(val list) return out; } +static val dot_meta_list_p(val list) +{ + if (!consp(list)) + return list; + + list = cdr(list); + + for (; consp(list); list = cdr(list)) { + val a = car(list); + if (a == var_s || a == expr_s) + return list; + } + + return nil; +} + static val dot_to_apply(val form, val lisp1_p) { - if ((opt_compat && opt_compat <= 137) || proper_list_p(form)) { - return form; - } else { + val args = nil, meta = nil; + + if (opt_compat) { + if (opt_compat <= 137) + return form; + if (opt_compat <= 184 && proper_list_p(form)) + return form; + } + + if ((meta = dot_meta_list_p(form)) != nil) { + val pfx = ldiff(form, meta); + args = append2(cdr(pfx), cons(meta, nil)); + } else if (!proper_list_p(form)) { + args = imp_list_to_list(cdr(form)); + } + + if (args) { val sym = car(form); - val args = imp_list_to_list(cdr(form)); return cons(sys_apply_s, cons(if3(lisp1_p, sym, list(fun_s, sym, nao)), args)); } + + return form; } val expand_forms(val form, val menv) @@ -11549,10 +11549,7 @@ for obvious reasons, namely that does not mean that there is a compound form in the dot position, but denotes an alternate spelling for .codn "(a b c foo z)" , -where foo behaves as a variable. (There exists a special exception to this, -namely that the meta-numbers and meta-symbols of the -.code op -operator can be used in the dot position). +where foo behaves as a variable. If the dot position of a compound form is an atom, then the behavior may be understood according to the following transformations: @@ -11562,7 +11559,35 @@ may be understood according to the following transformations: [f a b c ... . x] --> [apply f a b c ... x] .cble -Effectively, the dot notation constitutes a shorthand for +In addition to atoms, meta-expressions and meta-variables can appear in the dot +position, even though their underlying syntax is comprised of a compound +expression. This appears to work according to a transformation pattern +which superficially appears to be the same as that for atoms: + +.cblk + (f a b c ... . @x) --> (apply (fun f) a b c ... @x) +.cble + +However, in this situation, the +.code @x +is actually the form +.code "(sys:var x)" +and the dotted form is actually a proper list. The transformation is +in fact taking place over a proper list, like this: + +.cblk + (f a b c ... sys:var x) --> (apply (fun f) a b c ... (sys:var @x)) +.cble + +That is to say, the \*(TL form expander reacts to the presence of a +.code sys:var +or +.code sys:expr +atom in embedded in the form. That symbol and the items which follow it +are wrapped in an additional level of nesting, converted into a single +compound form element. + +Effectively, in all these cases, the dot notation constitutes a shorthand for .codn apply . Examples: |