Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7121

Re: C/Fortran-like #include functionality for large expressions?

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: C/Fortran-like #include functionality for large expressions?
Date 2011-12-11 08:57 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jc1ral$t3r$1@smc.vnet.net> (permalink)
References <jbvjbn$isb$1@smc.vnet.net>

Show all headers | View raw


On 10/12/2011 12:29, Frank Iannarilli 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
>
>
Your example didn't work because a is local to the Module, so in effect 
you executed a line of the form:

a$17=2.;ToExpression["a=3."];Print[a$17]

(The number 17 is arbitrary - see the help for the Module function)

If the expression that you want to include does not contain variables 
that should be local, the solution is trivial - just assign them to a 
variable:

subst=Hold[a=3.]

(no need to convert to string) and insert the expression as needed in 
your function as ReleaseHold[subst].

Getting the replacement a -> a$17 would be a lot harder, and is 
essentially pointless because a should presumably be global.

David Bailey
http://www.dbaileyconsultancy.co.uk

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

C/Fortran-like #include functionality for large expressions? Frank Iannarilli <frankeye@cox.net> - 2011-12-10 12:29 +0000
  Re: C/Fortran-like #include functionality for large expressions? David Bailey <dave@removedbailey.co.uk> - 2011-12-11 08:57 +0000
  Re: C/Fortran-like #include functionality for large expressions? "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-11 08:46 +0000

csiph-web