#10743: Add iterator protocol to EclObject
---------------------------+------------------------------------------------
   Reporter:  nbruin       |       Owner:  was            
       Type:  enhancement  |      Status:  needs_review   
   Priority:  major        |   Milestone:  sage-4.6.2     
  Component:  interfaces   |    Keywords:  ECL lisp ecllib
     Author:  Nils Bruin   |    Upstream:  N/A            
   Reviewer:               |      Merged:                 
Work_issues:               |  
---------------------------+------------------------------------------------
Changes (by nbruin):

  * status:  new => needs_review


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=EclListIterator(EclObject("(1 2 3)"))
> sage: type(I)
> <type 'sage.libs.ecl.EclListIterator'>
> sage: [i for i in I]
> [<ECL: 1>, <ECL: 2>, <ECL: 3>]
> sage: [i for i in EclObject("(1 2 3)")]
> [<ECL: 1>, <ECL: 2>, <ECL: 3>]
> sage: EclListIterator(EclObject("1"))
> Traceback (most recent call last):
> ...
> TypeError: ECL object is not iterable
> }}}

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
 }}}

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10743#comment:1>
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