Giter VIP home page Giter VIP logo

Comments (8)

dpgeorge avatar dpgeorge commented on August 24, 2024

Yep, not yet implemented! This should be easy to do, just add the relevant functionality to py/objlist.c, in the function list_binary_op. Maybe someone wants to have a go at it? :)

from micropython.

nickovs avatar nickovs commented on August 24, 2024

I don't know if I will be able to find the time but I'll take a look. The related extend() method for lists is also missing but it's the same code.

While we're at it, string multiplication is also missing.

from micropython.

nickovs avatar nickovs commented on August 24, 2024

Thanks for that Chipaca. I had been tinkering on this this evening too but it seem that you got there first. Since you are already working on this shall I stop on the RT_BINARY_OP_INPLACE_ADD, RT_BINARY_OP_MULTIPLY and RT_BINARY_OP_INPLACE_MULTIPLY too?

I was also implementing list.extend(), which is similar to RT_BINARY_OP_INPLACE_ADD save that it needs to work with any iterable object. This lead me down three different ratholes which it would be helpful if Damien could clarify. These are (in no particular order):

  1. Can we count on the garbage collector to clear up heap objects allocated in the course of executing C code (such as iterator for other objects) without any hints being given? I'm used to coding for CPython so documenting the differences here would be helpful.
  2. What is the correct style for iterating over the items in an utterable object from within the C code? If the answer to the question above is 'yes' then I presume I just call the getiter function in the object structure and have at it.
  3. What is the correct style for throwing Python exceptions (such as type errors) from within C code? The binary_op table lets me just return NULL but if I am in a function like list.extend() and need to return a meaningful error I need to do some more.

While I can probably glean the answers to these from the rest of the code but it would help people getting started if we could have the answers to these written down somewhere.

from micropython.

chipaca avatar chipaca commented on August 24, 2024

As that was my first patch to the project I was waiting for feedback before moving on. So don't stop if you're doing the other ones.

Do, however, consider this: list.extend is exactly the same as list.__iadd__. That is, in CPython 3.3:

>>> a = []
>>> a += range(10)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

from micropython.

nickovs avatar nickovs commented on August 24, 2024

Aha. I had not noticed that:

l = [1,2,3]
l = l + 'foo'

behaves completely differently to:

l = [1,2,3]
l += 'foo'

Learn something new every day!

from micropython.

pfalcon avatar pfalcon commented on August 24, 2024

Now we have #42 & #43 . Bottom line: we should somehow sync who's going to/working on something. The process I propose is you post a ticket (if one doesn't exist), and also comment(s) on related ticket where you know it was discussed. Example: #46.

from micropython.

chipaca avatar chipaca commented on August 24, 2024

Yeap.

On Fri, Jan 3, 2014 at 11:06 AM, Paul Sokolovsky
[email protected]:

Now we have #42 #42 & #43#43. Bottom line: we should somehow sync who's going to/working on something.
The process I propose is you post a ticket (if one doesn't exist), and also
comment(s) on related ticket where you know it was discussed. Example: #46#46
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/39#issuecomment-31516581
.

John Lenton ([email protected]) ::: http://chipaca.com

from micropython.

pfalcon avatar pfalcon commented on August 24, 2024

Both list addition and multiplication is implemented now, with unit tests.

from micropython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.