I am replying inline...

On Sun, Jan 15, 2023 at 6:09 PM Raul Miller <rauldmil...@gmail.com> wrote:
>
> On Sun, Jan 15, 2023 at 3:38 PM Jose Mario Quintana
> <jose.mario.quint...@gmail.com> wrote:
> > I am aware that BQN has first-class functions.  Is there any other array
> > language that also has them?
>
> In this context, a mozilla page on "first class functions" is interesting:
>
> https://developer.mozilla.org/en-US/docs/Glossary/First-class_Function
>
> "A programming language is said to have First-class functions when
> functions in that language are treated like any other variable. For
> example, in such a language, a function can be passed as an argument
> to other functions, can be returned by another function and can be
> assigned as a value to a variable."
>
> ---------
>
> Here, BQN uses upper case vs. lower case to distinguish the role of a
> function definition (roughly analogous to distinguishing between a
> gerund and its verb form).

Right, I personally do not like too much that convention; in general, I use
lowercase names for functions and uppercase names for nouns (which I seldom
use).

>
> From a user perspective this is largely a syntactic issue (though, of
> course, there's also implementation issues).

The key word is "largely."  Any gerund still is a noun; thus, gerunds are
just representations of their associated functions.

>
> ---------
>
> The K/Q approach is also interesting here. (K is a family of languages
> rather than a single language -- it's intentionally undocumented with
> large differences between releases, and Q is (somewhat more stably)

There is a fair amount of q documentation here,

Reference card | kdb+ and q documentation - Kdb+ and q documentation
(kx.com) <https://code.kx.com/q/ref/>

> implemented in K.) Here, arrays are themselves "first class functions"
> -- specifically indexing a list has the same syntax as calling a
> function. There's no rank (all arrays are rank 1, though they may

Right, since there are list of lists of ... ;so, that does seem to be a big
issue (although one would have to write, for example, verbs for matrix
multiplication and inverse unless a suitable library is available).

> contain arrays analogous to J's boxing) and K's monadic verbs support
> a multi-argument sort of valence analogous to APL's multi-dimensional
> indexing A[1 2 3; 4 5 6;7 8 9] for example. And you might get into
> different operators when applying "functions" to values (though,
> because of the many versions, it's difficult to describe this
> comprehensively).

Lo and behold, q verbs are genuinely first-class, they can take and produce
verbs and, apparently, is the recommended way to program functionally in q.
The following is a toy example to illustrate the method by calculating a
sum of squares,

q){x y z}[(+/);{x xexp 2}]
{x y z}[+/;{x xexp 2}]
q)({x y z}[(+/);{x xexp 2}]) 1 2 3 4 / redundant parentheses for clarity
30f

or one could use the built-in keyword ' instead of {x y z}.  In j, of
course, one can do this,

   +/@:*:
+/@:*:
   (+/@:*:) 1 2 3 4
30

Yet, there is a subtle potentially critical difference, the q version {x y
z} is dynamic, but the j version @: is not because @: is a conjunction (not
surprisingly, tacit j8xx dynamic versions are possible when black cats are
involved).

>
> ---------
>
> Anyways, ... I guess one of the things which makes J's gerunds be
> considered as "not first class" is that they have a unique syntax
> which must be used when we consider them as verb definitions -- more
> specifically we can't use some of this syntax with actual verb
> definitions. (Interestingly, in some contexts, this distinction
> vanishes. So in those contexts we might consider verbs as first class
> while thinking of adverbs and conjunctions as not first class.)
>

Some time ago we had a similar discussion, I mentioned that, in my opinion,
the j9xx tacit tools were relatively weak and I proposed an exercise that
was just beyond trivial,

[Jchat] Was [Jprogramming] Tacit completeness (jsoftware.com)
<http://www.jsoftware.com/pipermail/chat/2021-December/009017.html>

Unfortunately, the j903 calculus add-on was unusable for that purpose.  I
wonder if some progress has been made.

Perhaps, this thread should be moved to the Chat forum although I would
like to see some j90x code here; but, I will let others decide.

> Thanks,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to