The essence of combinatory logic is to manipulate a set of data using function composition without having to reference the data in each of the functions. Combinatory logic is a form of lambda calculus, which is the basis of the functional programming paradigm(to use a cascade of functions to transform an input into a required output).
A combinator is a higher-order function that accepts other functions as arguments and produces a function application as output.
The language J implements some of the combinatory primitives discussed by Haskell Curry. Of particular interest are the concepts of hooks and forks in J.
Let us define a function g, that takes a number and calculates the sum of its square and factorial. An explicit definition of this function:
g(x) = (x! + x^2)The concept of a fork defines how a series of adjacent functions is applied to an argument. In J, if f g and h are functions, a fork is reduced in the following manner.
(f g h) x = f(x) g h(x)while a hook is reduced in the following manner:
(g h) x = x g h(x)We may use this concept to shorten the explicit function g(x) defined above:
g=: ! + *:Note that these combinators are implicit in J. Grouping two functions applies a hook combinator to them, grouping three functions ( a train in J terms) applies a fork to them. Various other combinators are present in the language that remove the need to explicitly reference variables in function compositions. This is one of the reasons J's syntax is so terse.
Ursala is another language that implements a form of combinatory logic, although it differs considerably from J's idea. Ursala solves the issue of eliminating variables from functions by using a form of variable addressing called pointer expressions.
(Continued later)
No comments:
Post a Comment