Re: [Oorexx-devel] Ad Trampoline, Partial arguments, higher order functions, pipeline (Re: Ad experimental ooRexx ...

2012-01-07 Thread Jean-Louis Faucher
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 

[Oorexx-devel] Ad Trampoline, Partial arguments, higher order functions, pipeline (Re: Ad experimental ooRexx ...

2012-01-03 Thread Rony G. Flatscher
Bonsoir Jean-Louis,

having read and experimented a little bit a few remarks and questions:

  * Trampoline: that's really cool as recursive functions become computable 
that otherwise would
not be able to run due to not enough control stack space as your factorial 
example nicely
demonstrates. I ran a classic recursive factorial and the trampoline 
version up to 1300!
increasing numeric digits to yield an exact result (going higher factorials 
will blow up the
control-stack in the classic version, where the trampoline version happily 
hums away). 

  * 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.

  * Higher-order functions: are the following basic definitions correct?
  o 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.
  o each: iterates over the items of a collection and returns an array in 
which each visited
item was processed according to the RexxBlock,
  o map: iterates over the items of a collection and returns the 
collection in which each
visitied item was processed according to the RexxBlock,
  o 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)?

  * Higher-order functions: 
  o What are mapR and eachI for?
  o What are mapCR, mapWR, eachCI, eachWI for?
  o 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. 

  * ad filter: what is a filter and where and how can one use it?

  * ad  times, times.yield, resume: for which objects are these methods 
defined and what do
they do?

  * ad using block syntax without surrounded by round parentheses: it seems 
that one can state
~map{expression or code with return-statement} instead of ~map({expression 
or code with
return-statement}): is this intentional (it would break the simple rule 
that if a method gets an
argument this argument needs to be enclosed in round parentheses) ? E.g. 
from your readme.txt:
abcdefghijk~mapC{arg(2):arg(1) }

  * expressions implicitly returning a value: if a RexxBlock only consists of 
an expression, then
the result of the expression will be returned, e.g. 12~times({arg(1)/2}) 
which is the same as
12~times({return arg(1)/2}). This is probably intentional, still thinking 
whether I like it or
not (the return-keyword statement is one that every Rexx programmer is 
accustomed to and that
explicitly documents what the code is supposed to do; not having a return 
keyword statement
should cause a runtime error if a result is expected; the implicit return 
is probably not really
Rexxish, although neat in this particular context, which is probably 
restricted to RexxBlocks?).


A last question related to Pipelines (have not yet come to this corner): is 
this an adaptation of
the ooRexx samples\pipe.rex where you just employ closures and 
coactivities? It looks like that
(seems to supply a .do stage allowing deifning RexxBlocks, which is very 
powerful; also a stage
named .inject and .drop? Maybe .console etc.).

TIA,

---rony


--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel