Primitives: Difference between revisions

From The K Language Wiki
Content added Content deleted
m ('has' is not in k9 anymore)
("Widen scope of language category")
 
(21 intermediate revisions by 2 users not shown)
Line 4: Line 4:


== Verbs ==
== Verbs ==
Single argument forms(monadic) listed first, two-argument forms(dyadic) listed second.


=== Operator Verbs ===
Empty cells indicate that the primitives are the same as K4-K6.

Operator verbs use the following characters: <code>: + - * % ! &amp; &#124; &lt; &gt; = ~ , ^ # _ $ ? @ .</code>.

Suffixing a verb with <code>:</code> forces it to be interpreted as monadic.

[[Monadic]] forms (one argument) are listed first, [[dyadic]] forms (two arguments) are listed second.

Empty cells indicate that the primitives in the given dialect are the same as in K4-K6.

{| class="wikitable"
{| class="wikitable"
|+ Table of Primitives in major dialects
|+ Table of operator verbs in major dialects
|-
|-
! rowspan=2|
! rowspan=2|
! colspan="2" |K3!! colspan="2" |K4-K6 !! colspan="2" |K9
! colspan="2" |[[K3]]!! colspan="2" |[[K4]],[[K5]],[[K6]] !! colspan="2" |[[K9]]<sup>*</sup>
|-
|-
!monad
!monad
Line 17: Line 25:
! monad!!dyad!!monad!!dyad
! monad!!dyad!!monad!!dyad
|-
|-
| <code>:</code>
| <code>:</code>
|
|
| || [[right|identity]] || [[right]] || ||
| || [[right|identity]] || [[right]] || ||
|-
|-
| <code>+</code>
| <code>+</code>
|
|
| || [[transpose]] || [[add]] || [[transpose]]||[[add]]
| || [[transpose]] || [[add]] || [[transpose]]||[[add]]
|-
|-
| <code>-</code>
| <code>-</code>
|
|
| || [[negate]] || [[subtract]] || [[negate]]||[[subtract]]
| || [[negate]] || [[subtract]] || [[negate]]||[[subtract]]
|-
|-
| <code>*</code>
| <code>*</code>
|
|
| || [[first]] || [[multiply]] || [[first]]||[[multiply]]
| || [[first]] || [[multiply]] || [[first]]||[[multiply]]
|-
|-
| <code>%</code>
| <code>%</code>
|[[reciprocal]]
| [[reciprocal]]
| || [[square root]] || [[divide]] || ||[[divide]]
| || [[square root]] || [[divide]] || ||[[divide]]
|-
|-
| <code>!</code>
| <code>!</code>
|
|
| || [[enum]], [[odometer]], [[keys]] || [[mod]], [[create dict]] || [[enum]] ([[odometer]]), [[keys]]||[[create dict]]
| [[rotate]], [[mod]] || [[enum]], [[odometer]], [[keys]] || [[mod]], [[create dict]] || [[enum]] ([[odometer]]), [[keys]]||[[create dict]]
|-
|-
| <code>&amp;</code>
| <code>&amp;</code>
|
|
| || [[where]] || [[min]] || [[where]]||[[min]]
| || [[where]] || [[min]] || [[where]]||[[min]]
Line 57: Line 65:
| || [[grade down]]|| [[greater]] || [[Grade down|descending]]||[[greater]]
| || [[grade down]]|| [[greater]] || [[Grade down|descending]]||[[greater]]
|-
|-
| <code>=</code>
| <code>=</code>
|
|
| || [[group]], [[identity matrix]] || [[equal]] || [[group]]||[[equal]]
| || [[group]], [[identity matrix]] || [[equal]] || [[group]]||[[equal]]
|-
|-
| <code>~</code>
| <code>~</code>
|
|
| || [[not]] || [[match]] || [[not]]||[[match]]
| || [[not]] || [[match]] || [[not]]||[[match]]
|-
|-
| <code>,</code>
| <code>,</code>
|
|
| || [[enlist]] || [[concatenate]] || [[enlist]]||[[concatenate]]
| || [[enlist]] || [[concatenate]] || [[enlist]]||[[concatenate]]
|-
|-
| <code>^</code>
| <code>^</code>
|[[shape]]
|[[shape]]
|[[power]]|| [[null?]] || [[except]], [[fill]] || [[sort]] || [[cut]]
|[[power]]|| [[null?]] || [[except]], [[fill]] || [[sort]] || [[cut]]
|-
|-
| <code>#</code>
| <code>#</code>
|
|
| || [[length]] || [[take]], [[reshape]]|| [[count]]|| [[filter]], [[take]]
| || [[length]] || [[take]], [[reshape]]|| [[count]]|| [[filter]], [[take]]
|-
|-
| <code>_</code>
| <code>_</code>
|
|
| || [[floor]], [[lowercase]] || [[drop]], [[delete]], [[cut]] || [[floor]]|| [[Filter|filter-out]], [[drop]]
| || [[floor]], [[lowercase]] || [[drop]], [[delete]], [[cut]] || [[floor]]|| [[Filter|filter-out]], [[drop]]
|-
|-
| <code>$</code>
| <code>$</code>
|
|
| || [[string]] || [[pad]], [[cast]] || [[string]]||[[parse]]
| || [[string]] || [[pad]], [[cast]] || [[string]]||[[parse]]
|-
|-
| <code>?</code>
| <code>?</code>
|
|
| || [[distinct]], [[random-float]] || [[find]], [[random]] || [[unique]]||[[find]], [[random]] (with floats)
| || [[distinct]], [[random-float]] || [[find]], [[random]] || [[unique]]||[[find]], [[random]]
|-
|-
| <code>@</code>
| <code>@</code>
|[[Type|atom?]]
|[[Type|atom?]]
| || [[type]] || [[at]] || [[type]]|| [[cast]]
| || [[type]] || [[at]] || [[type]]|| [[cast]]
|-
|-
| <code>.</code>
| <code>.</code>
|
|
| || [[eval]], [[values]] || [[dot]] || [[eval]]||[[dot]]
| || [[eval]], [[values]] || [[dot]] || [[eval]]||[[dot]]
|}
|}

=== Special Forms ===

{| class="wikitable"
|+Table of special forms
!
!Polyadic Name
|-
|<code>@</code>
|[[amend]]
|-
|<code>.</code>
|[[deep amend]], [[try]]
|-
|<code>$</code>
|[[if]]
|-
|<code>!</code>
|[[update]] (K4/qdb)
|-
|<code>?</code>
|[[splice]]
|-
|<code>?</code>
|[[select]] (K4/qdb)
|}

=== Named Verbs ===

{| class="wikitable"
{| class="wikitable"
|+Table of named primitives based on implementation
|+Table of named verbs in various implementations
!
!
!oK
![[OK|oK]]
!K7
![[K7]]
![[K9]]<sup>*</sup>
!K9
|-
|-
|utility
|utility
Line 111: Line 148:
|math
|math
| [[sin]] [[cos]] [[exp]] [[log]]
| [[sin]] [[cos]] [[exp]] [[log]]
| [[sqrt]] [[sin]] [[cos]] [[abs]] [n][[log]] [n][[exp]] [n][[rand]]
| [[sqrt]] [[sin]] [[cos]] [[abs]] [[log]] [[exp]] [[rand]]
|[[sin]] [[cos]] [[log]] [[div]](`i) [[exp]] [[sqr]] [[sqrt]] [[Dot product|dot]] [[bar]] [[deltas]] [[sum]] [[sums]] [[rand]]
|[[sin]] [[cos]] [[log]] [[div]] [[exp]] [[sqr]] [[sqrt]] [[Dot product|dot]] [[bar]] [[deltas]] [[sum]] [[sums]] [[rand]]
|-
|-
|stats
|stats
Line 119: Line 156:
|[[count]] [[first]] [[last]] [[avg]] [[med]] [[mode]] [[var]] [[mavg]] [[msum]]
|[[count]] [[first]] [[last]] [[avg]] [[med]] [[mode]] [[var]] [[mavg]] [[msum]]
|-
|-
|table(K7+)
|table([[K7]]+)
|
|
|[[asc]] [[dsc]] [[key]]
|[[asc]] [[dsc]] [[key]]
|[[top]] [[key]] [[unkey]] [[meta]]
|[[top]] [[key]] [[unkey]] [[meta]]
|-
|-
Line 127: Line 164:
|
|
|[[min]] [[max]] [[asc]]
|[[min]] [[max]] [[asc]]
|[[min]] [[max]] [[countd]]?
|[[min]] [[max]] [[countd]]
|}
|}


==Adverbs ==
== Adverbs ==

Adverbs use the characters <code>'</code>, <code>/</code> and <code>\</code> for their syntax.

They are primitives that take [[Verb|general verbs]] as arguments. As such they are higher order functions.


{| class="wikitable"
{| class="wikitable"
|-
|-
! !! K3-K6!! K9
! !! [[K3]],[[K4]],[[K5]],[[K6]]!! [[K9]]<sup>*</sup>
|-
|-
| <code>'</code>|| [[each]] | [[binary search]] ||[[Each|each]] | [[binary search]]
| <code>'</code>|| [[each]] | [[binary search]]<sup>*</sup><sup>*</sup> ||[[Each|each]] | [[binary search]]<sup>*</sup><sup>*</sup>
|-
|-
| <code>/</code>|| [[over]] | [[fixedpoint]] | [[for]] | [[while]] | [[join]] | [[base encode]]||[[over]] | [[join]] | [[base encode]]
| <code>/</code>|| [[over]] | [[fixedpoint]] | [[for]] | [[while]] | [[join]]<sup>*</sup><sup>*</sup> | [[base encode]]||[[over]] | [[join]]<sup>*</sup><sup>*</sup> | [[base encode]]
|-
|-
|<code>\</code>|| [[scan]] | [[scan-fixedpoint]] | [[scan-for]] | [[scan-while]] | [[split]] | [[base decode]]||[[scan]] | [[split]] | [[base decode]]
|<code>\</code>|| [[scan]] | [[scan-fixedpoint]] | [[scan-for]] | [[scan-while]] | [[split]]<sup>*</sup><sup>*</sup> | [[base decode]]||[[scan]] | [[split]]<sup>*</sup><sup>*</sup> | [[base decode]]
|-
|-
|<code>':</code>||[[each prior]] | [[windows]]||[[each prior]]
|<code>':</code>||[[each prior]] | [[windows]]||[[each prior]]
Line 148: Line 189:
|<code>\:</code>||[[each left]]||[[each left]]
|<code>\:</code>||[[each left]]||[[each left]]
|}
|}

== Remarks ==

'''<sup>*</sup>''': K9 is a nascent dialect which is still currently undergoing changes. Some pages may not be up to date with the latest build, and some are intentionally left unwritten in case of later changes.

'''<sup>*</sup><sup>*</sup>''': The primitives [[base encode]], [[base decode]], [[binary search]], [[join]] and [[split]] are verbs in the adverb syntax space. They are distinguished by argument type.

[[Category:Verbs]]
[[Category:Adverbs]]
[[Category:Primitives]]
[[Category:Language]]

Latest revision as of 08:14, 9 July 2022

K's primitives are designed to fit a large range of diverse functionality within the ASCII character set. This makes it typable on a keyboard, while keeping the language expressive and interesting to use.

All of K's primitives are made to be multipurpose, and have varied meanings based on the context they are used in. Symbol primitives can be either 1 or 2 characters long.

Verbs[edit]

Operator Verbs[edit]

Operator verbs use the following characters: : + - * % ! & | < > = ~ , ^ # _ $ ? @ ..

Suffixing a verb with : forces it to be interpreted as monadic.

Monadic forms (one argument) are listed first, dyadic forms (two arguments) are listed second.

Empty cells indicate that the primitives in the given dialect are the same as in K4-K6.

Table of operator verbs in major dialects
K3 K4,K5,K6 K9*
monad dyad monad dyad monad dyad
: identity right
+ transpose add transpose add
- negate subtract negate subtract
* first multiply first multiply
% reciprocal square root divide divide
! rotate, mod enum, odometer, keys mod, create dict enum (odometer), keys create dict
& where min where min
| reverse max reverse max
< grade up lesser ascending lesser
> grade down greater descending greater
= group, identity matrix equal group equal
~ not match not match
, enlist concatenate enlist concatenate
^ shape power null? except, fill sort cut
# length take, reshape count filter, take
_ floor, lowercase drop, delete, cut floor filter-out, drop
$ string pad, cast string parse
? distinct, random-float find, random unique find, random
@ atom? type at type cast
. eval, values dot eval dot

Special Forms[edit]

Table of special forms
Polyadic Name
@ amend
. deep amend, try
$ if
! update (K4/qdb)
? splice
? select (K4/qdb)

Named Verbs[edit]

Table of named verbs in various implementations
oK K7 K9*
utility in prm in within bin like find freq prm cmb in bin within prm freq cmb
math sin cos exp log sqrt sin cos abs log exp rand sin cos log div exp sqr sqrt dot bar deltas sum sums rand
stats count first last min max sum avg var dev med count first last avg med mode var mavg msum
table(K7+) asc dsc key top key unkey meta
misc min max asc min max countd

Adverbs[edit]

Adverbs use the characters ', / and \ for their syntax.

They are primitives that take general verbs as arguments. As such they are higher order functions.

K3,K4,K5,K6 K9*
' each | binary search** each | binary search**
/ over | fixedpoint | for | while | join** | base encode over | join** | base encode
\ scan | scan-fixedpoint | scan-for | scan-while | split** | base decode scan | split** | base decode
': each prior | windows each prior
/: each right each right
\: each left each left

Remarks[edit]

*: K9 is a nascent dialect which is still currently undergoing changes. Some pages may not be up to date with the latest build, and some are intentionally left unwritten in case of later changes.

**: The primitives base encode, base decode, binary search, join and split are verbs in the adverb syntax space. They are distinguished by argument type.