trip logs / gnuvola

Trip Log 2017-09-22 h14

Next on the “indices style upgrade” trip (see accompanying tarball to follow along) is patch 3, the first in the set to make a change that the user can perceive (both patch 1 and patch 2 are “internal”).  Patch 3 has delta -8 (negative like patch 1, but more “satisfying” for reasons explained further ahead) and footprint 16, and involves three top-level procs.  For your convenience, I excerpt the interesting portions here, prefixed with line numbers: 

     4  Subject: [PATCH 3/8] tl-mkindex: Omit leading "Trip Log " from all titles.
     9  * sub/tl-mkindex (consult-db query): If ‘e.title’ starts
    10  with "Trip Log ", return the portion sans that prefix;
    11  otherwise, return ‘e.title’ directly.
    12  (clean-title): Delete proc.
    13  (interesting-elements leaf-entries): Don't bother w/ ‘clean-title’.
    22  @@ -224,7 +224,9 @@ (define (consult-db upath-ignored where-clause)
    23     (define query
    24       (parse+make-SELECT-tree
    25        #t `(t.tag (array_agg (substring e.upath ,(1+ upath-ignored)))
    26  -                (array_agg e.title))
    27  +                (array_agg (coalesce (substring e.title #:FROM
    28  +                                                "^Trip Log (.*)")
    29  +                                     e.title)))
    30        #:from '((#:left-join #:natural
    31                              (t . tltags)
    32                              (e . tlent)))
    33  @@ -253,15 +255,6 @@ (define (consult-db upath-ignored where-clause)
    34      (apply map one (cols<-tuples-result
    35                      (fetch-tuples)))))
    37  -(define clean-title                     ; TODO: parameterize
    38  -  (let* ((cruft "Trip Log ")
    39  -         (cruft-len (string-length cruft)))
    40  -    ;; clean-title
    41  -    (lambda (s)
    42  -      (if (string-prefix? cruft s)
    43  -          (substring s cruft-len)
    44  -          s))))
    45  -
    46   (define (slash-count s)
    47     (string-count s #\/))
    49  @@ -294,8 +287,7 @@ (define (interesting-elements)
    51         (define (leaf-entries)
    52           (list url
    53  -              (map clean-title
    54  -                   (map cdr distinct-refs))))
    55  +              (map cdr distinct-refs)))
    57         (define (dir-entries)

First cross-check: Is patch 3 user-visible impact reflected in the title (line 4)?  Yes, it lacks the “int” present in both patch 1 and 2. 

Well, better to say “maybe” for now, and award (or not) trust to the patch (and its author) only after we understand what's going on.  After all, the “int” is a mere label; could be merited, could be lipstick on a pig.  Another curiosity is the space between “Log” and the double-quote — intentional or evidence of sloppiness?  Hmmm... 

Second cross-check: Do the procs named in the commit message (lines 9, 12, 13) match the ones on the hunks' at-at-lines (lines 22, 33, 49)?  Sure, there's ‘consult-db’ and all the rest. 

Oops — “and all the rest” is not entirely true!  Yes, proc ‘interesting-elements’ is fine (lines 13, 49), but no, proc ‘clean-title’ (line 12) is not named in hunk 2's at-at-line (line 33).  That's because the program that generates these patch files is completely accurate for the non-TEXT portion of the at-at-line, and only approximate for the TEXT portion: 

@@ -K,L +N,M @@     TEXT
─────────────── ─────────────
  (accurate)    (approximate)

In this case, it approaches the truth by scanning backward from the change site (in the file) for a line that has an open-paren in the first column (i.e., flush left, no indentation).  That line (or an initial fragment of it) becomes the TEXT portion of the hunk's at-at-line. 

This works reasonably well for changes inside a form, but utterly fails when the change is purely subtractive (here, patch 3 hunk 2) or additive (before, patch 1 hunk 1) involving a complete top-level form.  So it goes; sometimes you can't always get what you want :-D. 

This discrepency-driven detour is actually a good segue into the next round of cross-checks; we've already taken the trouble to verify that hunk 2 (lines 33-48) corresponds to its description (line 12) in the commit message, and furthermore, the description has merit.  Easy peasy!  Building on this, common sense says that when you get rid of THING, you can't use THING any more, which we can contextualize as: 

if you remove proc ‘clean-title’,   [h2-condition]
you should not use ‘clean-title’    [h2-consequence] let's see if we can find evidence of ‘h2-consequence’ in the other hunks and descriptions.  As it turns out, yes, hunk 3 (lines 49-58) shows the disappearance of ‘clean-title’ (present in before-text, absent in after-text) and its description (line 13) has a (corresponding) snub. 

Cool, hunk 2 and hunk 3 seem legit, at least, in terms of these structural and surface-semantics cross-checks — we'll dig deeper a little further on.  How about hunk 1?  Here is its description, excerpted from the commit message, reformatted slightly and prefixed with line numbers: 

1  (consult-db query):
2  If ‘e.title’ starts with "Trip Log ",
3  return the portion sans that prefix;
4  otherwise, return ‘e.title’ directly.

The location of the change (line 1) looks fine.  Check.  On the other hand, the structure of the (grammatically valid) sentence departs from the V OBJ ADV pattern we've seen until now.  Instead, we have a conditional clause (line 2) and two consequent clauses (lines 3, 4), both in the imperative mood with verb “return”.  We can think of the structure as “If CONDITION (then do) CONSEQUENCE-YES (else do) CONSEQUENCE-NO”.  Applied to a similar sentence of the same form — “If rain is in the weather forecast, bring an umbrella, otherwise bring a hackysack.” — we have: 

CONDITION        --  rain is in the weather forecast
CONSEQUENCE-YES  --  bring an umbrella
CONSEQUENCE-NO   --  bring a hackysack

To evaluate a sentence with this structure we perform two steps: (a) evaluate CONDITION to obtain a yes/no result; (b) based on this result, evaluate either CONSEQUENCE-YES or CONSEQUENCE-NO, but not both.  (Of course, this example is not as general as it could be — the truly dedicated would bring a hackysack regardless, but you get the picture, right?) 

“And of course, ttn, you try to distract with those fancy hypertext clicky things and a cutesy (but, granted, probably sincere) homage to a truly original educator.  What weirdness are you hiding now?!” 

Ah, glad to see another way to ask “What am I missing?” (despite the sneering tone :-P).  Before answering, I should remind you that weird can be wonderful, too, but that transformation is something only you can control.  And that's the key word here: control. 

In all the commit messages we've examined until now, the implicit subject of the imperative mood sentences has always been “the programmer”, i.e., the agent of change, the one who performs the actions, the one in control.  The actions (i.e., the verbs in those sentences) concord; all of them (“move”, “use”, “add”, “delete”) are text editing operations for the programmer to perform.  Indeed, most of the cross-checks we've done boil down to simulated (in our mind) edits.  Also, implicit for the actions are the timing of the action (prior to the commit) and qualification (unconditionally). 

The last two aspects are what's new and weird here (patch 3 hunk 1 description).  The sentence is clearly NOT unconditional (it has a CONDITION).  Furthermore, throughout the sentence there are nouns (‘e.title’, “portion”) and verbs (“starts”, “return”) that cannot be explained in the surface (textual) context.  So, what context do all these corroborating (and perhaps — remember, we like to maintain a skeptical stance — self-consistent) clues point to? 

Well, to lead you to discover the answer for yourself, I'm going to detour a bit and jeopardize my nerd cred by declaring that the following analogy is indeed based on experience — I have actually been invited to parties (plural) and interacted with other human beings.  (Granted, most of the interactions involved musical instruments, but that only “underscores” the point. :-D)  OK, enough teasing.  The clue is: 

Q: What is your name?
Q: Who do you know here?
Q: _______________

Did you figure out the analogy?  If not, no worries, all will be revealed in the next installment.  Please join me there! 

Copyright (C) 2017 Thien-Thi Nguyen