Skip to main content
Added tags and changed the title to include the use case and make the purpose of the the question easier to understand.
Link

Is there Define a way to usedelayed function depending on a global variable as if you are pasting itsthough the variable's contents? was pasted

Tweeted twitter.com/StackMma/status/1587776585804947458
addded underscores to fix typo.
Source Link
ions me
  • 1.1k
  • 6
  • 13

Problem

Say I previously defined a variable (maybe through some extensive calculation)

thing = (a+x)y

Then, I want to use that expression elsewhere. In general, I can't just type "thing". For example, the following doesn't work

thingy[athingy[a_,y]y_] := NIntegrate[ thing ,{x,0,10}]

What I want

I want a way to use variables such that it always behaves like I copied and pasted its contents directly e.g. I want to type:

thingy[athingy[a_,y]y_] := NIntegrate[ Paste[thing] ,{x,0,10}]

and have it behave like:

thingy[athingy[a_,y]y_] := NIntegrate[ (a+x)y ,{x,0,10}]

Not just in this particular example, but in all use cases.

What I am not looking for

Making this use case work.

Yes, I know that I can fix it with:

thingy[a1_,y1_] := NIntegrate[ thing /. {a->a1,y->y1} ,{x,0,10}]

I'd like a built-in function, even if it behaves slightly differently from the way I described, rather than a hard-coded user-defined function (unless it's a very short).

Problem

Say I previously defined a variable (maybe through some extensive calculation)

thing = (a+x)y

Then, I want to use that expression elsewhere. In general, I can't just type "thing". For example, the following doesn't work

thingy[a,y] := NIntegrate[ thing ,{x,0,10}]

What I want

I want a way to use variables such that it always behaves like I copied and pasted its contents directly e.g. I want to type:

thingy[a,y] := NIntegrate[ Paste[thing] ,{x,0,10}]

and have it behave like:

thingy[a,y] := NIntegrate[ (a+x)y ,{x,0,10}]

Not just in this particular example, but in all use cases.

What I am not looking for

Making this use case work.

Yes, I know that I can fix it with:

thingy[a1_,y1_] := NIntegrate[ thing /. {a->a1,y->y1} ,{x,0,10}]

I'd like a built-in function, even if it behaves slightly differently from the way I described, rather than a hard-coded user-defined function (unless it's a very short).

Problem

Say I previously defined a variable (maybe through some extensive calculation)

thing = (a+x)y

Then, I want to use that expression elsewhere. In general, I can't just type "thing". For example, the following doesn't work

thingy[a_,y_] := NIntegrate[ thing ,{x,0,10}]

What I want

I want a way to use variables such that it always behaves like I copied and pasted its contents directly e.g. I want to type:

thingy[a_,y_] := NIntegrate[ Paste[thing] ,{x,0,10}]

and have it behave like:

thingy[a_,y_] := NIntegrate[ (a+x)y ,{x,0,10}]

Not just in this particular example, but in all use cases.

What I am not looking for

Making this use case work.

Yes, I know that I can fix it with:

thingy[a1_,y1_] := NIntegrate[ thing /. {a->a1,y->y1} ,{x,0,10}]

I'd like a built-in function, even if it behaves slightly differently from the way I described, rather than a hard-coded user-defined function (unless it's a very short).

Became Hot Network Question
Source Link
ions me
  • 1.1k
  • 6
  • 13

Is there a way to use a variable as if you are pasting its contents?

Problem

Say I previously defined a variable (maybe through some extensive calculation)

thing = (a+x)y

Then, I want to use that expression elsewhere. In general, I can't just type "thing". For example, the following doesn't work

thingy[a,y] := NIntegrate[ thing ,{x,0,10}]

What I want

I want a way to use variables such that it always behaves like I copied and pasted its contents directly e.g. I want to type:

thingy[a,y] := NIntegrate[ Paste[thing] ,{x,0,10}]

and have it behave like:

thingy[a,y] := NIntegrate[ (a+x)y ,{x,0,10}]

Not just in this particular example, but in all use cases.

What I am not looking for

Making this use case work.

Yes, I know that I can fix it with:

thingy[a1_,y1_] := NIntegrate[ thing /. {a->a1,y->y1} ,{x,0,10}]

I'd like a built-in function, even if it behaves slightly differently from the way I described, rather than a hard-coded user-defined function (unless it's a very short).