-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels