RE: Reentrant Functions
- To: mathgroup at smc.vnet.net
- Subject: [mg29453] RE: [mg29424] Reentrant Functions
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
- Date: Wed, 20 Jun 2001 04:36:32 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hermann, since in Mathematica we only have a single thread of execution, the question for reentrance in its proper sense of concurrent invocation does not apply. For recursion, we first should be aware that a "function" in Mathematica is not the same thing as a Function in C, Pascal or Fortran. Especially there is no notion of a local store (stack or heap memory) and corresponding references to it(variables in local code), which is at the root of the question. Instead all binding of expressions is made to symbols (transformation rules residing in a global hash table). The symbols are obeying scope rules though: they are dynamically generated and removed (Module), temporarily shadowed or subjected to different bindings (Block) or textually substituted (With). To know these scoping rules (also for Function, Table, Sum, etc.) is essential for writing and understanding Mathematica code. For that please consult The Book, there is no way around (and not a single short answer)! And a special point of difficulty is the fact that in Mathematica there is no concept of a formal variable (and its associated store). Block, Module and Function constructs contained in a function definition create new symbols whenever they are evaluated. This means you may program recursively and you will have "new variables" for each "instantiation". So far functions are "reentrant" per se. You can however refer to global symbols, i.e. those defined outside of the function definition. Redefining them, giving them new values, within a function evaluation may be useful or cause troubles, but this is a matter of your algorithm, not of programming language. -- Hartmut Wolf > -----Original Message----- > From: Hermann Schmitt [mailto:schmitther at netcologne.de] To: mathgroup at smc.vnet.net > Sent: Tuesday, June 19, 2001 11:36 AM > To: mathgroup at smc.vnet.net > Subject: [mg29453] [mg29424] Reentrant Functions > > > > Hello, > can functions be made reentrant, i.e. can I invoke in a function the > same function again? > Hermann Schmitt >