Consider this Dynamic
list
Slider[Dynamic@i, {Range[2, 10]}]
MapThread[DirectedEdge, Gather[##] & /@ (Range[#] & /@ Dynamic@i)]
The error is
List expected at position 2 in
MapThread[...]
. Although the output given by the function is correct:
MapThread[DirectedEdge, {{1}, {2}}]
(* {1 -> 2} *)
Edit:
The purpose of the list creating above is to create a list being exploited by Graph
:
DynamicModule[{p = {{0, 0}, {2, 2}}, i = 2},
Grid[{
{Dynamic[DirectedEdge @@ Range@i],
Dynamic@N@Round[MousePosition["Graphics"], 0.5]},
{(Dynamic@Thread[{{DirectedEdge @@ Range@i}, {p}}]),
EventHandler[Dynamic@Graph[{DirectedEdge @@ Range@i},
VertexCoordinates -> p, PlotRange -> 5, GridLines -> Automatic,
Frame -> True,
FrameTicks -> All], "MouseDown" :>
{(AppendTo[p, N@Round[MousePosition["Graphics"], 0.5]];),++i}]}
}, Frame -> All]]
With at the top the construction of the DirectedEdge
and the location of the mouse, at the bottom my attempt to see what should the list look like in order to be replaced in
Graph[{#1},VertexCoordinates -> #2]
Once again I assume that it's a Dynamic
issue.
this simple code here
. No. This code is not simple. If it was simple, you would have seen the problem allready ;). In cases like these, I take break the code apart, try each piece on its own to make sure it works ok, then build things back piece by piece. And try to spread things out a little. This always works. $\endgroup$Dynamic
doesn't evaluate. It has the HoldFirst attribute and is only evaluated in the front end; while it looks in the front end like you're passing a list you're really passingDynamic[list]
toMapThread
and that's a no go. $\endgroup$List
instead of theDynamic[List]
? $\endgroup$Dynamic
outsideMapThread
. Or use the sam trick which you unconsciously used withRange
:) $\endgroup$