Skip to main content
added 164 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

Here is an expressly iterative solution:

bf[f_, x_] := ((f~Scan~#; #~Level~{2})& ~FixedPoint~ {x};) (* In[2]:= bf[Print, {{1, {2, 3}}, {4, 5}}] {{1,{2,3}},{4,5}} {1,{2,3}} {4,5} 1 {2,3} 4 5 2 3 *) 

Incorporating Rojo's advice to Hold expressions gathered by Level:

bf[f_, x_] := ( Level[f~Scan~#; #, {2}, Hold] & ~FixedPoint~ {x} ;) 

Here is an expressly iterative solution:

bf[f_, x_] := ((f~Scan~#; #~Level~{2})& ~FixedPoint~ {x};) (* In[2]:= bf[Print, {{1, {2, 3}}, {4, 5}}] {{1,{2,3}},{4,5}} {1,{2,3}} {4,5} 1 {2,3} 4 5 2 3 *) 

Here is an expressly iterative solution:

bf[f_, x_] := ((f~Scan~#; #~Level~{2})& ~FixedPoint~ {x};) (* In[2]:= bf[Print, {{1, {2, 3}}, {4, 5}}] {{1,{2,3}},{4,5}} {1,{2,3}} {4,5} 1 {2,3} 4 5 2 3 *) 

Incorporating Rojo's advice to Hold expressions gathered by Level:

bf[f_, x_] := ( Level[f~Scan~#; #, {2}, Hold] & ~FixedPoint~ {x} ;) 
Source Link
WReach
  • 69.8k
  • 4
  • 167
  • 275

Here is an expressly iterative solution:

bf[f_, x_] := ((f~Scan~#; #~Level~{2})& ~FixedPoint~ {x};) (* In[2]:= bf[Print, {{1, {2, 3}}, {4, 5}}] {{1,{2,3}},{4,5}} {1,{2,3}} {4,5} 1 {2,3} 4 5 2 3 *)