List.reset() NotSupportedException

View: New views
5 Messages — Rating Filter:   Alert me  

List.reset() NotSupportedException

by psi-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


during some development i happened to change from handing over an
array, to handing over a list, to a function i'd written requiring an
IEnumerator.

and i got this;  "System.NotSupportedException: Operation is not
supported."

on checking it appears that IEnumerator.Reset(), doesn't have too.

( maybe it should have been named;   IEnumerator.MostlyReset()  ;p )

and so some questions arise;

* in boo List's case is this a chose, or is it yet to be implemented?

*  does this mean that, and can you rely on, none of the frameworks
functions ever requiring IEnumerators with reset implemented? even
though arrayList and the generic lists, do implement reset.

* can you have a type that implements reset when its easy and fires
off the exception when it gets hard? do any of the frameworks
IEnumerators do this?

* is the only real solution to proceed as if reset() didn't exist, and
that's why List doesn't have it?



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: List.reset() NotSupportedException

by Processor Devil :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

1. you haven't posted your code
2. neither Boo List or System.Collections.ArrayList have Reset method.
Try to be more specific

2009/10/5 psi <simon.place@...>

during some development i happened to change from handing over an
array, to handing over a list, to a function i'd written requiring an
IEnumerator.

and i got this;  "System.NotSupportedException: Operation is not
supported."

on checking it appears that IEnumerator.Reset(), doesn't have too.

( maybe it should have been named;   IEnumerator.MostlyReset()  ;p )

and so some questions arise;

* in boo List's case is this a chose, or is it yet to be implemented?

*  does this mean that, and can you rely on, none of the frameworks
functions ever requiring IEnumerators with reset implemented? even
though arrayList and the generic lists, do implement reset.

* can you have a type that implements reset when its easy and fires
off the exception when it gets hard? do any of the frameworks
IEnumerators do this?

* is the only real solution to proceed as if reset() didn't exist, and
that's why List doesn't have it?






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: List.reset() NotSupportedException

by Daniel Grunwald :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

psi wrote:
> during some development i happened to change from handing over an
> array, to handing over a list, to a function i'd written requiring an
> IEnumerator.
>
> and i got this;  "System.NotSupportedException: Operation is not
> supported."
>
> on checking it appears that IEnumerator.Reset(), doesn't have too.
>  
IEnumerator.Reset() is from the .NET 1.x days. Nearly all enumerators
written since .NET 2.0 will throw a NotSupportedException when you call
Reset on them. This includes the enumerators created using "yield" (both
in Boo and C#) and [for x in y] generator expressions in Boo.
Solution: Pass an IEnumerable instead of an IEnumerator; and call
GetEnumerator() multiple times if you need to iterate several times.
Never call IEnumerator.Reset.


Daniel



signature.asc (201 bytes) Download Attachment

Re: List.reset() NotSupportedException

by psi-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


thanks, (sorry for late response, ive been moving house)

i found this;
http://stackoverflow.com/questions/1468170/why-the-reset-method-on-enumerator-class-must-throw-a-notsupportedexception
which goes into this in more depth.

as the moment i have a rule of thumb, ( which is what we're left
with.) it appears that objects that are ICollection in the framework
supply IEnumerables with reset implemented, otherwise not.

specifically, arrays, listarrays, generic lists, do.

(maybe because its trivial to do.)

of course if you can't rely on reset() then its no use, as you say you
can use IEnumerable, and make a new enumerator, but this prevents
handing over a part consumed enumerator.

so, (and i had already done this before the original post), i have
memberwisecloned the enumerator at the beginning of a function, when i
needed a reset later.

Example, overloaded for IEnumerable/IEnumerator and with/without reset
()

import System
import System.Collections
import System.Collections.Generic

def pairs(en as IEnumerable):
        return pairs(en.GetEnumerator(),en.GetEnumerator())

def pairs(en as IEnumerator):
        return pairs(en,en.MemberwiseClone())

def pairs(en1 as IEnumerator,en2 as IEnumerator):
        return if not en1.MoveNext()
        previous=en1.Current
        while en1.MoveNext():
                yield en1.Current,previous
                previous=en1.Current
        en2.MoveNext()
        yield en2.Current,previous


def pairsUsingReset(en as IEnumerable):
        return pairsUsingReset(en.GetEnumerator())

def pairsUsingReset(en as IEnumerator):
        return if not en.MoveNext()
        previous=en.Current
        while en.MoveNext():
                yield en.Current,previous
                previous=en.Current
        en.Reset()
        en.MoveNext()
        yield en.Current,previous


p=pairs(System.Collections.ArrayList((1,2,3)))
print join(map(p,{x|return join(x,"-")}))

p=pairsUsingReset(System.Collections.ArrayList((1,2,3)))
print join(map(p,{x|return join(x,"-")}))


/*
# Output @ Sun Oct 11 15:02:28 BST 2009
2-1 3-2 1-3
2-1 3-2 1-3
# Used (interp) :  0:00.76 real,0.68 user,0.02 sys
*/

and in this particular case this has the unforeseen, and quite useful,
consequence, that the pairs are made using wherever the enumerator
was, when it was fed in.

unfortunately an enumerable could be implemented which somehow held
its position in a referenced object, but this appears not to be the
case with the main framework ICollections, but how reliable is that?
this is just the sort of thing interfaces were invented to solve!

BTW this is all on mono 2.4.2.3



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: List.reset() NotSupportedException

by psi-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> 1. you haven't posted your code

pointless, i know i could see the code.

> 2. neither Boo List or System.Collections.ArrayList have Reset method.

wrong, see below.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Boo Programming Language" group.
To post to this group, send email to boolang@...
To unsubscribe from this group, send email to boolang+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/boolang?hl=en
-~----------~----~----~----~------~----~------~--~---