At the moment the map ins/del syntaxes are:
m[k] = v // ins
m[k] = v, true // ins
m[k] = v, false // del
One proposal has been to make del:
m[k] = _
But it occurs to me that if that were done the whole syntax could be
collapsed to:
m[k] = v // ins
m[k] = _ // del
Which avoids the need to use a value when deleting.
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Programming in Python 3" - ISBN 0321680561
http://www.qtrac.eu/py3book.html
The existing way has the cute ability to make the insertion/deletion
choice at runtime, but I don't think I've seen a compelling place
where that's been used where a simple if block wouldn't be bearable.
Dave.
It's a nice syntactic trick but it does not make me happy,
having insert vs delete be indicated by a pretend value
(ie _, which serves this purpose nowhere else).
I'd prefer
m[k] = ()
which at least has a notion of "nothing here guv", but
is rather too clever for my taste and uncomfortably
fragile.
A horrible twofold overloading of -- would allow
m -- k
but I wouldn't dare suggest
m ++ k
as the (an) idiom for putting things in maps.
Chris
--
Chris "allusive" Dollin
Agree,
-1 for a new built-in (del, rem, remove, etc...)
M;
I think this is a really bad idea, because it introduces something
new into Go's semantics.
Go functions are given values. How those values are built is not
of interest to the function. This is true even for the magic functions
`make` and `new` which have Go types as arguments.
For del(m[k]) to work, del has to look at the structure of the
argument /expression/, not at its /value/, because the
run-time operation needs two things: a map m and a key k,
separately.
While the language and compiler are of course to pick any tango
they like to dance, having a single isolated place in the language
where something that isn't a type has structure that must be
respected by a builtin does not strike me as a good idea.
del(m,k) would be miles better; I'm not saying I like it, but
it would be better.