Timeline for Define a delayed function depending on a global variable as though the variable's contents was pasted
Current License: CC BY-SA 4.0
25 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 4, 2022 at 19:21 | history | edited | userrandrand | CC BY-SA 4.0 |
deleted 106 characters in body
|
Nov 3, 2022 at 22:38 | comment | added | userrandrand | @att ooh now I understand sorry my mistake. Thanks for the tip and help (:. | |
Nov 3, 2022 at 20:30 | comment | added | att |
@userrandrand Oops, I meant = . As noted in my first comment this kind of construction relies on using Set rather than SetDelayed .
|
|
Nov 3, 2022 at 20:12 | comment | added | userrandrand |
@att What I did : thing = (a + x) y; thingy[a_, y_] := NIntegrate[thing, {x, 0, 10}] // Inactivate then DownValues[thingy] = Activate@DownValues[thingy] and that did not work
|
|
Nov 3, 2022 at 20:09 | comment | added | att |
@userrandrand My original suggestion was to Inactivate the RHS (// has higher precedence than := ) instead of manually Inactive -ing certain heads, after which the downvalues can be activated as described.
|
|
Nov 3, 2022 at 19:54 | comment | added | userrandrand |
@att I know maybe I miss understood the //Inactivate and you meant to use Inactivate[thingy[a_]:=thing] while I understood that you meant thingy[a_]:=thing//Inactivate which after rereading your comment you did say append //Inactivate to the **definition** so maybe I misunderstood.
|
|
Nov 3, 2022 at 19:47 | comment | added | att |
@userrandrand you need to assign DownValues[thingy]=Activate@DownValues[thingy] .
|
|
Nov 3, 2022 at 13:37 | comment | added | userrandrand |
@att I tried Activate@DownValues[thingy] and It did not activate the Inactivate
|
|
Nov 3, 2022 at 0:49 | history | edited | userrandrand | CC BY-SA 4.0 |
added 100 characters in body
|
Nov 3, 2022 at 0:43 | history | edited | userrandrand | CC BY-SA 4.0 |
added 100 characters in body
|
Nov 3, 2022 at 0:13 | history | edited | userrandrand | CC BY-SA 4.0 |
added 455 characters in body
|
Nov 2, 2022 at 23:41 | comment | added | userrandrand | @IonSme hi att posted their answer with what they meant. | |
Nov 2, 2022 at 23:40 | comment | added | ions me |
@att is the "definition" here the RHS, or the whole expression? When you say Activate[Inactivate[definition]]
|
|
Nov 2, 2022 at 5:27 | comment | added | userrandrand |
@att even if one evaluates the right hand side of := using With the pattern values on the left hand side will change maybe to avoid problems with localization of the arguments of the function. That can be checked by using With[{thing=thing},thingy[a_,y_]:= ... thing .. ] and then checking the down values of thingy. As such I rather not get into the details of why := will not work like = especially that I am not sure or do not remember all the details.
|
|
Nov 2, 2022 at 5:19 | history | edited | userrandrand | CC BY-SA 4.0 |
added 437 characters in body
|
Nov 2, 2022 at 5:08 | history | edited | userrandrand | CC BY-SA 4.0 |
added 890 characters in body
|
Nov 2, 2022 at 5:04 | comment | added | userrandrand |
@att maybe you might want to post Activate[Inactivate[definition]] idea i am not sure what you have in mind. I updated my answer to also use $PreRead to make an input alias
|
|
Nov 2, 2022 at 5:02 | comment | added | userrandrand |
@att I have not tested the DownValues[thingy] = Activate@DownValues[thingy] trick but it seems pretty cool I will hopefully remember to try it out.Thanks (:
|
|
Nov 2, 2022 at 5:00 | history | edited | userrandrand | CC BY-SA 4.0 |
added 890 characters in body
|
Nov 2, 2022 at 4:52 | comment | added | att |
Actually, come to think of it, Activate[Inactivate[definition]] pretty much satisfies OP's requirements.
|
|
Nov 2, 2022 at 4:50 | comment | added | att |
Inactivate ing the whole expression more closely mirrors the semantics of the original := assignment, but I definitely see the argument in favor of only Inactive ating some heads.
|
|
Nov 2, 2022 at 4:41 | comment | added | userrandrand |
@att I agree that Inactive[NIntegrate] is tedious to write but it allows the integrand to be evaluated without the integral being evaluated. I find that a bit pleasant to see when calling the function without Activate . Also using nintegrate=Inactive[NIntegrate] makes it less tedious to write
|
|
Nov 2, 2022 at 4:11 | comment | added | att |
You can also DownValues[thingy] = Activate@DownValues[thingy] afterwards to remove the need to Activate the function result.
|
|
Nov 2, 2022 at 4:08 | comment | added | att |
Worth noting that = is required because := does not evaluate its right hand side (and thus won't perform variable substitutions). It's probably more convenient to append //Inactivate to the definition instead of wrapping heads present there with Inactive , and this step can be entirely skipped if delayed evaluation of the RHS isn't needed.
|
|
Nov 2, 2022 at 2:54 | history | answered | userrandrand | CC BY-SA 4.0 |