Ticket #1170 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

/docs/book/pir/ch04_variables.pod: Iterator does not work as documented

Reported by: jkeenan Owned by: jkeenan
Priority: minor Milestone:
Component: docs Version: 1.7.0
Severity: low Keywords:
Cc: Language:
Patch status: applied Platform:

Description

Based on /docs/book/pir/ch04_variables.pod -- or page 34 of the PIR book, I created and ran this file:

[study] 518 $ cat iter.pir
.sub main :main
    $P2 = new "ResizablePMCArray"
    $P2[0] = 10
    $P2[1] = 20
    $P1 = iter $P2
    $P5 = shift $P1
    say $P5
.end

[study] 519 $ ./parrot iter.pir
10

Based on the same source, I then created and ran this file, but running it produced an error:

[study] 520 $ cat xiter.pir 
.sub main :main
    $P2 = new "ResizablePMCArray"
    $P2[0] = 10
    $P2[1] = 20
    $P1 = new "Iterator", $P2
    $P5 = shift $P1
    say $P5
.end

[study] 521 $ ./parrot xiter.pir 
Direct creation of Iterator
current instr.: 'main' pc 11 (xiter.pir:6)

Am I doing something wrong? Is this merely a documentation error? Or does new "Iterator", $P2 not work as documented?

Thank you very much.

kid51

Change History

follow-up: ↓ 2   Changed 5 years ago by coke

At some point, iterator usage was reworked to avoid direct instantiation of iterators; that example should now read:

.sub main :main
    $P2 = new "ResizablePMCArray"
    $P2[0] = 10
    $P2[1] = 20
    $P1 = iter $P2
    $P5 = shift $P1
    say $P5
.end

in reply to: ↑ 1 ; follow-up: ↓ 4   Changed 5 years ago by jkeenan

  • priority changed from normal to minor
  • owner set to jkeenan
  • severity changed from medium to low
  • patch set to applied

Replying to coke:

At some point, iterator usage was reworked to avoid direct instantiation of iterators; that example should now read: {{{ .sub main :main $P2 = new "ResizablePMCArray" $P2[0] = 10 $P2[1] = 20 $P1 = iter $P2 $P5 = shift $P1 say $P5 .end }}}

So now only the first instance is valid Parrot code. Accordingly, I have deleted discussion of the second from the file in question:

Index: docs/book/pir/ch04_variables.pod
===================================================================
--- docs/book/pir/ch04_variables.pod    (revision 42215)
+++ docs/book/pir/ch04_variables.pod    (working copy)
@@ -1281,16 +1281,6 @@
 
 =end PIR_FRAGMENT
 
-Alternatively, you can also create an iterator by creating a new
-C<Iterator>X<Iterator PMC> PMC, passing the aggregate PMC as an
-initialization parameter to C<new>:
-
-=begin PIR_FRAGMENT
-
-  $P1 = new "Iterator", $P2
-
-=end PIR_FRAGMENT
-
 The C<shift>X<shift opcode> opcode extracts the next value from the iterator.
 
 =begin PIR_FRAGMENT

Applied in r42216. Will close ticket in 1-2 days unless there is further discussion.

Thank you very much.

kid51

  Changed 5 years ago by jkeenan

  • status changed from new to assigned

in reply to: ↑ 2   Changed 5 years ago by jkeenan

  • status changed from assigned to closed
  • resolution set to fixed

Replying to jkeenan:

Applied in r42216. Will close ticket in 1-2 days unless there is further discussion.

No complaints. Closing ticket.

kid51

Note: See TracTickets for help on using tickets.