Skip to main content
added 30 characters in body
Source Link
blabla999
  • 2k
  • 12
  • 11

#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)

#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
]

(all character counts are w.o omittable whitespace)

#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)

added 613 characters in body
Source Link
blabla999
  • 2k
  • 12
  • 11

#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
]

(all character counts are w.o omittable whitespace)

#Smalltalk (79/66 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 ;-)

character counts are w.o omittable whitespace

#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
]

(all character counts are w.o omittable whitespace)

added 602 characters in body
Source Link
blabla999
  • 2k
  • 12
  • 11

#Smalltalk (79/66 chars w)#

###version 1 (79):### { [ 'line1' print ].o [ 'line2' print ]. whitespace [ '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:#value#print

little explanationgives:
[..] line4line3line2line1

the code is a blocklittle unsafe (aka lambda closure);
{..} is an array constructor;
reverse and mapit requires that the block's containing method does not contain other string literals; but we are obvious;
#value evaluates a block closure.playing golf - not trusted software development ;-)

###output:### line4line3line2line1character counts are w.o omittable whitespace

#Smalltalk (79 chars w.o. whitespace)#

{
    [ '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

#Smalltalk (79/66 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 ;-)

character counts are w.o omittable whitespace

Source Link
blabla999
  • 2k
  • 12
  • 11
Loading