Skip to main content

Timeline for Replacement inside held expression

Current License: CC BY-SA 4.0

22 events
when toggle format what by license comment
Jun 7, 2021 at 13:52 comment added Leonid Shifrin @Gravifer Well, you can check for yourself, the source of all WFRs is available. I frankly don't have the time to check right now.
Jun 7, 2021 at 5:21 comment added Gravifer I wonder if this ResourceFunction["Inline"] is an implementation of the famous trick? If not, does it achieve the same objectives?
Aug 21, 2020 at 8:17 comment added Leonid Shifrin @luyuwuli Thanks. Sometimes I also learn a lot from rereading my posts :) (I obviously learn a lot from (re)reading posts of others, too, but that's probably less surprising).
Aug 20, 2020 at 23:24 comment added luyuwuli Glad I can help:) BTW, I always learn a lot after rereading your posts.
Aug 20, 2020 at 21:48 comment added Leonid Shifrin @luyuwuli You are right, this has been the wrong choice of words, and that sentence was actually misleading. The part inside declaration is evaluated in any case, since in general it is needed for the condition check. Whether the condition ends up being True or False, decides whether the rule is considered at the end as applicable or not, by the pattern matcher. I have edited the post to address this. Thanks for pointing this out.
Aug 20, 2020 at 21:47 history edited Leonid Shifrin CC BY-SA 4.0
Corrected a misleading sentence / statement
Aug 20, 2020 at 16:13 comment added luyuwuli I'm not sure whether I understand it correctly, but my experiment doesn't agree with this conclusion,"Since the condition is True, it forced the eval variable to be evaluated inside the declaration part of With" e.g. Hold[{Hold[2.], Hold[3.]}] /. n_Real :> With[{eval = (Print["!"]; f[n])}, g[eval] /; False] will always print ! even though the condition is False.
Oct 11, 2016 at 15:44 history edited Leonid Shifrin CC BY-SA 3.0
Fixed a broken link
Mar 23, 2016 at 10:42 history edited Jacob Akkerboom CC BY-SA 3.0
Made notation more standard, consistent with Leonids style
Jul 28, 2013 at 6:31 history migrated from stackoverflow.com (revisions)
Oct 7, 2011 at 8:23 comment added Leonid Shifrin @WReach Thanks, very nice indeed. I discussed RuleCondition here before: stackoverflow.com/questions/5866016/question-on-condition/…, but it did not occur to me to try using it here. Nice finding!
Oct 7, 2011 at 3:47 vote accept Alexey Popkov
Oct 6, 2011 at 20:40 comment added WReach +1 The Trott-Strzebonski technique appears to be the officially sanctioned solution. You may have some academic interest in my response which discusses a technique involving the unofficial, unsupported symbol RuleCondition.
Sep 2, 2011 at 8:29 comment added Leonid Shifrin @Simon Indeed. This was before my time on SO :)
Sep 2, 2011 at 2:35 comment added Simon This trick also came up in the question Evaluating only particular Head type in expression?
Aug 5, 2011 at 15:13 comment added Leonid Shifrin @Szabolcs Sure I will. I will collect a few more related useful things and then post it there, within a couple of days.
Aug 5, 2011 at 15:07 comment added Szabolcs @Leonid, can you please add this to stackoverflow.com/questions/4198961/… ?
Jul 10, 2011 at 7:45 comment added Leonid Shifrin @Alexey For the same reason as when you define a global function as f[x_]:=Module[{var = x^2},With[{var = var},Hold[var]/;var>10]]. What happens is that everything in the enclosing scoping constructs that does not go into Condition gets evaluated - this is needed to compute the result of test in Condition. The semantics of rules with shared local variables is different from the standard rule-substitution semantics, this is what makes all these things possible. The further non-triviality of Trott-Strzebonski technique is that local rules are used, so all expression levels are accessible.
Jul 10, 2011 at 4:03 comment added Alexey Popkov Why Condition inside With forces evaluation not only With (with except to the Condition) but also enclosing Module? Without the Condition the r.h.s of the rule stay completely unevaluated.
Jul 9, 2011 at 10:54 comment added Leonid Shifrin @Alexey I updated my post with some explanation. It may not be completely satisfactory, but this is how I think of it currently.
Jul 9, 2011 at 8:18 comment added Alexey Popkov The Trott-Strzebonski method looks a bit magical. Could you please explain how it works?
Jul 9, 2011 at 7:14 history answered Leonid Shifrin CC BY-SA 3.0