assocs.extras: Add a word set-once-at that throws if the key is already set.

locals-and-roots
Doug Coleman 2016-04-04 11:45:21 -07:00
parent 1aa8a432c7
commit 10cb7e12c1
1 changed files with 8 additions and 0 deletions

View File

@ -44,3 +44,11 @@ GENERIC: delete-value-at ( value assoc -- )
M: assoc delete-value-at
[ value-at* ] keep swap [ delete-at ] [ 2drop ] if ;
ERROR: key-exists value key assoc ;
: set-once-at ( value key assoc -- )
2dup ?at [
key-exists
] [
drop set-at
] if ;