Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

del a[:], del a[3:], del [:3], i.e. del with slices doesn't work #45

Open
mobluse opened this issue Nov 8, 2021 · 1 comment
Open

Comments

@mobluse
Copy link

mobluse commented Nov 8, 2021

del with slices doesn't work. E.g.

Welcome to Snek version 1.7
> a=['a', 'b', 'c', 'd', 'e', 'f']
> a[:]
['a', 'b', 'c', 'd', 'e', 'f']
> del a[:]
<stdin>:4 Syntax error at "\n".
+ 
> a[:]
['a', 'b', 'c', 'd', 'e', 'f']
> del a[3:]
<stdin>:7 Syntax error at "\n".
+ 
> del a[:3]
<stdin>:9 Syntax error at "\n".
+ 
> a[:]
['a', 'b', 'c', 'd', 'e', 'f']

E.g. MicroPython handles this:

MicroPython v1.15-64-g1e2f0d280 on 2021-06-30; micro:bit v2.0.0 with nRF52833
Type "help()" for more information.
>>> a=['a', 'b', 'c', 'd', 'e', 'f']
>>> a[:]
['a', 'b', 'c', 'd', 'e', 'f']
>>> del a[:]
>>> a[:]
[]
>>> a=['a', 'b', 'c', 'd', 'e', 'f']
>>> del a[3:]
>>> a[:]
['a', 'b', 'c']
>>> a=['a', 'b', 'c', 'd', 'e', 'f']
>>> del a[:3]
>>> a[:]
['d', 'e', 'f']
>>> a
['d', 'e', 'f']

Maybe it would take up too much memory in Snek to handle slices with del, but if some code can be reused for this purpose without adding memory it would be good to have. At least, I think, it should be documented that slices don't work with del since they seem to work everywhere else in Snek.

@keith-packard
Copy link
Owner

Thanks! I didn't realize that they should work. I can add some code for at least some platforms :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants