aboutsummaryrefslogtreecommitdiff
path: root/doc/functional.md
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-05 16:46:42 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-05 16:46:42 -0400
commita25cb2b0bf26033c9bc778d816618a752d015d99 (patch)
tree7056712bb10bf509764e04e56267f106e50dbea0 /doc/functional.md
parentdf5ddc0ed2fe48411645228c6e2d596be239a0c6 (diff)
Somehow, all the docs have now been edited
Diffstat (limited to 'doc/functional.md')
-rw-r--r--doc/functional.md12
1 files changed, 6 insertions, 6 deletions
diff --git a/doc/functional.md b/doc/functional.md
index 54989fae..cd7656ca 100644
--- a/doc/functional.md
+++ b/doc/functional.md
@@ -4,9 +4,9 @@
BQN boasts of its functional capabilities, including first-class functions. What sort of functional support does it have, and how can a BQN programmer exercise these and out themself as a Schemer at heart?
-First, let's be clear about what the terms we're using mean. A language has *first-class functions* when functions (however they are defined) can be used in all the same ways as "ordinary" values like numbers and so on, such as being passed as an argument or placed in a list. Lisp and JavaScript have first-class functions, C has unsafe first-class functions via function pointers, and Java 7 and APL don't have them as functions can't be placed in lists or used as arguments. This doesn't mean every operation is supported on functions: for instance, numbers can be added, compared, and sorted; while functions could perhaps be added to give a train, comparing or sorting them as functions (not representations) isn't computable, and BQN doesn't support any of the three operations when passing functions as arguments.
+First, let's be clear about what the terms we're using mean. A language has *first-class functions* when functions (however they are defined) can be used in all the same ways as "ordinary" values like numbers and so on, such as being passed as an argument or placed in a list. Lisp and JavaScript have first-class functions, and C has unsafe first-class functions via function pointers. Java 7 and APL don't have them, as functions can't be placed in lists or used as arguments. This doesn't mean every operation is supported on functions: for instance, numbers can be added, compared, and sorted; while functions could perhaps be added to give a train, comparing or sorting them as functions (not representations) isn't computable, and BQN doesn't support any of the three operations when passing functions as arguments.
-Traditionally, APL has worked around its lack of first-class functions with operators, that is, second-order functions. Arrays in APL are first class while functions are second class and operators are third class, and each class can act on the ones before it. However, the three-tier system has some obvious limitations that we'll discuss, and BQN removes these by making every type first class.
+Traditionally, APL has worked around its lack of first-class functions with operators, that is, second-order functions. Arrays in APL are first class while functions are second class and operators are third class, and each class can act on the ones above it. However, the three-tier system has some obvious limitations that we'll discuss, and BQN removes these by making every type first class.
<!--GEN
pl ← <˘∘‿2⥊⟨
@@ -80,9 +80,9 @@ To ← {
-->
-The term *functional programming* is more contentious, and has many meanings some of which can be vague. Here I use it for what might be called *first-class functional programming*, programming that makes significant use of first-class functions; in this usage, Scheme is probably the archetypal functional programming language. However, other definitions are also worth mentioning. APL is often called a functional programming language on the grounds that functions can be assigned and manipulated, and called recursively, all characteristics it shares with Lisp. I prefer the term *function-level programming* for this usage. A newer usage, which I call *pure functional programming*, restricts the term "function" to mathematical functions, which have no side effects, so that functional programming is programming with no side effects, often using monads to accumulate effects as part of arguments and results instead. Finally, *typed functional programming* is closely associated with pure functional programming and refers to languages influenced by type theory such as [Haskell](https://www.haskell.org/), [F#](https://fsharp.org/), and [Idris](https://www.idris-lang.org/) (the last of which even supports *[dependently-typed](https://en.wikipedia.org/wiki/Dependent_type) functional programming*, but I already said "finally" so we'll stop there). Of these, BQN supports first-class functional and function-level programming, allows but doesn't encourage pure functional programming, and does not support typed functional programming, as it's dynamically and not statically typed.
+The term *functional programming* is more contentious, and has many meanings some of which can be vague. Here I use it for what might be called *first-class functional programming*, programming that makes significant use of first-class functions; in this usage, Scheme is probably the archetypal functional programming language. However, other definitions are also worth mentioning. APL is often called a functional programming language on the grounds that functions can be assigned and manipulated, and called recursively, all characteristics it shares with Lisp. I prefer the term *function-level programming* for this usage. A newer usage, which I call *pure functional programming*, restricts the term "function" to mathematical functions, which have no side effects, so that functional programming is programming with no side effects, often using monads to accumulate effects as part of arguments and results instead. Finally, *typed functional programming* is closely associated with pure functional programming and refers to languages influenced by type theory such as [Haskell](https://www.haskell.org/), [F#](https://fsharp.org/), and [Idris](https://www.idris-lang.org/) (the last of which even supports *[dependently-typed](https://en.wikipedia.org/wiki/Dependent_type) functional programming*, but I already said "finally" so we'll stop there). Of these, BQN supports first-class functional and function-level programming, allows but doesn't encourage pure functional programming, and doesn't support typed functional programming, as it's dynamically and not statically typed.
-Another topic we are interested in is *lexical scoping* and *closures*. [Lexical scoping](lexical.md) means that the realm in which a variable exists is determined by its containing context (in BQN, the surrounding set of curly braces `{}`, if any) within the source code. A closure is really an implementation mechanism, but it's often used to refer to a property of lexical scoping that appears when functions defined in a particular block can be accessed after the block finishes execution. For example, they might be returned from a function or assigned to a variable outside of that function's scope. In this case the functions can still access variables in the original scope. I consider this property to be a requirement for a correct lexical scoping implementation, but it's traditionally not a part of APL: implementation might not have lexical scoping (for example, J and I believe [A+](https://aplwiki.com/wiki/A+) use static scoping where functions can't access variables in containing scopes) or might cut off the scope once execution ends, leading to value errors that one wouldn't predict from the rules of lexical scoping.
+Another topic we're interested in is *lexical scoping* and *closures*. [Lexical scoping](lexical.md) means that the realm in which a variable exists is determined by its containing context (in BQN, the surrounding set of curly braces `{}`, if any) within the source code. A closure is really an implementation mechanism, but it's often used to refer to a property of lexical scoping that appears when functions defined in a particular block can be accessed after the block finishes execution. For example, they might be returned from a function or assigned to a variable outside of that function's scope. In this case the functions can still access variables in the original scope. I consider this property to be a requirement for a correct lexical scoping implementation, but it's traditionally not a part of APL: implementation might not have lexical scoping (for example, J and K use static scoping where functions can't access variables in containing scopes) or might cut off the scope once execution ends, leading to value errors that one wouldn't predict from the rules of lexical scoping.
## Functions in APL
@@ -118,7 +118,7 @@ As with all functions, the result of `Lin` has a subject role. To use it as a fu
expLin ← Lin exp
ExpLin 5
-A tricker but more compact method is to use the 1-modifier `{𝔽}`, as the input to a modifier can have a subject or function role but its output always has a function role.
+A tricker but more compact method is to use the 1-modifier `{𝔽}`, as a modifier's operand can have a subject or function role but its output always has a function role.
(Lin exp){𝔽} 5
@@ -153,7 +153,7 @@ Another, and probably more common, use of arrays of functions is to apply severa
⟨√, 2⊸≍, ⊢-⋆⟩ {𝕎𝕩}¨ 9
-The 2-modifier Choose (`◶`) relies on arrays of functions to… function. It's very closely related to Pick `⊑`, and in fact when the left operand and the elements of the right operand are all data there's no real difference: Choose returns the constant function `𝕗⊑𝕘`.
+The 2-modifier [Choose](choose.md) (`◶`) relies on arrays of functions to… function. It's very closely related to [Pick](pick.md) `⊑`, and in fact when the left operand and the elements of the right operand are all data there's no real difference: Choose results in the constant function `𝕗⊑𝕘`.
2◶"abcdef" "arg"