For instance, if I am trying to draw a graph with 5 vertices labeled a through e, and I want to draw edges connecting a and b, a and c, a and d, a and e, b and c, b and d, and c and e, I would run the following code.
{a, b, c, d, e} = CirclePoints[5]
Graphics[{
{PointSize@Medium, Point[{a, b, c, d, e}]},
Line[{
{a, b}, {a, c}, {a, d}, {a, e},
{b, c}, {b, d},
{c, e}}]
}]
Which results in this graphic
(source: gdurl.com)
However, this becomes frustrating as a
, b
, c
, d
, and e
are not bound to the Graphics
call. Ideally, I'd like to be able to do something like:
With[{
{a, b, c, d, e} = CirclePoints[5]
}, Graphics[{
{PointSize@Medium, Point[{a, b, c, d, e}]},
Line[{
{a, b}, {a, c}, {a, d}, {a, e},
{b, c}, {b, d},
{c, e}}]
}]
]
However, this results in an error
"Local variable specification {{a,b,c,d,e}=CirclePoints[5]} contains {a,b,c,d,e}=CirclePoints[5], which is an assignment to {a,b,c,d,e}; only assignments to symbols are allowed."
which makes sense, given that With
does not have the desired capability, and neither do Block
and Module
.
So, is there a way to do this?
With
. $\endgroup$