specter

Latest version: 1.1.3
2018-10-06T10:58:00.000100Z

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..

nathanmarz 2018-10-06T12:42:23.000100Z

@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])

1
manas_marthi 2018-10-08T16:03:27.000100Z

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

manas_marthi 2018-10-09T12:44:40.000100Z

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_marthi 2018-10-09T13:05:36.000100Z

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..

nathanmarz 2018-10-09T16:06:41.000100Z

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

nathanmarz 2018-10-09T16:07:03.000100Z

for the first I would just do that with a reduce

manas_marthi 2018-10-10T10:32:52.000100Z

Noted thank you

nathanmarz 2018-10-06T12:42:42.000100Z

the second is more efficient

2018-10-06T12:42:48.000100Z

Thank you @nathanmarz!

2018-10-06T12:43:19.000100Z

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