Using SetValue with a list of points

mweissa2 shared this question 3 years ago

I am having trouble understanding how SetValue works with a list of points. Consider the following basic setup:

  • We have two lines, m and n intersecting at a point P.
  • Points A and B are constrained to lines m and n, respectively.
  • Define pointlist = {A,B}.

With this setup, the command SetValue[B,P] causes point B to move to point P, as expected. However, SetValue[pointlist(2), P] does not do anything, and SetValue[pointlist, 2, P] returns the error "Command SetValue: Illegal argument: List pointlist".

What is going wrong? Isn't pointlist(2) the same object as B? Why does the SetValue command work if I address it to B, but not to pointlist(2)? And shouldn't SetValue work with the syntax SetValue[ <list>, <number>, <object> ]?

Comments (8)


the right syntax for setvalue is setvalue[<point>,<point>] or setvalue[<list>,<list>]

the syntax

SetValue[ <List>, <Number>, <Object> ]Let n be the <Number>. The command SetValue sets the n-th element of a free list to the current value of the object. Number n can be at most 1 + length of L.

needs the list is free

ie: list={(1,2),(2,3)}; setvalue[list,2,P] works. if list={A,B} you need to modify B not the list


But why doesn't SetValue[pointlist(2), P] work? Isn't pointlist(2) in my setup a point?


pointlist(2) is not an object, it is a value

C=poinlist(2) is the C object with pointlist(2) value


I am afraid I don't understand. If A and B are points, and pointlist = {A,B}, then isn't pointlist(2) the same as B?


I am spanish and I am afraid I can not explain clearly the difference. If A is red and B is yellow, then isn't pointlist orange?

it is clear the answer is no.

when you write pointlist={A,B}, B is an ancestor of pointlist and pointlist(2) is a descendant of pointlist.

ie: C=B is not equal setvalue[C,B]. more C=B does not make C and B same points because they can get different properties. C=B says that value of C is equal to value of B ever

ie: D=if[<condition>,A,B] does not make D same A or B; the value of new object D is sometimes the value of A, sometimes the value of B.

I expect somebody can to explain it better


mathmagic is right.

it's about what depends on what. I give it a try but basicly I'm saying the same as he already did.

- A and B are free objects, you can move them on the two lines

- P= Intersect(m, n) is a dependent object, you can move it on its own.

You can use SetValue (P, <coordinates>) only within the conditions of the intersection, so you can't change it with the command SetValue. It it's the itersection point, that's it.

So it's important that for a dependent object SetValue only works within previously set definitions. It doesn"t overwrite them! If e.g. DD=Point(xAxis), you can redefine DD as DD = (1,2) but not SetValue(DD, (1,2)).

You can define P=(0,0) but then you overwrite the definition as intersection. P becomes a free point and from now on

it has nothing more to do with the intersection.

Now how is it with lists?

- When making a list of points {A, B}, you create a list with values, based on the coordinates of A and B.

As mathmagic tried to explain A and B are points, the list contains coordinates that can be represented as points,

but the elements of the list aren't independent objects which you can change freely.

The list depends on A and B and will change if AND ONLY IF you move A or B.

- You can use SetValue in combination with the list only in one direction: from the list to a next, depending object

e.g. if PP is an existing point: SetValue(P, pointlist(2))

pointlist(2) only works in one direction: to pick up the value of the object referred to

but never to edit this value in the list itself.

- So redefining the list itselfs can by changing A or B (the parent objects of the list)

or by roverwriting the definition list as e.g. pointlist= {A, P} instead of {A, B}, so giving up the dependence to A and B.

As with DD=Point(xAxis), you cannot use SetValue(DD, (2,1)) but you can redefine SetValue(DD, (2,0)) as it respects the preset definition to be on the xAxis.

For pointlist={A,B} the SetValue(pointlist(2), ...) command cannot work to change B. If you want to change the list you have to change A or B

Please read now the post of mathmagic once again, and maybe all together make it more clear.

And to illustrate this graphically I added a file with two lists:

list = {(1, 2), (3, 2), (5, 1)} is displayed as three green points. But if you try to drag one of these points, you'll see that you can't since it doens't consist of three free points. The only thing you can do in the graphic is to drag the whole list, so the three green points. Algebraicly SetValue(list(2),(1,0)) won't work.

list2={A, B} with A= (1,0) and B=(3,1) If you hide A and B, list2 is even not displayed. Its value will change in the Algebra View when dragging A or B, but SetValue(list(2),(1,0)) won't work.


Files: list.ggb

or briefly said: The key thing is to understand what listpoints={A,B} means.

It's likely to understand it as "Put A and B in a list" like apples in a basket.

This isn't the case. listpoints={A,B} is just a shortcut notation for "Make a list with the coordinates of A and B."

Since A and B aren't in the list themselves, just a referring to their coordinates, you cannot change them in the list itself. That's why the command SetValue(listpoints(1 or 2)) doesn't work. You only can change A or B where they are defined, and that's not in the list.



@mweissa2: in your example SetValue[B, P] is clearly shorter than SetValue[list1(2), P] so I assume you have some other usecase in mind? Maybe if you let us know what your goal is we could help a bit.

I think Chris and Mathmagic explained it already, another answer to your question is that list1(2) is a *copy* of B, so SetValue on it won't change B.

© 2020 International GeoGebra Institute