#10743: Add iterator protocol to EclObject
-----------------------------+----------------------------------------------
 Reporter:  nbruin           |         Owner:  nbruin                           
     
     Type:  enhancement      |        Status:  closed                           
     
 Priority:  major            |     Milestone:  sage-4.7                         
     
Component:  interfaces       |    Resolution:  fixed                            
     
 Keywords:  ECL lisp ecllib  |        Author:  Nils Bruin                       
     
 Upstream:  N/A              |      Reviewer:  Karl-Dieter Crisman, Jean-Pierre 
Flori
   Merged:  sage-4.7.alpha3  |   Work_issues:                                   
     
-----------------------------+----------------------------------------------
Description changed by jdemeyer:

Old description:

> Experience teaches that EclObjects wrapping LISP lists would often be
> convenient to iterate over in list comprehensions and for loops.
> Pythonizing the EclObject would work recursively, which is often not what
> is required: you just want to work with EclObjects wrapping the members
> of the list. The iterator protocol seems to yield a convenient and well-
> defined interface. Examples:
>
> {{{
> sage: from sage.libs.ecl import *
> sage: [i for i in EclObject("(1 2 3)")]
> [<ECL: 1>, <ECL: 2>, <ECL: 3>]
> sage: [i for i in EclObject("(1 2 . 3)")]
> [<ECL: 1>, <ECL: 2>, <ECL: 3>]
> sage: [i for i in EclObject("NIL")]
> []
> sage: [i for i in EclObject("T")]
> Traceback (most recent call last):
> ...
> TypeError: ECL object is not iterable
> }}}
> ----
> Depends on [http://trac.sagemath.org/sage_trac/ticket/10766 #10766].
>
> Apply attachment:trac_10743-ecl-iter_p1.patch
>
> If it doesn't screw up #7377 applying properly (which it shouldn't, as
> #7377 only touches ecl.pyx in one small place far from here), also apply
> attachment:trac_10743-reviewer.patch

New description:

 Experience teaches that EclObjects wrapping LISP lists would often be
 convenient to iterate over in list comprehensions and for loops.
 Pythonizing the EclObject would work recursively, which is often not what
 is required: you just want to work with EclObjects wrapping the members of
 the list. The iterator protocol seems to yield a convenient and well-
 defined interface. Examples:

 {{{
 sage: from sage.libs.ecl import *
 sage: [i for i in EclObject("(1 2 3)")]
 [<ECL: 1>, <ECL: 2>, <ECL: 3>]
 sage: [i for i in EclObject("(1 2 . 3)")]
 [<ECL: 1>, <ECL: 2>, <ECL: 3>]
 sage: [i for i in EclObject("NIL")]
 []
 sage: [i for i in EclObject("T")]
 Traceback (most recent call last):
 ...
 TypeError: ECL object is not iterable
 }}}
 ----
 Depends on #10766.

 Apply [attachment:trac_10743-ecl-iter_p1.patch] and
 [attachment:trac_10743-reviewer.patch]

 See also #7377.

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10743#comment:17>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to