Cons.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Dec 2003 15:26:02 +0100
changeset 1377 150000bb9d20
parent 1248 2d0493cd8d3c
child 1623 d93980e41a6a
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2002 by eXept Software AG
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
SequenceableCollection subclass:#Cons
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:'car cdr'
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:''
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'Collections-Linked'
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!Cons class methodsFor:'documentation'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
copyright
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 COPYRIGHT (c) 2002 by eXept Software AG
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
              All Rights Reserved
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 This software is furnished under a license and may be used
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 hereby transferred.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    A pair as in lisp.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    Create with:
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    42
        a !! b
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    43
    or:
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    44
        Cons car:a cdr:b
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    45
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    46
    Conses are not heavily used by Smalltalk (actually: not at all).
1377
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
    47
    Consider this a demo class.
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    [author:]
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        Claus Gittinger
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    [see also:]
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
"
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
!Cons class methodsFor:'instance creation'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
car:carArg cdr:cdrArg
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    ^ self basicNew car:carArg cdr:cdrArg
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
fromArray:anArray
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    |p last first|
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    anArray do:[:el |
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        p := self car:el cdr:nil.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
        first isNil ifTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
            first := p.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
        ] ifFalse:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
            last cdr:p.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
        ].
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
        last := p.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    ].
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    ^ first.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    "
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    78
     Cons fromArray:#(1 2 3 4)   
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    79
     Cons fromArray:#()    
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    80
     Cons fromArray:#(1)    
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
    81
     Cons fromArray:(1 to:10000)    
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    "
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
!Cons methodsFor:'accessing'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
at:n
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    88
    "for collection compatibility:
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    89
     a slow indexed accessor"
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    90
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    ^ (self nth:n) car
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    "
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    94
     (Cons fromArray:#(1))       at:1     
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    95
     (Cons fromArray:#(1 2 3 4)) at:1 
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    96
     (Cons fromArray:#(1 2 3 4)) at:3  
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    97
     (Cons fromArray:#(1 2 3 4)) at:4  
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
    98
     (Cons fromArray:#(1 2 3 4)) at:5  
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
at:n put:newValue
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   103
    "for collection compatibility:
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   104
     a slow indexed accessor"
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   105
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    (self nth:n) car:newValue.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    ^ newValue.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
     |l|
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   112
     l := Cons fromArray:#(1 2 3 4).
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
     l at:1 put:'one'.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
     l at:3 put:'three'.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
     l       
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    "
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   119
head
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   120
    "return the head, first or car - whatever you wonna call it"
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   121
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   122
    ^ self car
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   123
!
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   124
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
last
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   126
    "for lispers:
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   127
     return the last element of a list"
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   128
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    |p rest|
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    p := self.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    [(rest := p cdr) notNil] whileTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
        p := rest
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    ].
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   135
    ^ p car
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    "
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   138
     (Cons fromArray:#(1))       last     
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   139
     (Cons fromArray:#(1 2 3 4)) last    
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    "
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
nth:n
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   144
    "for lispers:
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   145
     return the nth element of a list"
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   146
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    |cnt p|
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    cnt := n.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    p := self.
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   151
    [
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
        cnt := cnt - 1.
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   153
        cnt == 0 ifTrue:[^ p car].
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
        p := p cdr.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
        p isNil ifTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
            self error:'no such element' mayProceed:true.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
            ^ nil
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
        ].
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   159
    ] loop.
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    "
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   162
     (Cons fromArray:#(1))       nth:1     
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   163
     (Cons fromArray:#(1 2 3 4)) nth:1 
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   164
     (Cons fromArray:#(1 2 3 4)) nth:3  
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   165
     (Cons fromArray:#(1 2 3 4)) nth:4  
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   166
     (Cons fromArray:#(1 2 3 4)) nth:5  
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   167
     (Cons fromArray:#( ))       nth:1  -> error    
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    "
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   169
!
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   170
1243
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   171
reversed
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   172
    "for lispers:
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   173
     return a new list with the cars in reverse order"
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   174
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   175
"/ for now, tail recursion is not yet optimized by the st/x jitter...
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   176
"/
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   177
"/    |rev|
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   178
"/
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   179
"/    rev := [:lst :acc |
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   180
"/                lst isNil ifTrue:[
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   181
"/                    acc
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   182
"/                ] ifFalse:[
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   183
"/                    rev value:(lst tail)
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   184
"/                        value:(Cons car:(lst head) cdr:acc)
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   185
"/                ]
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   186
"/           ].
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   187
"/    ^ rev value:self value:nil
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   188
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   189
    | lst acc|
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   190
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   191
    lst := self.
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   192
    acc := nil.
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   193
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   194
    [
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   195
        |nLst nAcc|
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   196
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   197
        lst isNil ifTrue:[ ^ acc].
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   198
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   199
        nLst := lst tail.
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   200
        nAcc := Cons car:(lst head) cdr:acc.
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   201
        lst := nLst.
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   202
        acc := nAcc.
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   203
   ] loop
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   204
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   205
    "
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   206
     (Cons fromArray:#(1))       reversed     
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   207
     (Cons fromArray:#(1 2))     reversed     
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   208
     (Cons fromArray:#(1 2 3 4)) reversed    
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   209
     (Cons fromArray:(1 to:10000)) reversed    
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   210
    "
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   211
!
15058ebc321b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1237
diff changeset
   212
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   213
tail
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   214
    "return the tail, second or cdr - whatever you wonna call it"
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   215
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   216
    ^ self cdr
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
!Cons methodsFor:'accessing - basic'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
car
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   222
    "return the head, first or car - whatever you wonna call it"
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    ^ car
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
car:something
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   228
    "set the head, first or car - whatever you wonna call it"
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    car := something.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
car:carArg cdr:cdrArg 
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   234
    "set both car and cdr"
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    car := carArg.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    cdr := cdrArg.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
cdr
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   241
    "return the tail, second or cdr - whatever you wonna call it"
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    ^ cdr
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
cdr:something
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   247
    "set the tail, second or cdr - whatever you wonna call it"
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    cdr := something.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
!Cons methodsFor:'list processing'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
append:aCons
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   255
    "for lispers:
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   256
     append the arg. Return a new list, where the 2nd part is shared.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   257
     Destructive: the receivers last cdr is modified."
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   258
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    |p rest|
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    p := self.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    [(rest := p cdr) notNil] whileTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
        p := rest
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    ].
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    p cdr:aCons.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    ^ self
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
    "
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   269
     (Cons fromArray:#(1 2 3 4)) 
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   270
        append:(Cons fromArray:#(5 6 7 8)) 
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   271
    "
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   272
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   273
    "sharing demonstrated:
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   274
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   275
     |a b ab|
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   276
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   277
     a := Cons fromArray:#(1 2 3 4).
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   278
     b := Cons fromArray:#(5 6 7 8).
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   279
     ab := a append:b.
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   280
     b car:'five'.
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   281
     ab      
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   282
    "
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   283
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   284
    "destruction demonstrated:
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   285
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   286
     |a b ab|
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   287
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   288
     a := Cons fromArray:#(1 2 3 4).
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   289
     b := Cons fromArray:#(5 6 7 8).
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   290
     ab := a append:b.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   291
     a  
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
    "
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   293
!
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   294
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   295
take:nTaken
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   296
    "for lispers:
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   297
     take n elements from the list; return a new list"
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   298
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   299
    |nRemain l rslt lastCons cons|
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   300
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   301
    nTaken > 0 ifTrue:[
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   302
        "/ avoiding recursion here...
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   303
        "/ instead of:
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   304
        "/        ^ Cons car:(self car) cdr:(self cdr take:nTaken-1)
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   305
        "/ we do:
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   306
        nRemain := nTaken.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   307
        l := self.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   308
        rslt := lastCons := Cons car:(l car) cdr:nil.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   309
        [nRemain > 1] whileTrue:[
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   310
            l := l cdr.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   311
            cons := Cons car:(l car) cdr:nil.    
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   312
            lastCons cdr:cons.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   313
            lastCons := cons.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   314
            nRemain := nRemain - 1.
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   315
        ].
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   316
        ^ rslt.
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   317
    ].
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   318
    ^ nil
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   319
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   320
    "
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   321
     (Cons fromArray:#(1 2 3 4)) take:3  
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   322
     (Cons fromArray:#(1)) take:0  
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   323
     (Cons fromArray:#()) take:3  
1248
2d0493cd8d3c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1243
diff changeset
   324
     (Cons fromArray:(1 to: 1000)) take:999  
1237
3814a1f983a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1074
diff changeset
   325
    "
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
!Cons methodsFor:'printing'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
displayString
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
    ^ self printString
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
printOn:aStream
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    (car isLazyValue not and:[ car isCons ]) ifTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
        aStream nextPutAll:'('.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
        car printOn:aStream.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
        aStream nextPutAll:')'.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
    ] ifFalse:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
        car printOn:aStream.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    ].
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
1073
1b0886e40a5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
   343
    aStream nextPutAll:'!!'.
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    (cdr isLazyValue not and:[ cdr isCons ]) ifTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
        aStream nextPutAll:'('.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
        cdr printOn:aStream.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
        aStream nextPutAll:')'.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
    ] ifFalse:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
        cdr printOn:aStream.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    ].
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
!Cons methodsFor:'queries'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
isCons
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
    ^ true
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
size
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   361
    "for smalltalkers: the lists length"
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   362
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
    |l p rest|
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    l := 1.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    p := self.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
    [(rest := p cdr) notNil] whileTrue:[
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
        l := l + 1.
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
        p := rest
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
    ].
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
    ^ l
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
    "
1074
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   374
     (Cons fromArray:#( )) size    
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   375
     (Cons fromArray:#(1)) size     
cb147ae2e03c comment
Claus Gittinger <cg@exept.de>
parents: 1073
diff changeset
   376
     (Cons fromArray:#(1 2 3 4)) size    
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    "
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
! !
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
1377
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   380
!Cons methodsFor:'streaming'!
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   381
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   382
readStream
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   383
    ^ ConsStream on:self.
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   384
! !
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   385
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
!Cons class methodsFor:'documentation'!
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
version
1377
150000bb9d20 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   389
    ^ '$Header: /cvs/stx/stx/libbasic2/Cons.st,v 1.7 2003-12-09 14:26:02 cg Exp $'
1043
544a0829a59b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
! !