insert -> put

This commit is contained in:
Elliot Glaysher 2017-10-13 23:28:11 -07:00
parent 22dca3032f
commit c2b8d61fa2
2 changed files with 19 additions and 19 deletions

View File

@ -110,7 +110,7 @@
m
=^ first gen (range:gen 0 100)
=^ second gen (range:gen 0 100)
$(m (insert:dct:new-hoon m first second), i +(i))
$(m (put:dct:new-hoon m first second), i +(i))
::
:: || %test
::
@ -508,29 +508,29 @@
++ test-member
(expect-eq (member four 4) %.y "member")
::
++ test-insert-with
++ test-put-with
=+ ints=(from-list [["one" 1] ["two" 2] ["three" 3] ["four" 4] ~])
%^ expect-eq
(insert-with ints "three" 2 add)
(put-with ints "three" 2 add)
(from-list [["one" 1] ["two" 2] ["three" 5] ["four" 4] ~])
"insert-with"
"put-with"
::
++ test-insert-with-key
++ test-put-with-key
%^ expect-eq
(insert-with-key four 4 "four" |=({a/@ud b/tape c/tape} (weld (scow %ud a) b)))
(put-with-key four 4 "four" |=({a/@ud b/tape c/tape} (weld (scow %ud a) b)))
(from-list [[1 "one"] [2 "two"] [3 "three"] [4 "4four"] ~])
"insert-with-key"
"put-with-key"
::
++ test-insert-lookup-with-key
++ test-put-lookup-with-key
%^ expect-eq
%- insert-lookup-with-key :^
%- put-lookup-with-key :^
four
4
"five"
|=({key/@ud old/tape new/tape} new)
:- `"four"
(from-list [[1 "one"] [2 "two"] [3 "three"] [4 "five"] ~])
"insert-lookup-with-key"
"put-lookup-with-key"
::
++ test-delete
%^ expect-eq

View File

@ -851,7 +851,7 @@
::
:> # %insertion
+|
++ insert
++ put
:> inserts a new key/value pair, replacing the current value if it exists.
|* {a/(dict) key/* value/*}
|- ^+ a
@ -873,7 +873,7 @@
[n.a l.a d]
[n.d [n.a l.a l.d] r.d]
::
++ insert-with
++ put-with
:> inserts {key}/{value}, applying {fun} if {key} already exists.
|* {a/(dict) key/* value/* fun/$-({* *} *)}
|- ^+ a
@ -894,7 +894,7 @@
[n.a l.a d]
[n.d [n.a l.a l.d] r.d]
::
++ insert-with-key
++ put-with-key
:> inserts {key}/{value}, applying {fun} if {key} already exists.
|* {a/(dict) key/* value/* fun/$-({* * *} *)}
|- ^+ a
@ -915,7 +915,7 @@
[n.a l.a d]
[n.d [n.a l.a l.d] r.d]
::
++ insert-lookup-with-key
++ put-lookup-with-key
:> combines insertion with lookup in one pass.
|* {a/(dict) key/* value/* fun/$-({* * *} *)}
|- ^- {(maybe _value) _a}
@ -1174,7 +1174,7 @@
%^ foldl:ls new-list
`(dict _*fun _q.+.n.-.a)`~
|= {m/(dict _*fun _q.+.n.-.a) p/_i.-.new-list}
(insert-with m -.p +.p combine)
(put-with m -.p +.p combine)
::
++ fold
:> performs a fold on all the values in {a}.
@ -1281,7 +1281,7 @@
%^ foldl:ls a
`(dict _p.-.i.-.a _q.+.i.-.a)`~
|= {m/(dict _p.-.i.-.a _q.+.i.-.a) p/_i.-.a}
(insert m p)
(put m p)
::
++ from-list-with
:> creates a dict from a list, with {fun} resolving duplicates.
@ -1289,7 +1289,7 @@
%^ foldl:ls a
`(dict _*fun _q.+.i.-.a)`~
|= {m/(dict _*fun _q.+.i.-.a) p/_i.-.a}
(insert-with m -.p +.p fun)
(put-with m -.p +.p fun)
::
:: todo: without a natural ordering, association lists and gates to operate
:: on them probably don't make sense. i'm skipping them for now.
@ -1389,8 +1389,8 @@
=+ x=(fun n.a)
~! x
?- -.x
$& [(insert (union -.lr -.rr) p.n.a +.x) (union +.lr +.rr)]
$| [(union -.lr -.rr) (insert (union +.lr +.rr) p.n.a +.x)]
$& [(put (union -.lr -.rr) p.n.a +.x) (union +.lr +.rr)]
$| [(union -.lr -.rr) (put (union +.lr +.rr) p.n.a +.x)]
==
::
:: ++split, ++split-lookup and ++split-root do not make sense without