Kap: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Fix formatting error)
m (Congratulations you are now an influencer! (TinyAPL))
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox array language
{{Infobox array language
| logo                    = [[file:kap_logo.png]]
| array model              = [[nested array model|nested]]
| array model              = [[nested array model|nested]]
| index origin            = 0
| index origin            = 0
| function styles          = block (like [[dfn]]s)
| function styles          = block (like [[dfn]]s)
| numeric types            = 64-bit float, 64-bit integer, complex (64-bit float components)
| numeric types            = 64-bit float, 64-bit integer, complex (64-bit float components), unlimited precision big rationals
| unicode support          = full
| unicode support          = full
| released                = 2020
| released                = 2020
| developer                = [[Elias Mårtenson]]
| developer                = [[Elias Mårtenson]]
| latest release version  = 2022 (unversioned)
| latest release version  = 2024 (unversioned)
| implementation language  = [[wikipedia:Kotlin (programming language)|Kotlin]]
| implementation language  = [[wikipedia:Kotlin (programming language)|Kotlin]]
| source                  = [https://github.com/lokedhs/array GitHub]
| source                  = [https://codeberg.org/loke/array Codeberg]
| platforms                = JVM, Native Linux, In-browser, [[wikipedia:Node.js|Node.js]]
| platforms                = JVM, Native Linux, In-browser, [[wikipedia:Node.js|Node.js]]
| license                  = [[wikipedia:MIT License|MIT]]
| license                  = [[wikipedia:MIT License|MIT]]
| website                  = [https://kapdemo.dhsdevelopments.com/ KAP]
| website                  = [https://kapdemo.dhsdevelopments.com/ Kap]
| documentation            = [https://kapdemo.dhsdevelopments.com/kap-comparison.html KAP for APL’ers]
| documentation            = [https://kapdemo.dhsdevelopments.com/reference.html Kap reference]
| file ext                = .kap
| file ext                = .kap
| influenced by            = [[Dyalog APL]], [[GNU APL]]
| influenced by            = [[Dyalog APL]], [[GNU APL]], [[BQN]]
| influenced              = [[TinyAPL]]
| run online              = [https://kapdemo.dhsdevelopments.com/clientweb2/ JS Client]
| run online              = [https://kapdemo.dhsdevelopments.com/clientweb2/ JS Client]
}}
}}


'''KAP''' is an array-based language that aims to implement most of standard APL, along with additional features. Much of standard APL works in KAP, although if an APL feature does not fit with KAP's design, those features are changed or removed.
'''Kap''' is an array-based language that aims to implement most of standard APL, along with additional features. Much of standard APL works in Kap, although if an APL feature does not fit with Kap's design, those features are changed or removed.


== Lazy evaluation ==
== Lazy evaluation ==


The main difference compared to APL is that KAP is lazy-evaluated. This means that the language gives the developers very loose guarantees when (or if, and how many times) a function will actually be invoked. For example, <source lang=apl inline>↑ f¨ ⍳10</source> will only make a single call to <source lang=apl inline>f</source> because <code>f¨ ⍳10</code> will not immediately evaluate the result but only return a delayed evaluation. Since all but the first result is then discarded, those results will never be computed.
The main difference compared to APL is that Kap is lazy-evaluated. This means that the language gives the developers very loose guarantees when (or if, and how many times) a function will actually be invoked. For example, <syntaxhighlight lang=apl inline>↑ f¨ ⍳10</syntaxhighlight> will only make a single call to <syntaxhighlight lang=apl inline>f</syntaxhighlight> because <code>f¨ ⍳10</code> will not immediately evaluate the result but only return a delayed evaluation. Since all but the first result is then discarded, those results will never be computed.


== Differences from APL ==
== Differences from APL ==


The following is a list of significant differences compared to APL:
The following is a list of significant differences compared to APL:<ref>Mårtenson, Elias. [https://kapdemo.dhsdevelopments.com/kap-comparison.html Kap for APL’ers]. Unversioned. Retrieved 2023-08-13.</ref>


* Lazy evaluation
* Lazy evaluation
* All values are immutable, it is not possible to modify the content of an array
* First class functions
* Bignum support and rational arithmetic
* Ability to define custom syntax
* Ability to define custom syntax
* Native hash table support
* Native hash table support
{{APL dialects}}[[Category:APL dialects]][[Category:Nested array languages]][[Category:Leading axis languages]]
* Parallel evaluation (to take advantage of multi-core CPU's)
 
== Primitives ==
 
=== Functions ===
 
{|class=wikitable
! Glyph                                                !! Monadic                    !! Dyadic
|-
| <syntaxhighlight lang=apl inline>+</syntaxhighlight> || [[Conjugate]]              || [[Add]]
|-
| <syntaxhighlight lang=apl inline>-</syntaxhighlight> || [[Negate]]                || [[Subtract]]
|-
| <syntaxhighlight lang=apl inline>×</syntaxhighlight> || Angle ([[Signum]])        || [[Multiply]]
|-
| <syntaxhighlight lang=apl inline>÷</syntaxhighlight> || [[Reciprocal]]            || [[Divide]]
|-
| <syntaxhighlight lang=apl inline>|</syntaxhighlight> || [[Magnitude]]              || [[Mod]]
|-
| <syntaxhighlight lang=apl inline>⋆</syntaxhighlight> ||colspan=2| [[Power]]
|-
| <syntaxhighlight lang=apl inline>⍟</syntaxhighlight> ||colspan=2| [[Log]]
|-
| <syntaxhighlight lang=apl inline>=</syntaxhighlight> ||                            || [[Equals]]
|-
| <syntaxhighlight lang=apl inline>≠</syntaxhighlight> ||                            || [[Not equals]]
|-
| <syntaxhighlight lang=apl inline><</syntaxhighlight> || [[Increase rank]]          || [[Less than]]
|-
| <syntaxhighlight lang=apl inline>></syntaxhighlight> || [[Decrease rank]]          || [[Greater than]]
|-
| <syntaxhighlight lang=apl inline>≤</syntaxhighlight> ||                            || [[Less than or equal]]
|-
| <syntaxhighlight lang=apl inline>≥</syntaxhighlight> ||                            || [[Greater than or equal]]
|-
| <syntaxhighlight lang=apl inline>∧</syntaxhighlight> || [[Sort up]]                || [[Logical and]]
|-
| <syntaxhighlight lang=apl inline>∨</syntaxhighlight> || [[Sort down]]              || [[Logical or]]
|-
| <syntaxhighlight lang=apl inline>⍲</syntaxhighlight> ||                            || [[Logical nand]]
|-
| <syntaxhighlight lang=apl inline>⍱</syntaxhighlight> ||                            || [[Logical nor]]
|-
| <syntaxhighlight lang=apl inline>∼</syntaxhighlight> || [[Logical not]]            || [[Without]]
|-
| <syntaxhighlight lang=apl inline>√</syntaxhighlight> || [[Square root]]            || [[Root]]
|-
| <syntaxhighlight lang=apl inline>⌊</syntaxhighlight> || [[Floor]]                  || [[Min]]
|-
| <syntaxhighlight lang=apl inline>⌈</syntaxhighlight> || [[Ceiling]]                || [[Max]]
|-
| <syntaxhighlight lang=apl inline>!</syntaxhighlight> || [[Factorial|Gamma]]        || [[Binomial]]
|-
| <syntaxhighlight lang=apl inline>⍴</syntaxhighlight> || [[Shape]]                  || [[Reshape]]
|-
| <syntaxhighlight lang=apl inline>⍳</syntaxhighlight> || [[Index generator]]        || [[Index of]]
|-
| <syntaxhighlight lang=apl inline>⊢</syntaxhighlight> || [[Identity]]              || [[Right]]
|-
| <syntaxhighlight lang=apl inline>⊣</syntaxhighlight> || [[Hide]]                  || [[Left]]
|-
| <syntaxhighlight lang=apl inline>⌷</syntaxhighlight> ||                            || [[Index (function)|Index lookup]]
|-
| <syntaxhighlight lang=apl inline>⊂</syntaxhighlight> || [[Enclose]]                || [[Partitioned enclose]]
|-
| <syntaxhighlight lang=apl inline>⊃</syntaxhighlight> || [[Disclose]]              || [[Pick]]
|-
| <syntaxhighlight lang=apl inline>,</syntaxhighlight> || [[Ravel]]                  || [[Concatenate]]
|-
| <syntaxhighlight lang=apl inline>⍪</syntaxhighlight> || [[Table]]                  || [[Concatenate first axis]]
|-
| <syntaxhighlight lang=apl inline>↑</syntaxhighlight> || [[Take first]]            || [[Take]]
|-
| <syntaxhighlight lang=apl inline>↓</syntaxhighlight> || [[Drop first]]            || [[Drop]]
|-
| <syntaxhighlight lang=apl inline>?</syntaxhighlight> || [[Roll]]                  || [[Deal]]
|-
| <syntaxhighlight lang=apl inline>⌽</syntaxhighlight> || [[Reverse horizontally]]  || [[Rotate horizontally]]
|-
| <syntaxhighlight lang=apl inline>⊖</syntaxhighlight> || [[Reverse vertically]]    || [[Rotate vertically]]
|-
| <syntaxhighlight lang=apl inline>⍉</syntaxhighlight> || [[Transpose]]              || [[Transpose by axis]]
|-
| <syntaxhighlight lang=apl inline>∊</syntaxhighlight> ||                            || [[Member]]
|-
| <syntaxhighlight lang=apl inline>⍷</syntaxhighlight> ||                            || [[Find]]
|-
| <syntaxhighlight lang=apl inline>⍋</syntaxhighlight> || [[Grade up]]              ||
|-
| <syntaxhighlight lang=apl inline>⍒</syntaxhighlight> || [[Grade down]]            ||
|-
| <syntaxhighlight lang=apl inline>⫽</syntaxhighlight> ||                            || [[Replicate]]
|-
| <syntaxhighlight lang=apl inline>⍕</syntaxhighlight> || [[Format]]                ||
|-
| <syntaxhighlight lang=apl inline>⍎</syntaxhighlight> || Parse number              ||
|-
| <syntaxhighlight lang=apl inline>%</syntaxhighlight> ||                            || [[Case]]
|-
| <syntaxhighlight lang=apl inline>⊆</syntaxhighlight> || [[Nest]]                  || [[Partitioned enclose]]
|-
| <syntaxhighlight lang=apl inline>⊇</syntaxhighlight> ||                            || [[Select]]
|-
| <syntaxhighlight lang=apl inline>∩</syntaxhighlight> ||                            || [[Intersection]]
|-
| <syntaxhighlight lang=apl inline>⌸</syntaxhighlight> ||                            || [[Key]] (<syntaxhighlight lang=apl inline>{⍺⍵}⌸</syntaxhighlight> in Dyalog)
|-
| <syntaxhighlight lang=apl inline>∪</syntaxhighlight> ||                            || [[Union]]
|-
| <syntaxhighlight lang=apl inline>⊤</syntaxhighlight> ||                            || [[Decode]]
|-
| <syntaxhighlight lang=apl inline>⊥</syntaxhighlight> ||                            || [[Encode]]
|-
| <syntaxhighlight lang=apl inline>⌹</syntaxhighlight> || [[Matrix inverse]]        || [[Matrix division]]
|-
| <syntaxhighlight lang=apl inline>≡</syntaxhighlight> || [[Depth]]                  || [[Compare equal]]
|-
| <syntaxhighlight lang=apl inline>≢</syntaxhighlight> || [[Tally|Size of major axis]] || [[Compare not equals]]
|-
| <syntaxhighlight lang=apl inline>→</syntaxhighlight> || Return from a function    ||
|}
 
=== Operators ===
 
{|class=wikitable
! Syntax                                                !! Monadic                    !! Dyadic
|-
| <syntaxhighlight lang=apl inline>F¨</syntaxhighlight>  ||colspan=2| [[For each]]
|-
| <syntaxhighlight lang=apl inline>F/</syntaxhighlight>  || [[Reduce]]                || [[Windowed reduce]]
|-
| <syntaxhighlight lang=apl inline>F⌿</syntaxhighlight>  || [[Reduce leading axis]]    || [[Windowed reduce leading axis]]
|-
| <syntaxhighlight lang=apl inline>F⌻</syntaxhighlight><br/><syntaxhighlight lang=apl inline>•.F</syntaxhighlight>
                                                          |                            || [[Outer product]]
|-
| <syntaxhighlight lang=apl inline>F•G</syntaxhighlight> ||                            || [[Inner product]]
|-
| <syntaxhighlight lang=apl inline>F⍨</syntaxhighlight>  || [[Self|Duplicate]]        || [[Commute]]
|-
| <syntaxhighlight lang=apl inline>F⍣k</syntaxhighlight> ||colspan=2| [[Power operator]]
|-
| <syntaxhighlight lang=apl inline>F\</syntaxhighlight>  || [[Scan]]                  ||
|-
| <syntaxhighlight lang=apl inline>F⍀</syntaxhighlight>  || [[Scan first axis]]        ||
|-
| <syntaxhighlight lang=apl inline>F⍤k</syntaxhighlight> ||colspan=2| [[Rank operator]]
|-
| <syntaxhighlight lang=apl inline>F∵</syntaxhighlight>  ||colspan=2| Derive bitwise
|-
| <syntaxhighlight lang=apl inline>F∥</syntaxhighlight>  ||colspan=2| [[Parallel]]
|-
| <syntaxhighlight lang=apl inline>F˝</syntaxhighlight>  ||colspan=2| [[Inverse]]
|-
| <syntaxhighlight lang=apl inline>F∘G</syntaxhighlight> ||colspan=2| [[Withe|Compose]]
|-
| <syntaxhighlight lang=apl inline>F⍛G</syntaxhighlight> ||colspan=2| [[Inverse compose]]
|-
| <syntaxhighlight lang=apl inline>F⍥G</syntaxhighlight> ||colspan=2| [[Over]]
|-
| <syntaxhighlight lang=apl inline>F⍢G</syntaxhighlight> ||colspan=2| [[Structural under]]
|}
 
In addition to these, Kap uses the glyphs <syntaxhighlight lang=apl inline>«</syntaxhighlight> and <syntaxhighlight lang=apl inline>»</syntaxhighlight> to form [[Fork]]s. These are not operators, although they resemble them syntactically.
 
== External links ==
 
* [[Array Cast]] episode 72, [https://www.arraycast.com/episodes/episode72-kap Elias Mårtenson and the Kap array programming language]
 
== References ==
<references/>
{{APL dialects}}[[Category:APL dialects]][[Category:Nested array languages]][[Category:Languages with first-class functions]][[Category:Leading axis languages]]

Latest revision as of 11:53, 29 August 2024


Kap is an array-based language that aims to implement most of standard APL, along with additional features. Much of standard APL works in Kap, although if an APL feature does not fit with Kap's design, those features are changed or removed.

Lazy evaluation

The main difference compared to APL is that Kap is lazy-evaluated. This means that the language gives the developers very loose guarantees when (or if, and how many times) a function will actually be invoked. For example, ↑ f¨ ⍳10 will only make a single call to f because f¨ ⍳10 will not immediately evaluate the result but only return a delayed evaluation. Since all but the first result is then discarded, those results will never be computed.

Differences from APL

The following is a list of significant differences compared to APL:[1]

  • Lazy evaluation
  • First class functions
  • Bignum support and rational arithmetic
  • Ability to define custom syntax
  • Native hash table support
  • Parallel evaluation (to take advantage of multi-core CPU's)

Primitives

Functions

Glyph Monadic Dyadic
+ Conjugate Add
- Negate Subtract
× Angle (Signum) Multiply
÷ Reciprocal Divide
| Magnitude Mod
Power
Log
= Equals
Not equals
< Increase rank Less than
> Decrease rank Greater than
Less than or equal
Greater than or equal
Sort up Logical and
Sort down Logical or
Logical nand
Logical nor
Logical not Without
Square root Root
Floor Min
Ceiling Max
! Gamma Binomial
Shape Reshape
Index generator Index of
Identity Right
Hide Left
Index lookup
Enclose Partitioned enclose
Disclose Pick
, Ravel Concatenate
Table Concatenate first axis
Take first Take
Drop first Drop
? Roll Deal
Reverse horizontally Rotate horizontally
Reverse vertically Rotate vertically
Transpose Transpose by axis
Member
Find
Grade up
Grade down
Replicate
Format
Parse number
% Case
Nest Partitioned enclose
Select
Intersection
Key ({⍺⍵}⌸ in Dyalog)
Union
Decode
Encode
Matrix inverse Matrix division
Depth Compare equal
Size of major axis Compare not equals
Return from a function

Operators

Syntax Monadic Dyadic
For each
F/ Reduce Windowed reduce
F⌿ Reduce leading axis Windowed reduce leading axis
F⌻
•.F
Outer product
F•G Inner product
F⍨ Duplicate Commute
F⍣k Power operator
F\ Scan
F⍀ Scan first axis
F⍤k Rank operator
F∵ Derive bitwise
F∥ Parallel
Inverse
F∘G Compose
F⍛G Inverse compose
F⍥G Over
F⍢G Structural under

In addition to these, Kap uses the glyphs « and » to form Forks. These are not operators, although they resemble them syntactically.

External links

References

  1. Mårtenson, Elias. Kap for APL’ers. Unversioned. Retrieved 2023-08-13.
APL dialects [edit]
Maintained APL+WinAPL2APL64APL\ivApletteAprilCo-dfnsDyalog APLDyalog APL Visiondzaima/APLGNU APLKapNARS2000PometoTinyAPL
Historical A Programming LanguageA+ (A) ∙ APL#APL2CAPL\360APL/700APL\1130APL\3000APL.68000APL*PLUSAPL.jlAPL.SVAPLXExtended Dyalog APLIverson notationIVSYS/7090NARSngn/aplopenAPLOperators and FunctionsPATRowanSAXSHARP APLRationalized APLVisualAPL (APLNext) ∙ VS APLYork APL
Derivatives AHPLBQNCoSyELIGleeIIvyJJellyK (Goal, Klong, Q) ∙ KamilaLispLang5LilNialRADUiua
Overviews Comparison of APL dialectsTimeline of array languagesTimeline of influential array languagesFamily tree of array languages