Guten abend Rony,
- Partial arguments: this looks very interesting. However, I have
been a little bit surprised that the creation of the final argument array
does not append the new arguments to the partial ones and also leaves out
array entries that are empty. Why is this? It may be the case that for some
analysis it becomes important to be able to learn whether an argument was
omitted or not.
Since ooRexx lets omit arguments, I thought it was interesting to keep
this feature for partial arguments.
An example with oodialog. I give the signature of the method, and then I
define a closure for this method, with partial arguments. You will see that
createTahoma keeps omitted arguments. Some of these omitted arguments are
provided by createCenteredTahoma (chained partials).
The first argument of the closures is an instance of .UserDialog, because
the closures are built from a message (so the 1st arg becomes the receiver).
PS : I don't claim this example is a good example with oodialog. I needed
methods with many arguments, to illustrate ~partial with omitted arguments.
And oodialog fits this need. This example also demonstrates that closures
are functional, not object-oriented.
-- .UserDialog~create(x, y, cx, cy, title, style, dlgClass, fontName,
fontSize, expected)
-- createTahoma(dialog, x, y, cx, cy, title, style, fontSize, expected)
createTahoma = create~partial(Tahoma)
-- for illustration of chained partials (could use ~createCenter directly)
-- createCenteredTahoma(dialog, cx, cy, title, fontSize, expected)
createCenteredTahoma = createTahoma~partial(,0,0center)
-- .UserDialog~createStaticText(id, x, y, cx, cy, style, text)
-- createStaticText(dialog, cx, cy, text)
createStaticText = createStaticText~partial(,-1,1,1,,,SUNKEN)
dialog = .UserDialog~new
createCenteredTahoma~(dialog, 100, 10, hello, 30)
createStaticText~(dialog,,, this is a static text (close me))
dialog~execute(showtop)
::requires oodialog.cls
::requires extension/extensions.cls
- Higher-order functions: are the following basic definitions
correct?
- reduce: iterates over the items of a collection and supplies
them one by one as an argument to the block processing/accumulating
them in
one way or the other.
- each: iterates over the items of a collection and returns an
array in which each visited item was processed according to the
RexxBlock,
- map: iterates over the items of a collection and returns the
collection in which each visitied item was processed according to the
RexxBlock,
- reduceW is reduceWords, reduceC is reduceChar, mapW is
mapWords, mapC is mapChars, eachW is eachWords, eachC is
eachChars: they are available for .String and .MutableBuffer and
there as
a convenience (assuming that one could always create an array of words
or
chars from a string and then use reduce, map and each on them)?
yes, all this is correct
- Higher-order functions:
- What are mapR and eachI for?
R stands for Replace :
~map returns a copy of the collection.
~mapR modifies the collection in-place.
I stands for Indexed
~each returns an array of results
~eachI returns an array of results and indexes. In the dropbox delivery,
it's an array of two arrays. I'm reworking that in my sandbox : now it's an
array of pairs (result, index). This is because I'm implementing a specific
version of ~each for the coactivities. A lazy ~each must yield one result
at a time, so when indexed, must be a pair (result, index).
- What are mapCR, mapWR, eachCI, eachWI for?
mapCR : iterate over the characters and replace them by the returned
results (update in-place).
mapWR : iterate over the words and replace them by the returned results
(update in-place).
eachCI : iterate over the characters and return an array of indexed results.
eachCI : iterate over the words and return an array of indexed results.
- functionDoer will get two named arguments value and index and in
the case of reduce these two arguments will be preceded by an argument
(frist argument) representing the current value. It would be probably
helpful for the ooRexx programmer, if value was named item as this
is
the term used in the ooRexx documentation for collections.
yes. I will change that. Will also apply this change to pipelines.
- ad filter: what is a filter and where and how can one use it?
The method ~each lets filter : if no result returned, then no entry added
in the array.
I will commit soon the methods ~select and ~reject which are convenience
methods. You can do the same with ~each, but the block is smaller, just a
boolean expression.
- ad times, times.yield, resume: for which objects are these
methods defined and what do they do?
~times and ~times.yield are defined on .String, but works only with numbers
(because do i=self to ...). Execute N times the given