Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.1K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Understanding passing functions with parameters as a parameter

Posted 6 years ago

Hey,

I'm having trouble understanding why my function below needs the HoldAll attribute. My goal was to write a function that outputs the trace steps with frames around them.

Also... is there a more elegant way to achieve this?

Clear[traceFramed];
SetAttributes[traceFramed, HoldAll];
traceFramed[f_[n_Integer], filter_ : _] := 
  Column[Framed[#, FrameMargins -> Large] & /@ Trace[f[n], filter]];

Example: traceFramed[Range[5]]

Thank you very much!

POSTED BY: Timo K
2 Replies

Hi Timo,

without HoldAll or HoldFirst the argument gets evaluated and your function effectively sees traceFramed[{1, 2, 3, 4, 5}] - and for this (i.e. for the respective pattern) there is no definition made. It might be interesting for you to read e.g. The Standard Evaluation Procedure from the documentation.

Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 6 years ago

Thank you! I will read the proposed guide!

POSTED BY: Timo K
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard