Re: Variables within With statement
- To: mathgroup at smc.vnet.net
- Subject: [mg123724] Re: Variables within With statement
- From: Simon <simonjtyler at gmail.com>
- Date: Fri, 16 Dec 2011 05:53:11 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jccg39$mb4$1@smc.vnet.net>
- Reply-to: comp.soft-sys.math.mathematica at googlegroups.com
This has come up a few time recently on this mathgroup and stackoverflow: https://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/6fa6b0ad9d5d111c http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/3a5ae92bda1c7511 http://stackoverflow.com/a/5692010/421225 http://stackoverflow.com/a/4191096/421225 For what it's worth, here's the various versions I keep floating around SetAttributes[Let, HoldAll]; SyntaxInformation[Let] = {"ArgumentsPattern" -> {{__}, _}}; Let[{}, expr_] := expr Let[{a_, b___}, expr_] := With[{a}, Let[{b}, expr]] SetAttributes[WithRules, HoldRest] WithRules[rules_, expr_] := With@@Append[Apply[Set, Hold@rules, {2}], Unevaluated[expr]] SetAttributes[LetRules, HoldRest] LetRules[rules_, expr_] := Let@@Append[Apply[Set, Hold@rules, {2}], Unevaluated[expr]] Simon