Pasting all those lines into the Skill window won't work. The interactive command interpreter will only accept one Skill command at a time - and it must be all on one line.
In the example you would have to paste each of these lines one by one:
symbol = car(axlSelectByName("REFDES" "U40"))
minPitch = nil
foreach(pin1, pins foreach(pin2, remove(pin1, pins)
pitch = axlDistance(pin1 ->xy, pin2 ->xy) minPitch = if(minPitch, min(minPitch, pitch), pitch)))
Note how the foreach loop must be self-contained on one line.
I will discuss this issue with Cadence at the next week's CDNlive conference. Other Lisp implementations that I have used do not have this limitation.