diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | match.c | 2 | ||||
-rw-r--r-- | txr.1 | 63 |
3 files changed, 53 insertions, 20 deletions
@@ -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 @@ -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; @@ -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 |