I just wanted to point out that my definition can be shortened a little (by sorting in order from largest coordinate to smallest):
#(define (last-bar grob)
;; return the X-coordinate of the last barline on a line
(let* ((sys (ly:grob-system grob))
(array (ly:grob-object sys 'all-elements))
(grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
(lst (filter (lambda (x) (eq? 'BarLine (grob-name x)))
(ly:grob-array->list array)))
(bar-coords (sort (map (lambda (x) (cdr (ly:grob-extent x sys X))) lst) >)))
(car bar-coords)))