#Smalltalk (79/66/143 chars)#
###version 1 (79):### { [ 'line1' print ]. [ 'line2' print ]. [ 'line3' print ]. [ 'line4' print ] } reverse map:#value
little explanation:
[..] is a block (aka lambda closure);
{..} is an array constructor;
reverse and map are obvious;
#value evaluates a block closure.
###output:### line4line3line2line1
###version 2 (66): Here is a version using reflection; it fetches the string constants of the block and prints them:
Given any block containing string-prints:
b := [
'line1' print.
'line2' print.
'line3' print.
'line4' print
].
where 'normal' evaluation with:
b value.
gives: line1line2line3line4l
The following extracts the string literals and prints them reverse:
(b method literals select:[:l|l class==String]) reverse map:#print
gives: line4line3line2line1
the code is a little unsafe (it requires that the block's containing method does not contain other string literals; but we are playing golf - not trusted software development ;-)
###version 3 (143)###
defines a 'function' which redirects stdout to some internal stream, evaluates a block closure and finally prints the collected output in reverse:
w := [:b | |sav red|
[
sav := Stdout.
Stdout := red := '' writeStream.
b value.
] ensure:[
Stdout := sav.
red contents asCollectionOfLines reverse map:#printNL
]
].
then we evaluate any code within that wrapper:
w value:[
'line1' printNL.
'line2' printNL.
'line3' printNL.
'line4' printNL
]
its not thread save, though.
(all character counts are w.o omittable whitespace)