VarArgBlock.st
changeset 22311 5331770c9388
parent 15093 e79aeb6f6766
equal deleted inserted replaced
22310:7c2de8ff3d04 22311:5331770c9388
    44     passed in that single argument (as a collection).
    44     passed in that single argument (as a collection).
    45 
    45 
    46     Create a variableArgument block by sending #asVarArgBlock to a regular
    46     Create a variableArgument block by sending #asVarArgBlock to a regular
    47     block.
    47     block.
    48 
    48 
    49     This is a goody add-on, which may not be available/possible in other 
    49     This is a goody add-on, which may not be available/possible in other
    50     smalltalk implementations. Do not use it if cross-platform
    50     smalltalk implementations. Do not use it if cross-platform
    51     portability is required.
    51     portability is required.
    52 
    52 
    53 
    53 
    54     [author:]
    54     [author:]
    55         Claus Gittinger
    55 	Claus Gittinger
    56 
    56 
    57     [see also:]
    57     [see also:]
    58         Block
    58 	Block
    59 "
    59 "
    60 !
    60 !
    61 
    61 
    62 examples
    62 examples
    63 "
    63 "
    64    the same block, evaluated with 2 or 5 arguments:
    64    the same block, evaluated with 2 or 5 arguments:
    65                                                                 [exBegin]
    65 								[exBegin]
    66      |b|
    66      |b|
    67 
    67 
    68      b := [:args | Transcript show:'wow: '; showCR:args] asVarArgBlock.
    68      b := [:args | Transcript show:'wow: '; showCR:args] asVarArgBlock.
    69 
    69 
    70      b value:'hi' value:'there'. 
    70      b value:'hi' value:'there'.
    71      b value:'hello' value:'there' value:'how' value:'about' value:'this'.
    71      b value:'hello' value:'there' value:'how' value:'about' value:'this'.
    72                                                                 [exEnd]
    72 								[exEnd]
    73 
    73 
    74 
    74 
    75    does it accept a variable number of arguments ?:
    75    does it accept a variable number of arguments ?:
    76                                                                 [exBegin]
    76 								[exBegin]
    77      |b|
    77      |b|
    78 
    78 
    79      b := [:args | Transcript showCR:args].
    79      b := [:args | Transcript showCR:args].
    80      Transcript showCR:(b isVarArgBlock).
    80      Transcript showCR:(b isVarArgBlock).
    81 
    81 
    82      b := [:args | Transcript showCR:args] asVarArgBlock.
    82      b := [:args | Transcript showCR:args] asVarArgBlock.
    83      Transcript showCR:(b isVarArgBlock)
    83      Transcript showCR:(b isVarArgBlock)
    84                                                                 [exEnd]
    84 								[exEnd]
    85 "
    85 "
    86 
    86 
    87     "Created: 23.1.1997 / 04:57:26 / cg"
    87     "Created: 23.1.1997 / 04:57:26 / cg"
    88 ! !
    88 ! !
    89 
    89 
    93     "must clear the is-block flag bit in the class
    93     "must clear the is-block flag bit in the class
    94      (otherwise, the VM might try to inline value-messages)"
    94      (otherwise, the VM might try to inline value-messages)"
    95 
    95 
    96     |newFlags|
    96     |newFlags|
    97 
    97 
    98     newFlags := (self flags 
    98     newFlags := (self flags
    99                     bitClear:(Behavior flagBlock))
    99 		    bitClear:(Behavior flagBlock))
   100                         bitOr:(Behavior flagBlockLike).
   100 			bitOr:(Behavior flagVarArgBlock).
   101     self flags:newFlags.
   101     self flags:newFlags.
   102 
   102 
   103     "
   103     "
   104      self flags.       
   104      self flags.
   105      self initialize.
   105      self initialize.
   106      self flags.      
   106      self flags.
   107     "
   107     "
   108 ! !
   108 ! !
   109 
   109 
   110 !VarArgBlock methodsFor:'evaluation'!
   110 !VarArgBlock methodsFor:'evaluation'!
   111 
   111 
   142 !
   142 !
   143 
   143 
   144 value:arg1 value:arg2 value:arg3 value:arg4
   144 value:arg1 value:arg2 value:arg3 value:arg4
   145     "evaluate the receiver with four arguments."
   145     "evaluate the receiver with four arguments."
   146 
   146 
   147     ^ super value:(Array 
   147     ^ super value:(Array
   148 		    with:arg1 
   148 		    with:arg1
   149 		    with:arg2 
   149 		    with:arg2
   150 		    with:arg3 
   150 		    with:arg3
   151 		    with:arg4)
   151 		    with:arg4)
   152 
   152 
   153     "Modified: 22.1.1997 / 19:41:22 / cg"
   153     "Modified: 22.1.1997 / 19:41:22 / cg"
   154     "Created: 23.1.1997 / 04:58:14 / cg"
   154     "Created: 23.1.1997 / 04:58:14 / cg"
   155 !
   155 !
   156 
   156 
   157 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5
   157 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5
   158     "evaluate the receiver with five arguments."
   158     "evaluate the receiver with five arguments."
   159 
   159 
   160     ^ super value:(Array 
   160     ^ super value:(Array
   161 		    with:arg1 
   161 		    with:arg1
   162 		    with:arg2 
   162 		    with:arg2
   163 		    with:arg3 
   163 		    with:arg3
   164 		    with:arg4
   164 		    with:arg4
   165 		    with:arg5)
   165 		    with:arg5)
   166 
   166 
   167     "Modified: 22.1.1997 / 19:41:26 / cg"
   167     "Modified: 22.1.1997 / 19:41:26 / cg"
   168     "Created: 23.1.1997 / 04:58:18 / cg"
   168     "Created: 23.1.1997 / 04:58:18 / cg"
   169 !
   169 !
   170 
   170 
   171 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6
   171 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6
   172     "evaluate the receiver with six arguments."
   172     "evaluate the receiver with six arguments."
   173 
   173 
   174     ^ super value:(Array 
   174     ^ super value:(Array
   175 		    with:arg1 
   175 		    with:arg1
   176 		    with:arg2 
   176 		    with:arg2
   177 		    with:arg3 
   177 		    with:arg3
   178 		    with:arg4
   178 		    with:arg4
   179 		    with:arg5
   179 		    with:arg5
   180 		    with:arg6)
   180 		    with:arg6)
   181 
   181 
   182     "Modified: 22.1.1997 / 19:41:29 / cg"
   182     "Modified: 22.1.1997 / 19:41:29 / cg"
   184 !
   184 !
   185 
   185 
   186 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7
   186 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7
   187     "evaluate the receiver with seven arguments."
   187     "evaluate the receiver with seven arguments."
   188 
   188 
   189     ^ super value:(Array 
   189     ^ super value:(Array
   190 		    with:arg1 
   190 		    with:arg1
   191 		    with:arg2 
   191 		    with:arg2
   192 		    with:arg3 
   192 		    with:arg3
   193 		    with:arg4
   193 		    with:arg4
   194 		    with:arg5
   194 		    with:arg5
   195 		    with:arg6
   195 		    with:arg6
   196 		    with:arg7)
   196 		    with:arg7)
   197 
   197 
   200 !
   200 !
   201 
   201 
   202 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8
   202 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8
   203     "evaluate the receiver with eight arguments."
   203     "evaluate the receiver with eight arguments."
   204 
   204 
   205     ^ super value:(Array 
   205     ^ super value:(Array
   206 		    with:arg1 
   206 		    with:arg1
   207 		    with:arg2 
   207 		    with:arg2
   208 		    with:arg3 
   208 		    with:arg3
   209 		    with:arg4
   209 		    with:arg4
   210 		    with:arg5
   210 		    with:arg5
   211 		    with:arg6
   211 		    with:arg6
   212 		    with:arg7
   212 		    with:arg7
   213 		    with:arg8)
   213 		    with:arg8)
   234 ! !
   234 ! !
   235 
   235 
   236 !VarArgBlock class methodsFor:'documentation'!
   236 !VarArgBlock class methodsFor:'documentation'!
   237 
   237 
   238 version
   238 version
   239     ^ '$Header: /cvs/stx/stx/libbasic/VarArgBlock.st,v 1.8 2013-04-16 12:44:14 cg Exp $'
   239     ^ '$Header$'
   240 ! !
   240 ! !
   241 
   241 
   242 
   242 
   243 VarArgBlock initialize!
   243 VarArgBlock initialize!