[bug] Fold selector fails on streams

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug] Fold selector fails on streams

Roman
Issue status update for
http://smalltalk.gnu.org/node/655
Post a follow up:
http://smalltalk.gnu.org/project/comments/add/655

 Project:      GNU Smalltalk
 Version:      <none>
 Component:    Base classes
 Category:     bug reports
 Priority:     normal
 Assigned to:  Unassigned
 Reported by:  Roman
 Updated by:   Roman
 Status:       active

Excuse me for my english.
Streams are Iterable. Class Iterable defines a method fold, which must
be sent to any Stream. But in the current implementation method fold can
be sent only to instances of PositionableStream, because method fold is
based on isEmpty selector. For example, Generator does not provide
isEmpty selector:

   st> x:=Generator on: [:g| g yield: 1. g yield: 3 ]
   a Generator
   st> x fold: [:a :b| a+b]
   Object: Generator new "<0x403bc180>" error: did not understand
#isEmpty



My solution is:

  fold: aBlock [
     |marker acc|
     acc:=marker:=Object new.
     self do: [:i| acc:=acc==marker ifTrue: [i]
                                    ifFalse: [aBlock value: acc value:
i] ].
     acc==marker ifTrue: [ SystemExceptions.EmptyCollection signalOn:
self ]
                 ifFalse: [^acc] ]



_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [bug] Fold selector fails on streams

Paolo Bonzini-3
Issue status update for
http://smalltalk.gnu.org/project/issue/655
Post a follow up:
http://smalltalk.gnu.org/project/comments/add/655

 Project:      GNU Smalltalk
 Version:      <none>
 Component:    Base classes
 Category:     bug reports
 Priority:     normal
 Assigned to:  Unassigned
 Reported by:  Roman
 Updated by:   bonzinip
-Status:       active
+Status:       fixed

Applied, thanks.



_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk