Changeset 6350 for lang/smalltalk

Show
Ignore:
Timestamp:
02/08/08 00:25:19 (10 months ago)
Author:
murky-satyr
Message:

lang/smalltalk/misc/gost.st: SequenceableCollection?>>#zip

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/smalltalk/misc/gost.st

    r5930 r6350  
    8282|> s 
    8383  self P: s! 
     84@ o 
     85  (o respondsTo: #collect:) and: [ ^o collect: [:i| self at: i ] ]. 
     86  ^self at: o! 
    8487 
    8588!Symbol methodsFor: 'golf'! 
     
    123126 
    124127!SequenceableCollection methodsFor: 'golf'! 
    125 / p 
    126   ^(p isKindOf: SequenceableCollection) ifTrue: [ 
    127     | s r | 
    128     s := self readStream. r := OrderedCollection new. 
    129     [ r add: (s upToAll: p). s atEnd ] whileFalse. 
    130     r. 
    131   ] ifFalse: [ super / p ]! 
     128/ o 
     129  | s r | 
     130  s := ReadStream on: self.  
     131  r := OrderedCollection new. 
     132  (o isKindOf: SequenceableCollection) and: [ 
     133    [ r add: (s upToAll: o). s atEnd ] whileFalse ]. 
     134  (o isKindOf: Integer) and: [ 
     135    [ r add: (s nextAvailable: o). s atEnd ] whileFalse ]. 
     136  ^r! 
    132137* o 
    133138  ^(o isKindOf: Integer) 
     
    148153displayOn: s 
    149154  | j | 
    150   (j := Golf.Dic at: $\) isNil 
    151     ifTrue:  [ self do: [:x| x displayOn: s ] ] 
    152     ifFalse: [ self do: [:x| x displayOn: s ] separatedBy: [ j displayOn: s ] ]! 
    153    
     155  (j := Golf.Dic at: $\) 
     156    ifNil:    [ self do: [:x| x displayOn: s ] ] 
     157    ifNotNil: [ self do: [:x| x displayOn: s ] separatedBy: [ j displayOn: s ] ]! 
     158zip 
     159  "Transpose rows with columns (derived from GolfScript)." 
     160  | cols | 
     161  cols := 1 to: self size. 
     162  ^(1 to: self first size) collect: 
     163    [:i| cols collect: [:j| (self at: j) at: i ] ]! 
     164 
    154165!False methodsFor: 'golf'! 
    155166displayOn: s! 
     
    199210  "Makes a [D]ictionary from an array of associations." 
    200211  ^self asArray inject: Dictionary new into: [ :d :a | d add: a. d ]! 
    201 @ o 
    202   ^(o respondsTo: #collect:) 
    203     ifTrue:  [ o collect: [:i| self at: i ] ] 
    204     ifFalse: [ self at: o ]! 
    205212+ o 
    206213  (o isKindOf: BlockClosure) and: [ ^self fold: o ]. 
    207214  o isSymbol and: [ ^self fold: [:a :b| a perform: o with: b ] ]! 
    208 / n 
    209   | r s | 
    210   r := OrderedCollection new: (self size / n) ceiling. 
    211   s := ReadStream on: self. 
    212   [ r add: (s nextAvailable: n). s atEnd ] whileFalse. 
    213   ^r! 
    214215\ b 
    215216  ^self collect: b!