Often I have an unevaluated expression in a RuleDelayed Key-Value pair and subsequently want to access the value unevaluated. For example, say I want to Query assoc to yield HoldForm[Range[0,10]]

assoc = <|"a" ->  <|"b" :> Range[0, 10]|>|>;

This can be done readily enough (e.g. start with Query["a",{"b"}]@assoc, KeyValuePatternetc.) but it seems like there should be a more natural syntax?

  • $\begingroup$ Query["a", HoldForm[#"b"] &]@assoc $\endgroup$ – Edmund Jun 1 '16 at 0:02
  • $\begingroup$ @Edmund Yep, that's natural enough - thanks - quick accept if posted. $\endgroup$ – Ronald Monson Jun 1 '16 at 0:18

You may use HoldForm.

Query["a", HoldForm[#"b"] &]@assoc
(* HoldForm[Range[0,10]] *)

Hope this helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.