Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Manipulate and Module

  • To: mathgroup at
  • Subject: [mg132099] Re: Manipulate and Module
  • From: John Fultz <jfultz at>
  • Date: Fri, 6 Dec 2013 02:14:25 -0500 (EST)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <>

You should never pass Module variables into Manipulate, as it will cause exactly the problems you're seeing.  This is basically the same issue of passing Module variables into Dynamic.  You'll notice that in v9, if you do this, you'll get red syntax highlighting.  E.g., in:

Module[{x=1}, Dynamic[x]]

that the instance of =91x=92 inside the Dynamic will turn red to indicate that this is problematic code.  I realized a while ago that we really should be doing the same thing for Manipulate, and so in the upcoming Mathematica release, I added that rule to Mathematica's syntax highlighter.

The correct thing to do here is to use DynamicModule.  DynamicModule properly works with saved notebooks, with copying and pasting of Dynamic/Manipulate output, etc.  That's what it's designed to do.  Module, on the other hand, is tied to a temporal instance of a kernel evaluation, and so behaves very badly when you use Dynamic/Manipulate to transport it out of its temporal context (and, especially, after the current kernel session has died).

John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

On Dec 5, 2013, at 2:05 AM, Sergio Miguel Terrazas Porras <sterraza at> wrote:

> Hello folks!
> I had been using Module for a while, to avoid conflcts among variables in several functions used in the same notebook.
> When Manipulare came around, I modified many of my notebooks, putting a Manipulate inside the Module, something like this:
> function[var1_,var2_,...]:=Module[{internal list of vars},   Manipulate[something,{var,vinit,vfinal}]  ]
> But once in a while I encountered problems when opening a notebook.
> Something like Show[can not combine graph1 with graph2] etc.
> Now, the other way woulb be to interchange Module and Manipulate, putting the Module inside the Manipulate.
> What are the main differences between these two aproaches, and which one is the preffered one?
> Thanks,
> Sergio Terrazas

  • Prev by Date: Re: Laptop numpad enter does not evaluate cell
  • Next by Date: Re: Laptop numpad enter does not evaluate cell
  • Previous by thread: Manipulate and Module
  • Next by thread: Re: Manipulate and Module