diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-08-02 20:06:18 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-08-02 20:06:18 -0700 |
commit | 1d9f2661a2f151b9b264dd696821730e2e6e3e46 (patch) | |
tree | 817c4551efabd00747ce7195e8e54d9399699473 /match.c | |
parent | b267c86f0bb146ff0919aa7d7cf83e7d8e5e916c (diff) | |
download | txr-1d9f2661a2f151b9b264dd696821730e2e6e3e46.tar.gz txr-1d9f2661a2f151b9b264dd696821730e2e6e3e46.tar.bz2 txr-1d9f2661a2f151b9b264dd696821730e2e6e3e46.zip |
Bi-directional string tree match for non-vars.
There is an inconsistency in @(bind) in that
given @(bind x y) where x is a variable, both
directions are tried for a string tree match.
x could be tree of strings and y a string atom,
or vice versa. But if x is just an atom, or
a Lisp evaluation, then only one direction is
tried. @(bind @(list "a" "b") "a") succeeds,
but @(bind "a" @(list "a" "b")) fails.
* match.c (dest_bind): Test both directions
in the scalar and Lisp evaluated cases of the
left hand side. Subject to compatibility,
just in case.
* txr.1: Compat note added.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -366,8 +366,14 @@ static val dest_bind(val spec, val bindings, val pattern, lisp_evaled = t; } - if (lisp_evaled) - return if3(tree_find(value, ret, swap_12_21(testfun)), bindings, t); + if (lisp_evaled) { + if (!opt_compat || opt_compat >= 184) + if (tree_find(ret, value, testfun)) + return bindings; + if (tree_find(value, ret, swap_12_21(testfun))) + return bindings; + return t; + } while (consp(piter) && consp(viter)) { @@ -386,6 +392,10 @@ static val dest_bind(val spec, val bindings, val pattern, return funcall2(testfun, piter, viter) ? bindings : t; } return bindings; + } else if ((!opt_compat || opt_compat >= 184) && + tree_find(pattern, value, testfun)) + { + return bindings; } else if (tree_find(value, pattern, swap_12_21(testfun))) { return bindings; } |