#16073: Python 3 preparation: The semantic of map() function is changed
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  wluebbe                |       Status:  needs_review
           Type:         |    Milestone:  sage-6.4
  enhancement            |   Resolution:
       Priority:  major  |    Merged in:
      Component:         |    Reviewers:
  distribution           |  Work issues:
       Keywords:         |       Commit:
  python3                |  8331e848b1ab06e87ed5114926d941083ff0ae7f
        Authors:         |     Stopgaps:
  Wilfried Luebbe        |
Report Upstream:  N/A    |
         Branch:         |
  public/16073           |
   Dependencies:         |
-------------------------+-------------------------------------------------

Comment (by darij):

 {{{
 - return "".join(map(lambda x: self._character_to_code[x], string))
 + return "".join([self._character_to_code[x] for x in string])
 }}}
 Wondering if this is a good step forward, given that you can join an
 iterator to a string:
 {{{
 >>> map(lambda x: x+x, ['a','b','c'])
 <map object at 0x7fd747ddee10>
 >>> "blah".join(map(lambda x: x+x, ['a','b','c']))
 'aablahbbblahcc'
 }}}
 (Python 3).

 {{{
 - map(
 - lambda x: chr(ord(x) + 49),
 - list(str(num[0]))),
 + [chr(ord(x) + 49) for x in list(str(num[0]))],
 }}}
 Can't we get rid of the `list`?

 {{{
 - a,b,c,d,e,f = map(G,R)
 + a,b,c,d,e,f = list(map(G,R))
 }}}
 This seems to not be necessary:
 {{{
 >>> a,b,c = iter([1,2,3])
 >>> a
 1
 >>> b
 2
 >>> c
 3
 }}}

 This is unnecessary:
 {{{
 - if all(map(lambda s: s.is_final, state.label())):
 + if all([s.is_final for s in state.label()]):
 }}}
 If anything then `all` definitely works on iterators.

 --------

 Here is the thing that worries me the most: There are tools for automatic
 translation of python2 into 3. I am not sure if we should, or are going
 to, release them on the Sage library; but if we are, I would rather not do
 any manual work unless we can make sure that it will not interfere with
 the automated changes. I have a hunches that a well-written bot could do
 better than some of the changes in this patch (for instance, it should be
 a rule that `all(map(...))` can stay as it is rather than being replaced
 by `all(list(map(...)))`), thus leading to better speed, whereas with the
 changes already done it would not simplify them back to what they should
 be. This does not speak against edits such as replacing `list` variables
 by `list_` and likewise, which are the right thing to do either way. But I
 would be wary of making changes that possibly complicate the situation
 without knowing that it will become untangled when the time comes to
 actually switch to python 3.

--
Ticket URL: <http://trac.sagemath.org/ticket/16073#comment:18>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to