Re: C/Fortran-like #include functionality for large expressions?
- To: mathgroup at smc.vnet.net
- Subject: [mg123575] Re: C/Fortran-like #include functionality for large expressions?
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sun, 11 Dec 2011 03:50:07 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201112101226.HAA19213@smc.vnet.net>
This is a scoping issue. The variable a inside the module is not the
same as the a in the string.
Clear[testInclude]
testInclude[] := Module[{a},
Print[a];(* the actual variable name within Module *)
a = 2.;
ToExpression[StringReplace[p,
"a" -> ToString[HoldForm[a]]]];
Print[a]]
p = "a=3.";
testInclude[]
a$104
3.
Bob Hanlon
On Sat, Dec 10, 2011 at 7:26 AM, Frank Iannarilli <frankeye at cox.net> wrote:
> Hi All,
>
>
> Is there any C #include or similarly Fortran INCLUDE functionality I can gain within Mathematica? The purpose is to enhance readability of very large function definitions or Manipulate[] invocations, by splicing-in "chunks" of code (expressions) defined in separate cells.
>
> Here's an example of an attempt that doesn't work:
>
> testInclude[] :=
> Module[{a}, a = 2.; ToExpression[p]; Print[a]]
>
> p = "a=3." // The expression chunk to "include"
>
> testInclude[]
> // would like this to return "3", but stuck returning "2".
>
> Thanks,
> Frank
>
- References:
- C/Fortran-like #include functionality for large expressions?
- From: Frank Iannarilli <frankeye@cox.net>
- C/Fortran-like #include functionality for large expressions?