Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have a function that requires a list is as input. I.e.


Now, if I pass a variable as Dynamic like this

pts={{0.1,0.1} , {0.5,0.1}, {0.1, 0.5}};

everything works as expected as long as I don't use parts of the list. If I use a part of a list then things no longer work as expected ( by me ).

Another example

g[point_] := Slider2D[point]
p = {.1, .1}

that works as expected, and this one

g[point_] := Slider[point[[1]]]
p = {.1, .1}

that does not.

Question: What behaviour of Dynamic explains the above?

share|improve this question
up vote 7 down vote accepted

You should try to just follow the flow of your replacements, then you clearly see what's going wrong. In you first definition everything goes as you expect:

g[point_] := Slider2D[point]
g[Dynamic[p]] =  (* Becomes => Slider2D[Dynamic[p]] *) 

But in the second case you are stripping away the Dynamic tag:

g[point_] := Slider[point[[1]]]
g[Dynamic[p]] (*Becomes =>Slider[Dynamic[p][[1]]]  Which becomes => Slider[p]*)

Note: This is why your output is Slider[{0.1, 0.1}].

If you want slider Dynamically editing point[[1]] you need the Dynamic wrapper to be around it, so you would do:

g[point_] := Slider[point /. Dynamic[var_] :> Dynamic[var[[1]]]]
p = {.1, .1}

Though I would personally define this as:

g[Dynamic[point_]] := Slider[Dynamic[point[[1]]]]

Simply to make it clear that I'm defining the behavior for dynamically changeable variables.

share|improve this answer
I go for how you do it personally. Dynamic is what makes Mma powerful AND difficult, if you ask me. – nilo de roock Aug 7 '12 at 13:35

Perhaps this helps to see what is going on:

f[l_] := {Head[l], Head[l[[1]]]};
pts = {{0.1, 0.1}, {0.5, 0.1}, {0.1, 0.5}};


{List, List}
{Dynamic, List}

Why? Because even though Dynamic[{1,2,3}] gets printed as {1,2,3}, this is just output formatting; in reality, it remains Dynamic[{1,2,3}]. This is why when you look at the Head of the dynamic object passed to f you see Dynamic, but if you look at its first part you see List.

In summary then, putting Dynamic around an expression changes its head, even though it is still displayed as if the Dynamic wasn't there.

Another way to see this is to evaluate Dynamic[x] then select the output cell and shift-cmd-E to show what it is:

Mathematica graphics

share|improve this answer
What I see is that Head works on part of list with Dynamic in front of it. Then why, for example, doesn't Slider work on that part? – nilo de roock Aug 7 '12 at 12:58
what do you mean? What do you expect Slider[{.1,.1}] to do? – acl Aug 7 '12 at 13:43
Thanks, jVincent already explained it in his answer. I am clearer on Dynamic now. – nilo de roock Aug 7 '12 at 14:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.