Skip to content

Instantly share code, notes, and snippets.

@wayland
Last active February 21, 2025 23:59

Revisions

  1. wayland revised this gist Feb 21, 2025. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions infinite-loop.raku
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    #!/usr/bin/raku

    use lib '../XML/improve-Positional/lib/';

    use XML;

    sub WalkTreeMatch(@inputs) {
  2. wayland renamed this gist Feb 21, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. wayland created this gist Feb 21, 2025.
    35 changes: 35 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    $ ./infinite-loop.raku | head -50
    -----
    inputs count: 2
    inputs: [("A",), ("B", "C", ("E", "F", "G", {:A("E"), :E("A")}))]
    input count: 1
    input: $("A",)
    input child: "A"
    nameList
    Got to A
    input count: 3
    input: $("B", "C", ("E", "F", "G", {:A("E"), :E("A")}))
    input child: "B"
    nameList
    Got to B
    Got to C
    -----
    inputs count: 4
    inputs: ("E", "F", "G", {:A("E"), :E("A")})
    -----
    inputs count: 3
    inputs: (my \XML::Element_3298568580792 = XML::Element.new(name => "rootnode", nodes => [XML::Text.new(text =
    input count: 3
    input: (my \XML::Element_3298568580792 = XML::Element.new(name => "rootnode", nodes => [XML::Text.new(text =
    input child: (my \XML::Text_3298571614976 = XML::Text.new(text => "\n\t", parent => (my \XML::Element_329856858079
    nameXML::Element
    -----
    inputs count: 3
    inputs: (my \XML::Element_3298568580792 = XML::Element.new(name => "rootnode", nodes => [XML::Text.new(text =
    input count: 3
    input: (my \XML::Element_3298568580792 = XML::Element.new(name => "rootnode", nodes => [XML::Text.new(text =
    input child: (my \XML::Text_3298571614976 = XML::Text.new(text => "\n\t", parent => (my \XML::Element_329856858079
    nameXML::Element
    -----
    inputs count: 3
    ....
    51 changes: 51 additions & 0 deletions infinite-loop.raku
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/usr/bin/raku

    use lib '../XML/improve-Positional/lib/';

    use XML;

    sub WalkTreeMatch(@inputs) {
    my (@retvals);
    # Unindented lines were just inserted for debugging, and should be removed later (but see output)
    say "-----";
    say "inputs count: " ~ @inputs.elems;
    say "inputs: " ~ @inputs.raku().substr(0..100);
    for @inputs -> $input { # Input nodes in NodeSet
    $input ~~ Positional or next;
    say "input count: " ~ ($input[]).elems;
    say "input: " ~ $input.raku().substr(0..100);
    say "input child: " ~ $input[0].raku().substr(0..100);
    say "name" ~ $input.^name();
    for @$input -> $child { # Children of node from NodeSet
    if ($child ~~ Positional) {
    WalkTreeMatch($child) ==> @retvals;
    } else {
    if $child.can('name') {
    say "Got to " ~ $child.name;
    } else {
    say "Got to " ~ $child;
    }
    }
    }
    }
    return @retvals;
    }

    # Test on regular array
    my (@inputs) = ( ('A',), ('B','C', ('E','F','G', %( 'A' => 'E', 'E' => 'A'))));

    WalkTreeMatch(@inputs);

    # Test with XML
    my ($xmlstring) = qq:to/EOT/;
    <rootnode>
    <item level="1">
    <inner>text</inner>
    </item>
    </rootnode>
    EOT

    my ($doc) = from-xml($xmlstring);


    WalkTreeMatch($doc.root);