Minipulating a script variable manipulates the original it’s set to?

The search_ genesis script pic
For some reason this block deletes the items in the list provided despite the list being set to a script variable

1:


2:


3:

It shouldn’t do that because it’s being set to a variable and then the variable is manipulated, not the original list

I made a better inplmentation of the block but still I wanna know why this happens

[edit]
any list passed to a function is passed by reference (and so changes to the copy will affect all references to the same list) unless explicitly copied using something like id of list operator

Strange that’s the case as it really shouldn’t be

It's not un- common in programming languages that data sets that can end up being large are passed by reference

I guess but it doesn’t make much sense in the context of snap
This would basically mean that
untitled script pic 48
This would set all variables to 7 (it does not)

In other languages it might be expected but in snap it wouldn’t be because of the way that snap, just is

Your example in post 2 works as you'd expect - it reports another list that excludes the 5 but doesn't affect the original list

image

Yes, that’s because “keep” explicitly reports a new list as stated in the help message
That means that


Is what you need to do instead of the expected
untitled script pic 50

Yes

All the basic HOFs do that

What does HOF stand for? I don’t know it

Higher Order Function - map/keep/combine - page 49 of the manual

Oh, I could have swore I read the entire manual
Guess that just slipped past me

Before creating a new topic, please search the forum first :slight_smile:

Could have sworn I read those too..

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.