Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 4929 days ago | link | parent

"Right now 'del looks like a smorgasbord of special-case utilities which could all have shorter tailor-made alternatives."

That was my first reaction as well. I see one general new idea here, though: to extend indexing to return not just places but slices like in python and Go.

  (= l '(1 2 3 4))
  (l 1) ; 2
  (l 0 2) ; '(1 2)
  (= (l 0 2) '(3)) ; l is now '(3 3 4)
Now del becomes identical to setting a range to nil.

  (= l '(1 2 3 4))
  (= l.0 nil) ; l is now (nil 2 3 4)
  (= (l 0 1) nil) ; l is now (2 3 4)
Would this be useful?


1 point by Pauan 4929 days ago | link

"Would this be useful?"

It is in Python. Would it be useful in Arc? We already have cut, which does the same thing:

  (cut '(1 2 3 4) 0 2) -> (1 2)
But having a shorter syntax is nice. Would it be useful to assign to it? I think so, for the same reasons that it's nice in Python.

-----

1 point by akkartik 4929 days ago | link

"It is [useful] in Python."

Python doesn't allow assigning to slices, I think.

-----

1 point by Pauan 4929 days ago | link

It absolutely does! It also allows for deleting indices/slices:

  foo = [1, 2, 3, 4]
  foo[0:2] = [0]
  foo -> [0, 3, 4]

  del foo[0:1]
  foo -> [3, 4]
In fact, there's an idiomatic way to delete every element in a list:

  del foo[:]
  foo -> []

-----

2 points by akkartik 4929 days ago | link

Ah.

And del is identical to assigning to [].

  >>> foo = [0, 1, 2]
  >>> foo[0:1] = []
  >>> foo
  [1, 2]
I stand corrected.

-----