summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--match.c2
-rw-r--r--txr.163
3 files changed, 53 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index c4cd9611..98659aa8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-11-10 Kaz Kylheku <kaz@kylheku.com>
+
+ * match.c (v_fun): Bugfix: if there is material after
+ the function call, decline it; it is a horizontal context.
+
+ * txr.1: Discussion and examples of calls that are
+ in a horizontal context.
+
2011-11-09 Kaz Kylheku <kaz@kylheku.com>
* txr.1: Documented horizontal function definitions and calls
diff --git a/match.c b/match.c
index 896380af..0d9c16c5 100644
--- a/match.c
+++ b/match.c
@@ -2844,7 +2844,7 @@ static val v_fun(match_files_ctx *c)
val sym = first(first_spec);
val func = car(uw_get_func(sym));
- if (func) {
+ if (func && !rest(specline)) {
val args = rest(first_spec);
val params = car(func);
val ub_p_a_pairs = nil;
diff --git a/txr.1 b/txr.1
index dc7e78ba..c5452ecb 100644
--- a/txr.1
+++ b/txr.1
@@ -2884,39 +2884,64 @@ it goes to the vertical one.
Example:
- Query: @(define which (x))@(bind x "horizontal")@(end)
- @(define which (x))
- @(bind x "vertical")
- @(end)
- @(which fun)
+ Query: @(define which (x))@(bind x "horizontal")@(end)
+ @(define which (x))
+ @(bind x "vertical")
+ @(end)
+ @(which fun)
- Output: fun="vertical"
+ Output: fun="vertical"
Not only does this call go to the vertical function, but
it is in a vertical context.
+If only a horizontal function is defined, then that is the one which is called,
+even if the call is the only element in the line. This takes place in a
+horizontal character-matching context, which requires a line of input which can
+be traversed:
+
Example:
- Query: @(define which (x))@(bind x "horizontal")@(end)
- @(which fun)
+ Query: @(define which (x))@(bind x "horizontal")@(end)
+ @(which fun)
+
+ Data: ABC
- Data: ABC
+ Output: false
- Output: false
+The query failed. Why? Because since @(which fun) is in horizontal mode,
+it matches characters in a line. Since the function body consists
+of @(bind ...) which doesn't match any characters, the function
+call requires an empty line to match. The line ABC is not empty,
+and so there is a matching failure. The following
+example corrects this:
+
+Example:
-The query failed. Why? Because @(which fun) is in horizontal mode,
-which means that it matches a line. What line does it match?
-It matches the empty line. The reason is that the the call
-@(which fun) contains only a @(bind ...) which doesn't match any
-characters. In the following example, an empty line is supplied:
+ Query: @(define which (x))@(bind x "horizontal")@(end)
+ @(which fun)
- Query: @(define which (x))@(bind x "horizontal")@(end)
- @(which fun)
+ Data: <empty line>
+
+ Output: fun="horizontal"
+
+A call made in a clearly horizontal context will ignore
+the vertical definition, if any, and require the horizontal function.
+In the next example, the call is followed by trailing material,
+placing it in a horizontal context. Leading material will
+do the same thing:
+
+Example:
- Data: <empty line>
+ Query: @(define which (x))@(bind x "horizontal")@(end)
+ @(define which (x))
+ @(bind x "vertical")
+ @(end)
+ @(which fun)B
- Output: fun="horizontal"
+ Data: B
+ Output: fun="horizontal"
.SS Nested Functions