Handbook
Glossary
new-nth ( val i seq -- seq' )
Persistent sequence protocol
Next:
ppush ( val seq -- seq' )
Vocabulary
persistent
.
sequences
Inputs
val
an
object
i
an
integer
seq
a
sequence
Outputs
seq'
a
sequence
Generic word contract
Persistent analogue of
set-nth
. Outputs a new sequence with the
i
th element replaced by
val
.
Definition
IN:
persistent.sequences
GENERIC:
new-nth
( val i seq -- seq' )
Methods
USING:
accessors
kernel
math
persistent.sequences
persistent.vectors
persistent.vectors.private
;
M:
persistent-vector
new-nth
2dup
count>>
=
[
nip
ppush
]
[
clone
2dup
tail-offset
>=
[
[
node-mask
]
dip
[
node-set-nth
]
change-tail
]
[
[
(new-nth)
]
change-root
]
if
]
if
;
USING:
kernel
persistent.sequences
sequences
;
M:
sequence
new-nth
clone
[
set-nth
]
keep
;