'First Class' function datatype

'First Class' function datatype

PostPosted by gar37bic » Sat Sep 04, 2010 12:19 pm

I have toyed with APL on and off for many years, and remain a kind of fan. I'll be trying this implementation out just for my own interest.

Lately I've been looking at the functional programming languages (particularly Erlang) which have a certain ancestral relation with APL. One of the features of the functional languages is 'first class functions', which simply means that functions can be handled to some extent like any other piece of data - passed around as function arguments, etc.

I do not recall this as being an APL feature so I may be blathering on about nothing, but here goes:

I think first class functions would be a powerful extension to APL. There have been (and maybe still are) some ways to evaluate a string as APL but if I recall correctly they don't really fit into the language cleanly. So I propose to implement this as a datatype. Then, just as any other variable, a function could be an argument to another function, or a member of an array.

The latter is most important, as program flow could be controlled by the usual array constructs. For example, one array could contain a set of truth values (1 0 0 1 1) or operations that result in truth values, and another a set of functions (or the same function with different arguments, etc.). Then implementing this sort-of-case statement would be a simple dyadic operation with the truth set on the left and the function set on the right.

At first glance, there are some complications but I think that these are surmountable. I think the function data type would have to look much like a string, evaluated only when it is invoked. I haven't thought through what the various operators would do to these functions-as-variables, but it seems entirely reasonable that one could handle, create or modify them as strings.
gar37bic
 
Posts: 5
Joined: Sat Sep 04, 2010 11:59 am

PostPosted by forummaster » Sun Nov 07, 2010 10:37 am

{98.220}gar37bic wrote:
{98.220}gar37bic wrote:
I have toyed with APL on and off for many years, and remain a kind of fan. I'll be trying this implementation out just for my own interest.

Lately I've been looking at the functional programming languages (particularly Erlang) which have a certain ancestral relation with APL. One of the features of the functional languages is 'first class functions', which simply means that functions can be handled to some extent like any other piece of data - passed around as function arguments, etc.

I do not recall this as being an APL feature so I may be blathering on about nothing, but here goes:

I think first class functions would be a powerful extension to APL. There have been (and maybe still are) some ways to evaluate a string as APL but if I recall correctly they don't really fit into the language cleanly. So I propose to implement this as a datatype. Then, just as any other variable, a function could be an argument to another function, or a member of an array.

The latter is most important, as program flow could be controlled by the usual array constructs. For example, one array could contain a set of truth values (1 0 0 1 1) or operations that result in truth values, and another a set of functions (or the same function with different arguments, etc.). Then implementing this sort-of-case statement would be a simple dyadic operation with the truth set on the left and the function set on the right.

At first glance, there are some complications but I think that these are surmountable. I think the function data type would have to look much like a string, evaluated only when it is invoked. I haven't thought through what the various operators would do to these functions-as-variables, but it seems entirely reasonable that one could handle, create or modify them as strings.

The idea of functions as data has been discussed for many years without any agreement on a proposal. If you can work out the details (and the details are where these ideas fail), I'd love to see it.
forummaster
 
Posts: 567
Joined: Wed Jan 23, 2013 1:00 pm

PostPosted by manandpc » Thu Jul 05, 2012 9:47 am

I have a suggestion:

Use 'Divide to Conquer" for your idea. begin small

For example, you can thnk to extend data type to be similar to cells like 'Ms Excel Worksheet cells'. Those cells contains formulas or data.
manandpc
 
Posts: 67
Joined: Tue Jun 19, 2012 9:39 am


Return to New Datatypes

Who is online

Users browsing this forum: No registered users and 0 guests

cron