-
Notifications
You must be signed in to change notification settings - Fork 139
Verbs Classification
gitonthescene edited this page Dec 14, 2021
·
5 revisions
Verbs in K — that's what operations in imperative languages are. When you add two numbers in Python, you use an operation "+" (plus).
Python 3.2 (r32:88445, Apr 15 2011, 11:09:05)
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 12 + 23
35
Verbs in K serve the same purpose.
K Console - Enter \ for help
12 + 23
35
Yeah, it's too simple, I agree 😄 . But wait! While verbs are similar to operators, they have some distinctions:
- verbs in K have one-symbol length! Here is the full list:
~!@#$%^&*-_=+|.<>
. Every symbol has its own meaning. The one difficulty is to remember all purposes… - verbs can be used in two modes — prefix and infix. Prefix usage is called "monadic", infix — "dyadic". One verb can have different meanings in monadic and dyadic usages.
- though syntax seems complicated, semantic is rudimentary when you know the classification. Almost all verbs can be divided into 4 groups by method of data modification:
- Generative verbs — they create data
- Modifying verbs — they make changes to data and do not change data length
- Transforming verbs — they modify data, change shape, replace with other data
- Reflection verbs — take a look on data, examine shape, result of operation is only one data item
Almost all the features and all K verbs have analogues in other languages, but only in APL-based they have 1-char-long syntax. This saves time for "parse-interpret" process.
-
!
monadic — enumerate -
#
dyadicn#m
— fill
-
+
dyadic — add -
*
dyadic — multiply -
%
monadic, dyadic — divide -
-
monadic, dyadic — subtract -
|
monadic, dyadic — reverse, MAX/or -
&
diadic — AND/min -
^
diadic — power -
~
monadic — not -
!
dyadic — mod/rotate -
<
dyadic — less -
>
dyadic — greater -
=
dyadic — equal -
_
monadic — floor
-
+
monadic — transpose -
&
monadic — where -
=
monadic — group -
<
monadic — grade up -
>
monadic — grade down -
?
monadic — unique -
,
dyadic — join -
_
dyadic — cut lower/reshape -
#
dyadicn#y
— fill by list -
#
dyadicn#y
, length of y > n — cut upper
-
*
monadic — take first -
#
monadic — count -
^
monadic — shape -
~
dyadic — full equal -
@
monadic, dyadic — atom/at -
,
monadic — create one item list -
.
dyadic — value at -
?
dyadicx?n
version — find