unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* SXML example showing diff between node-reduce and node-join
@ 2021-01-11 13:44 Matt Wette
  2021-01-11 22:01 ` Ricardo Wurmus
  2021-01-11 22:07 ` tomas
  0 siblings, 2 replies; 3+ messages in thread
From: Matt Wette @ 2021-01-11 13:44 UTC (permalink / raw)
  To: Guile User

Hi All,

I'm going through the (sxml xpath) low-level routines to try to get a
solid understanding of what they do.  I just can't come up with an example
to show how node-reduce and node-join differ.   If someone could provide
such an example I would really appreciate it.  Takers?

My end goal is to write up a cookbook type note to show peeps how to use it.

Thanks,
Matt




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: SXML example showing diff between node-reduce and node-join
  2021-01-11 13:44 SXML example showing diff between node-reduce and node-join Matt Wette
@ 2021-01-11 22:01 ` Ricardo Wurmus
  2021-01-11 22:07 ` tomas
  1 sibling, 0 replies; 3+ messages in thread
From: Ricardo Wurmus @ 2021-01-11 22:01 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user


Hi Matt,

> I'm going through the (sxml xpath) low-level routines to try to get a
> solid understanding of what they do.  I just can't come up with an example
> to show how node-reduce and node-join differ.   If someone could provide
> such an example I would really appreciate it.  Takers?

Here’s an example:

--8<---------------cut here---------------start------------->8---
(define sxml
  (xml->sxml "\
<foo>
  <bar>baz</bar>
  <wow>great</wow>
  <boo>
    <wow>
      <b>superb</b>
    </wow>
  </boo>
  <bye>
    <hello>
      <world>
        <excellent>
          <wow>today</wow>
        </excellent>
      </world>
   </hello>
  </bye>
  <greet>
    <hello>
      <world>
        <wow>yesterday</wow>
      </world>
    </hello>
  </greet>
</foo>"
             #:trim-whitespace? #true))

(define wow-converter
  (lambda (node-or-nodeset)
    (if (and (string? node-or-nodeset)
             (string=? "yesterday" node-or-nodeset))
        '(new "WOW!")
        node-or-nodeset)))

(define joined
  ((node-join (sxpath '(//))
              (node-trace "visiting")
              wow-converter
              (sxpath '(*text*)))
   sxml))

(define reduced
  ((node-reduce (sxpath '(//))
                (node-trace "visiting")
                wow-converter
                (sxpath '(*text*)))
   sxml))
--8<---------------cut here---------------end--------------->8---

The node-trace converter already shows that they behave differently.
The wow-converter only gets to see the plain string “yesterday” when it
is used with node-join.

Clearly, this is not the best example one could come up with, but I hope
it’s a start.

-- 
Ricardo



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: SXML example showing diff between node-reduce and node-join
  2021-01-11 13:44 SXML example showing diff between node-reduce and node-join Matt Wette
  2021-01-11 22:01 ` Ricardo Wurmus
@ 2021-01-11 22:07 ` tomas
  1 sibling, 0 replies; 3+ messages in thread
From: tomas @ 2021-01-11 22:07 UTC (permalink / raw)
  To: Matt Wette; +Cc: Guile User

[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]

On Mon, Jan 11, 2021 at 05:44:41AM -0800, Matt Wette wrote:
> Hi All,
> 
> I'm going through the (sxml xpath) low-level routines to try to get a
> solid understanding of what they do.  I just can't come up with an example
> to show how node-reduce and node-join differ.   If someone could provide
> such an example I would really appreciate it.  Takers?
> 
> My end goal is to write up a cookbook type note to show peeps how to use it.

OK, I'll bite. But slowly. I'm not sure I'll reach to the end, but
have always been curious wrt the more interesting parts of SX...

CAVEAT: the word "combinator" alone makes my head spin. I know what
it is, when I read the definition slowly. But reading code written
in this style is still a bit challenging.

So it's quite possible that someone else beats me to it. That's
fine -- I'll eagerly learn from her/his answers :)

For a start, I'm reading [1], where Oleg Kiselyov and Kirill Lisovski
actually show some usage examples for both of the above functions.

Next, I'll actually try to play with them. Might take me a couple
of days. (After having no customers for a while, a couple of them
arrived at the same time. They always do, sigh, but I still love
them ;-)

Cheers

[1] http://okmij.org/ftp/papers/SXs-talk.pdf
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-11 22:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 13:44 SXML example showing diff between node-reduce and node-join Matt Wette
2021-01-11 22:01 ` Ricardo Wurmus
2021-01-11 22:07 ` tomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).