From 10cb7e12c1cfb4759ffeff3bc2f8e54900019e6a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 4 Apr 2016 11:45:21 -0700 Subject: [PATCH] assocs.extras: Add a word set-once-at that throws if the key is already set. --- extra/assocs/extras/extras.factor | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extra/assocs/extras/extras.factor b/extra/assocs/extras/extras.factor index cf63ee8472..80e2521d4f 100644 --- a/extra/assocs/extras/extras.factor +++ b/extra/assocs/extras/extras.factor @@ -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 ; \ No newline at end of file -- 2.34.1