comp.lang.ada
 help / color / mirror / Atom feed
* function as first class object
@ 2018-01-15 16:20 Mehdi Saada
  2018-01-15 17:37 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 4+ messages in thread
From: Mehdi Saada @ 2018-01-15 16:20 UTC (permalink / raw)


I'm thinking only of a limited form.
Like writing:
type FILTER_TYPE is access function (S: in STRING) return STRING;
FILTER: FILTER_TYPE := ( TO_BASIC( TO_LOWER ) )'Access
Not sure of the syntax though. Could it done one way or another ? Since the language is taking a slightly functional approach.
I know my exemple can be done otherwise, but it means more lines to maintain, blablabla. Or maybe convoluted use of nesting functions into functions, are in fact so rare it's not worth it.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function as first class object
  2018-01-15 16:20 function as first class object Mehdi Saada
@ 2018-01-15 17:37 ` Dmitry A. Kazakov
  2018-01-15 17:46   ` Mehdi Saada
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry A. Kazakov @ 2018-01-15 17:37 UTC (permalink / raw)


On 2018-01-15 17:20, Mehdi Saada wrote:
> I'm thinking only of a limited form.
> Like writing:
> type FILTER_TYPE is access function (S: in STRING) return STRING;
> FILTER: FILTER_TYPE := ( TO_BASIC( TO_LOWER ) )'Access
> Not sure of the syntax though. Could it done one way or another ?

Yes. You declare an abstract filter type with a primitive operation 
Apply. Then you create handles to that type with the same interface.

The purpose of the exercise is to escape limitness of the target types.

You derive an object from the abstract filter type with the function as 
the discriminant of. The implementation of Apply calls to the 
discriminant function.

You derive an object from the abstract filter type with a container of 
handles. The implementation of Apply calls Apply for the elements of the 
list passing the result as an argument to the next.

You define a compose operation, e.g. "+" on handles that creates an 
object with two handles in the list taken from the arguments and returns 
a handle to it.

That is.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function as first class object
  2018-01-15 17:37 ` Dmitry A. Kazakov
@ 2018-01-15 17:46   ` Mehdi Saada
  2018-01-15 17:50     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 4+ messages in thread
From: Mehdi Saada @ 2018-01-15 17:46 UTC (permalink / raw)


That's what I had in mind... But it's quite verbose.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: function as first class object
  2018-01-15 17:46   ` Mehdi Saada
@ 2018-01-15 17:50     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry A. Kazakov @ 2018-01-15 17:50 UTC (permalink / raw)


On 2018-01-15 18:46, Mehdi Saada wrote:
> That's what I had in mind... But it's quite verbose.

Not for the end user. For him it could be:

    +To_Basic'Access * +To_Lower'Access

or even reduced to:

    To_Basic'Access * To_Lower'Access

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-15 17:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-15 16:20 function as first class object Mehdi Saada
2018-01-15 17:37 ` Dmitry A. Kazakov
2018-01-15 17:46   ` Mehdi Saada
2018-01-15 17:50     ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox