tacit programming : Point-free, Concatenatives & J
https://gyazo.com/0db5c983c9b10230c31cd41d54caf6c2
concatenative programming language
concatenative
concatenate + -ive
連鎖する性質を持つ、連鎖性
quotation & combinator
A concatenative programming language is a point-free computer programming language in which all expressions denote functions, and the juxtaposition of expressions denotes function composition. Concatenative programming replaces function application, which is common in other programming styles, with function composition as the default way to build subroutines.
聯結型プログラミング言語とは、すべての式が函數を表し、式の聯結が函數合成を意味する點を持たないコンピュータプログラミング言語である。このプログラミングスタイルでは、他のプログラミングスタイルでよく用ゐられる函數適用の代はりに、函數合成をサブルーチン構築の標準的な方法として採用してゐる。
實裝
Joy
The Joy programming language in computer science is a purely functional programming language that was produced by Manfred von Thun of La Trobe University in Melbourne, Australia. Joy is based on composition of functions rather than lambda calculus. It has turned out to have many similarities to Forth, due not to design but to a sort of parallel evolution and convergence. It was also inspired by the function-level programming style of John Backus's FP.
コンピュータサイエンス分野における Joy 言語は、オーストラリア・メルボルンのラ・トローブ大學のマンフレート・フォン・トゥンによって開發された純粹函數型プログラミング言語である。この言語はλ計算ではなく、函數の合成を基本原理として設計されてゐる。設計思想とは無關係に、Forth 言語と多くの類似點が見られるが、これは一種の竝行進化と収束の結果である。また、ジョン・バッカスの函數型プログラミング言語「FP」の函數レベルプログラミングスタイルからも强い影響を受けてゐる。 Joy 言語は純粹な函數型プログラミング言語である。他のすべての函數型プログラミング言語が函數の引數への適用を基本とするのに對し、Joy は函數の合成を基本原理としてゐる。これらの函數はいずれもスタックを引數として受け取り、スタックを結果として返す。このため、Joy の構文は一見すると通常の後置記法に似てゐる。ただし、Joy では函數がスタックから任意の數の引數を消費し、任意の數の結果をスタックに殘すことができる。適切なプログラムを聯結することで、それらのプログラムが表す函數の合成操作を表現できる。Joy のデータ型の一つに「引用プログラム」があり、リストはその特殊なケースである。特定の函數はスタックの最上位に引用プログラムがあることを前提としてをり、これを樣々な方法で實行する。本質的には脫引用處理によって實行されるのである。他の函數型言語が抽象化と適用を基本とするのに對し、Joy は引用とコンビネータ⸺脫引用處理を實行する函數⸺を採用してゐる。このため、Joy には名前附きの形式パラメータは存在せず、實際の引數と形式パラメータの置換も行はれず、名前と値の對応關係からなる環境も存在しない。Joy のコンビネータは、他言語における函數型や高階函數とほぼ同樣の振る舞ひをし、再歸的定義と非再歸的定義の必要性を最小限に抑へてゐる。環境が不要であるため、Joy の代數構造は極めて單純であり、プログラムは手作業や他のプログラムによって容易に操作できる。多くのプログラムでは、まず別のプログラムを構築してからそれを實行するといふ手法が取られる。本稿は Forth 言語のプログラマーを對象とした入門書として執筆されたものである。
Factor
Factor is a stack-oriented programming language created by Slava Pestov. Factor is dynamically typed and has automatic memory management, as well as powerful metaprogramming features. The language has a single implementation featuring a self-hosted optimizing compiler and an interactive development environment. The Factor distribution includes a large standard library.
Factor はスラヴァ・ペストフによって開發されたスタック指向のプログラミング言語である。動的型附けを採用してをり、自動メモリ管理機能を備へてゐるほか、强力なメタプログラミング機能を有してゐる。この言語には單一の實裝が存在し、自己ホスト型の最適化コンパイラと對話型開發環境を特徵としてゐる。Factor の配布パッケージには、豐富な標準ライブラリが含まれてゐる。
The Factor programming language combines powerful language features with a full-featured library. The implementation is fully compiled for performance, while still supporting interactive development. Factor applications are portable between all common platforms. Factor can deploy stand-alone applications on all platforms. Full source code for the Factor project is available under a BSD license.
Factor belongs to the family of concatenative languages: this means that, at the lowest level, a Factor program is a series of words (functions) that manipulate a stack of references to dynamically-typed values. This gives the language a powerful foundation which allows many abstractions and paradigms to be built on top. Reload this page to see a random code example below.
Factor プログラミング言語は、强力な言語機能と充實した標準ライブラリを兼ね備へてゐる。實裝は完全にコンパイルされるため高いパフォーマンスを發揮する一方で、インタラクティブな開發環境もサポートしてゐる。Factor で開發されたアプリケーションは、すべての主要なプラットフォーム間で移植可能だ。Factor を使えば、スタンドアロンアプリケーションをあらゆるプラットフォームに展開できる。Factor プロジェクトの完全なソースコードは、BSD ライセンスの下で公開されてゐる。
Factor は「聯結型言語」の一種に分類される。これは、最も基本的なレベルでは、Factor プログラムがスタック上の動的型附け値への參照を操作する一聯のワード (函數) から構成されることを意味する。この設計により、言語は强力な基盤を備へてをり、その上に多樣な抽象化やプログラミングパラダイムを構築することが可能となる。このページを再讀み込みすると、以下にランダムなコード例が表示される。
Kitten
Kitten is a statically typed, stack-based functional programming language designed to be simple and fast. It is a concatenative language, combining aspects of imperative and pure functional programming. There is an introduction available and a tutorial in progress.
Kitten は靜的型附けのスタックベース函數型プログラミング言語で、シンプルさと高速性を追求した設計となってゐる。聯結型言語の特性を持ち、命令型プログラミングと純粹函數型プログラミングの要素を融合してゐる。入門ガイドが利用可能で、現在チュートリアルが作成中である。
PISC (Position Independent Source Code)
Popr
unix pipe & filter
stream
tacit programming
Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions, among which are combinators that manipulate the arguments. Tacit programming is of theoretical interest, because the strict use of composition results in programs that are well adapted for equational reasoning. It is also the natural style of certain programming languages, including APL and its derivatives, and concatenative languages such as Forth. The lack of argument naming gives point-free style a reputation of being unnecessarily obscure, hence the epithet "pointless style".
Unix scripting uses the paradigm with pipes.
The key idea in tacit programming is to assist in operating at the appropriate level of abstraction. That is, to translate the natural transformation given by currying$ \hom(A\times B,C)\cong \hom(B,C^{A})into computer functions, where the left represents the uncurried form of a function and the right the curried. $ C^A denotes the functionals from $ A to $ C (see also exponential object), while $ A\times B denotes the Cartesian product of $ A and $ B.
暗默的プログラミング (別名: ポイントフリースタイル) とは、函數定義において操作對象となる引數 (「ポイント」) を明示しないプログラミングパラダイムである。代はりに、定義では他の函數を組み合はせるのみで、その中には引數を操作するコンビネータも含まれる。この手法は理論的に興味深い性質を持つ。なぜなら、合成演算を嚴密に用ゐることで、等式的推論に適したプログラムが生成されるからである。また、APL やその派生言語、Forth などの聯結型言語など、特定のプログラミング言語の自然な記述スタイルでもある。引數名が存在しないため、このスタイルは不必要に難解だといふ評判があり、そのため「ポイントレススタイル」といふ蔑称で呼ばれることもある。
Unix のスクリプト處理では、このパラダイムがパイプ機構によって實現されてゐる。
暗默的プログラミングの核心的な槪念は、適切な抽象化レベルでの操作を容易にすることにある。具体的には、curry 化によって得られる自然な変換$ \hom(A\times B,C)\cong \hom(B,C^{A})]を、コンピュータプログラムの函數に変換することを指す。ここで左側はカリー化されていない函數の形式を、右側はカリー化された函數の形式をそれぞれ表現してゐる。$ C^Aは$ Aから$ Cへの函數の集合を表し(指數對象も參照)、$ A\times Bは$ Aと$ Bの直積集合を表す。 tacit programming is a programming method to construct functions without explicit arguments.
a.k.a. "point-free style"
prefer function composition than function application
$ \lambdaabstraction$ \toquotation
function application$ \tofunction composition
It is very common for functional programmers to write functions as a composition of other functions, never mentioning the actual arguments they will be applied to.
函數型プログラミングでは、函數を他の函數の合成として記述することが一般的であり、實際に適用される具体的な引數については言及しないことが多い。
資料
add
code:haskell
2 + 3
(+) 2 3
code:kitten
2 3 (+)
code:popr
2 3 +
code:j
2+3
+/2 3
average
code:haskell
foldr (+) 0 xs / (fromIntegral . length $ xs)
((/) . foldr (+) 0) <*> (fromIntegral . length) $ 2, 3 code:kitten
2, 3 dup 0 {(+)} fold_left swap length (/) code:popr
2 3 dup sum swap length /f code:j
xs=.2 3
(+/xs)%(#xs)
(+/%#)2 3
factorial
code:haskell
(foldr (*) 1) . (enumFromTo 1) $ 9
(foldr (*) 1) . (enumFromTo 1) $ 0
code:factor
USING: io kernel locals math math.parser ;
IN: factorial
: factorial_rec ( n n -- n ) dup 0 = drop [ n m | n m * m 1 - factorial_rec call
] if ;
9 factorial
code:factor
USING: kernel math math.ranges memoize sequences ;
IN: math.factorials
MEMO: factorial ( n -- n! )
9 factorial
0 factorial
code:kitten
9 { -> n, rec; if (n <= 0) { 1 } else { (n - 1) rec call * n } } fix
code:popr
9 fact
:bc fact
___ tests.fact (1 -> 1) x2 rec (hash: jr44u) ___
1 changing var >= 1 :: ?i x4 pgjhj 2 __primitive.eq &1 &3 :: y x1 bbebh 4 __primitive.assert &3 2 is 1 :: i? x1 iw379 6 __primitive.gt &1 &3 :: y x1 paus6 7 __primitive.assert 10 6 :: i? x1 nm6vj 8 __primitive.sub &1 3 >= 0 :: i x1 lukbp 9 tests.fact 8 :: i x1 jvosc 10 __primitive.mul 1 9 :: i x1 fgkih 3 fact
3 2 fact *
3 2 1 fact * *
3 2 1 * *
3 2 *
6
code:j
!9
!0
code:j
*/1+i.9
*/1+i.0
*/i.0
code:j
factorial =: 1: ` (* factorial@<:) @. *
factorial 9
factorial 0
factorial 2
1: ` (* factorial @ <:) @. * 2
* 2
1
(* factorial @ <:) 2
2 * (factorial @ <: 2)
2 * (factorial 1)
2 * (1: ` (* factorial@<:) @. * 1)
* 1
1
2 * (1 * (factorial@<: 1))
2 * (1 * (factorial 0))
2 * (1 * (1: ` (* factorial@<:) @. * 0))
* 0
0
2 * (1 * (1: 0))
2 * (1 * (1))
2 * 1
2
quicksort
code:j
quicksort=:(($:@(<#[),(=#[),$:@(>#[))({~?@#))^:(1<#)
quicksort 1 _9 2 _8 3 _7 4 _6 5
_9 _8 _7 _6 1 2 3 4 5
FizzBuzz
code:haskell
map (\n -> if (n mod 3 == 0) then "Fizz" else (show n)) 1..100 code:popr
code:j
''(('|'E.B)#i.#B)}B=.}.}:1{":(<'FizzBuzz')(<:(0 E.15|A)#A)}(<'Buzz')(<:(0 E.5|A)#A)}(<'Fizz')(<:(0 E.3|A)#A)}<"0 A=.>:i.100