Skip to main content
added 2 characters in body
Source Link

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this:

Function[List, {1, 2, 3}][Hold] (* Hold[1, 2, 3] *) Function[Function, Function[Slot[1]]][Hold] (* Hold[#1] *) Function[Slot, Function[Slot[1]]][Hold] (* Hold[1] & *) Function[Function, Function[x, 1]][Hold] (* Function[x, 1] *) (* Why not Hold[x, 1]? *) {Function[Null, Null][1]} (* {Null} *) (* Why not {1}? *) 

I think I understand the first 3 cases.
Could you please explain the last 2 results?

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this:

Function[List, {1, 2, 3}][Hold] (* Hold[1, 2, 3] *) Function[Function, Function[Slot[1]]][Hold] (* Hold[#1] *) Function[Slot, Function[Slot[1]]][Hold] (* Hold[1] & *) Function[Function, Function[x, 1]][Hold] (* Function[x, 1] *) (* Why not Hold[x, 1]? *) {Function[Null, Null][1]} (* {Null} *) (* Why not 1? *) 

I think I understand the first 3 cases.
Could you please explain the last 2 results?

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this:

Function[List, {1, 2, 3}][Hold] (* Hold[1, 2, 3] *) Function[Function, Function[Slot[1]]][Hold] (* Hold[#1] *) Function[Slot, Function[Slot[1]]][Hold] (* Hold[1] & *) Function[Function, Function[x, 1]][Hold] (* Function[x, 1] *) (* Why not Hold[x, 1]? *) {Function[Null, Null][1]} (* {Null} *) (* Why not {1}? *) 

I think I understand the first 3 cases.
Could you please explain the last 2 results?

edited title
Link
rm -rf
  • 89.8k
  • 21
  • 303
  • 498

What are the scoping rules for function parameters shadowing globalSystem` symbols?

Tweeted twitter.com/#!/StackMma/status/350888841869144064
Source Link

What are the scoping rules for function parameters shadowing global symbols?

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this:

Function[List, {1, 2, 3}][Hold] (* Hold[1, 2, 3] *) Function[Function, Function[Slot[1]]][Hold] (* Hold[#1] *) Function[Slot, Function[Slot[1]]][Hold] (* Hold[1] & *) Function[Function, Function[x, 1]][Hold] (* Function[x, 1] *) (* Why not Hold[x, 1]? *) {Function[Null, Null][1]} (* {Null} *) (* Why not 1? *) 

I think I understand the first 3 cases.
Could you please explain the last 2 results?