Fork me on GitHub
#specter
<
2018-10-06
>
kingcode10:10:00

I am trying to set values at different indexes within a flat vector in once call, e.g. [0 0 0 0] => [0 1 0 3]. I tried (setval [(nthpath 1)(nthpath 3)] [1 3] [0 0 0 0]) but got a runtime exc….What should I use instead? Thanks in advance..

nathanmarz12:10:23

@kingcode there's two approaches:

(setval (subselect (multi-path 1 3)) [1 3] [0 0 0 0])
or
(multi-transform
  (multi-path
    [1 (terminal-val 1)]
    [3 (terminal-val 3)])
  [0 0 0 0])

4
manas_marthi16:10:27

Hi Nathan, if I have a vector of vectors with index & new-values,or a vector of maps with index & new-value pairs, then how do I rewrite the above. please advise.. thank you

nathanmarz19:10:11

do you have an example input/output of what you're trying to do?

manas_marthi12:10:40

I am thinking of this data

input vec: [:a  :b  :c ... :m ... :z]

A map of indices and new values
{
 2 :c2
 12 :m2
 25 :z2
}
Or a map of old value new value pairs
{
 :c :c2
 :m :m2
 :z :z2
}

output vec: [:a  :b  :c2 ... :m2 ... :z2] 

manas_marthi13:10:36

Essentially how to deal with the scenario when I have a lot of values to be replaced and not just a handful of indices that can be hardcoded in the multipath selector expression..

nathanmarz16:10:41

for the latter you can do (transform [ALL #(contains? replacements %)] replacements data)

nathanmarz16:10:03

for the first I would just do that with a reduce

manas_marthi10:10:52

Noted thank you

nathanmarz12:10:42

the second is more efficient

kingcode12:10:19

Looking forward to learn and use more of this great library:)