Txlyre's website

Main page


My contacts


Valkyrja programming language


SyMAL CAS (Symbolic Math Array Language)


Pixels!


Állánë constructed language (Állánë álya)


Ugushian constructed language (Ùgùcskò mòwa / Ўугўушко мова)


Aliose constructed language (Aliose ingua)


Denáth constructed language


valkyrja logo

valkyrja programming language

Valkyrja is a K-inspired tacit array-based programming language.

Samples

/ Hello world
sayln "Hello, world!"

/ Hello world variant II
"Hello, world!"

/ Factorial
fac:{*/1+!x}

/ Sort
sort:{x@<x}

/ Calculate Nth fibonacci number
fibn:{:[x<2;1;it(x-1)+it(x-2)]}

/ Calculate fibonacci numbers
fib:{fibn'!x}


Brainfuck interpreter
Program that prints the 99 Bottles of Beer song lyrics

Downloads

The newest available version is 0.7α0602.
You can find it here.

Reference (0.7α0602)

Syntax

/ starts a line comment (should be prefollowed with one or more spaces/tabs);
a:1 is an assignment;
f:{x+y+z} defines a function. Functions can be anonymous. Functions can have up to three arguments: x, y, z; or don't have them at all (function takes no arguments called nillad);
it {:[x=0;1;x*it x-1]} reference to the current function;
1 1`000`000 0xff 0b1011 0o231 integer;
1.0 1. .1 float;
1 0 boolean;
`"a" character;
"hello" "a\nb\nc" string;
`s symbol;
` empty symbol;
nil nil;
1 2 3 [1;2;3] 1, 2, 3 vector;
[1 2 3;4 5 6] matrix;
[] empty vector;
`[[`key;"value"];[`key2;6]] dictionary;
:[cond1;clause1;cond2;clause2;...;condN;clauseN(;else)] condition;
:{expr1;expr2;...;exprN} block;
{x+y} {6} {x+1} function;
{x} 5 {x+y}(5;5) 5 {x+y} 5 application;
+ - # verb;
-5 5+5 verb application;
{x+y}(5;) *(;2) partial application;
3{x+1}/3 adverb.

Verbs

+ monadic flip. transpose a matrix.
+ dyadic plus. add numbers together.
- monadic negate. swap the sign.
- dyadic minus. substraction.
* monadic first. first element of vector x.
* dyadic times. multiplication.
% monadic reciprocal. divide 1 by x.
% dyadic divide. division.
| monadic reverse. reverse order of a vector.
| dyadic max/or. for numbers: larger one of x and y, for booleans: x or y.
& monadic where. &0 0 1 0 3 yields 2;4,4,4.
& dyadic min/and. for numbers: smaller one of x and y, for booleans: x and y.
^ monadic shape. #elts at each depth.
^ dyadic power. raise x to the exponent y.
! monadic enumerate/eval. for integers: build range from 0 to x (inclusive); for dictionaries: yield list of keys in dict x; for strings: evaluate string x as an expression.
! dyadic remainder. remainder of x and y.
< monadic grade-up. indices of vector sorted ascending.
< dyadic less. is x less than y.
> monadic grade-down. indices of vector sorted descending.
> dyadic more. is x greater than y.
= monadic group/values. for vectors: =3 4 3 4 4 yields <0;2>;<1;3,4>, for dictionaries: yield list of values in dict x.
= dyadic equals. is x equals to y.
~ monadic not. logical negation of x.
~ dyadic match. is x equals to y, type-intolerant, atomic.
@ monadic atom. is x an atom?
@ dyadic at/range. if x is vector: element at index y from vector x; if x is dictionary: get key y; if x is function: apply x to y; if x is integer: yield a range of integers from x to y.
# monadic size. for vectors and strings: length of x, for characters: ASCII-code of x
# dyadic take. if x is integer: repeat y for x times; for vectors: take element by index from matrix, eg. [1 2 3;3 4 6]#0 1 yields 2, if y is integer: fill y elements from x.
, monadic enlist. put x into a 1-element vector.
, dyadic join. join two vectors into one.
_ monadic floor. tolerant floor of x.
_ dyadic drop/chunk. remove y elements from vector x or split vector y into x chunks.
? monadic unique. for integers: convert int x into char; for vectors: distinct elements from vector x
? dyadic find/sample/deal/try. if x is function: apply x to y and check for errors, on error yield 1;message otherwise 0;result; if x is integer: yields x random elements from vector y, for integers: yields x random integers < y, if y is vector: yields index of y in vector x; for dictionaries: yields value of entry y in the dictionary x.
$ monadic format. cast x to string.
$ dyadic form. cast x to type of y; if x is string and y is a symbol `x, convert hexadecimal number x to integer.
|: monadic empty. yields true if x is empty or nil.
~: dyadic regmatch. match regex (GNU) x against string y.
?: dyadic regfind. find all occurences of regex (GNU) x in string y; yields list of pairs: start;end of substrings.
$: dyadic regextract. extract all occurences of regex (GNU) x in string y; yields list of substrings.
: dyadic S bind. bind symbol x to y.
:: dyadic S bindlocal. bind symbol x to y locally.
+: dyadic S bind plus. x:x+y.
-: dyadic S bind minus. x:x-y.
*: dyadic S bind times. x:x*y.
%: dyadic S bind divide. x:x%y.
,: dyadic S bind join. x:x,y.
_: dyadic S bind drop. x:x_y.
@: dyadic S bind item. eg. x:!3;[email protected]:5 0 yields 5;1,2; 4 4 [email protected]:4 2 yields 4;4,4; `[email protected]: in order to not modify x
#: dyadic S bind item in depth. eg. x:[1 2 3;4 5 6];x#:1337 1 0 yields <1;2,3>;<1337;5,6>; `x#: in order to not modify x

Adverbs

/ dyadic over. fold the vector y with x. eg. +/1 2 3 yields 6.
/ triadic while/iterate. if x is number: apply y to z x times, if x is function: apply y to z while x evaluates to true. eg. {x<10}{x+1}/3 yields 10.
/: dyadic until. apply until fixed-point is reached (y = x y)
\: dyadic scan-until. apply until fixed-point is reached collecting all intermediate results.
<: triadic each-left.
>: triadic each-right. eg. 2#>:["x";"y";"z"] take each right.
\ dyadic scan. fold the vector y with x collecting all intermediate results. eg. +\1 2 3 yields 1;3,6.
\ triadic scan-iterate. apply y to z x times collecting all intermediate results.
' dyadic each. apply x to each element of y. eg. !'1 2 3 yields <0>;<0;1>,<0;1,2>.
' triadic each. eg. "abc",'"def" join each.
': dyadic each-pair. pairwise apply x to each element of y.

Builtins

say monadic write x to the stdout.
sayln monadic write x and a newline to the stdout.
jsn monadic parse JSON string x.
jsr monadic represent x as a JSON string (serialize).
iota monadic yield a range of integers between 1 and x (inclusive)
type monadic reveal type of x. -1 unknown; 0 nil; 1 []; 2 integer; 3 string; 4 char; 5 symbol; 6 float; 7 dict; 8 vector; 9 builtin; 10 reference; 11 void; 12 nilad; 13 monad; 14 dyad; 15 triad; 16 verb.
exit monadic exit with code x.
time monadic yield current timestamp.
succ monadic yield x + 1.
pred monadic yield x - 1.
flat monadic flatten vector x.
fac monadic yield !x (factorial).
fib monadic yield xth fibonacci number.
fun.q monadic is x function?
hget monadic send a HTTP GET-request to the URL specified by x; yields vector: response-code;response-body; if x is symbol, http-scheme will be appended.
repr monadic represent x as a string. e.g. repr 1 2 3 yields "1;2,3"
input monadic print prompt x and read input string from input, pass empty symbol to disable the prompt.
use monadic read and eval code from file x or load an external shared library.
get monadic read file x.
line monadic read single line from file x.
close monadic close file x.
slurp monadic read file contents by filename x.
open dyadic open file x in mode y (r, w or both).
put dyadic write string y to file x.
save dyadic write y to file by filename x.
add dyadic append string y to file x.
in dyadic is vector y contains x?
split dyadic split vector y by index x.
shape dyadic reshape vector y to shape specified by x.
ltrim dyadic strip substring y from left side of string x.
rtrim dyadic strip substring y from right side of string x.
trim dyadic strip substring y from both sides of string x.
do dyadic if x is integer: execute function y x times; if x is function: execute function y while x evaluates to true.
rotate dyadic rotate vector y by x.
explode dyadic split string x by string y.
cut dyadic split string x by regex y.
join dyadic join string x by string y.
filter dyadic filter vector y with predicate x.
date dyadic format timestamp y to format x.
getc niladic read a character from input.
args atom list of command line arguments.
stdin atom standard input port.
stdout atom standard output port.
stderr atom standard error output port.
va.v atom version of the interpreter.
va.vn atom version number of the interpreter.
va.b atom build of the interpreter.
va.h atom host-system of the interpreter: win64; win32; osx; linux; unix; posix
pi atom π number
tau atom τ number
e atom e number

Valib

Valib allows to write native libraries for Valkyrja in C language.
Sample:

// lib.c

#include "vae.h"

FUNDEF(add)
  if (type(x) == NUM_T && type(y) == NUM_T)
    return mknum(fromnum(x) + fromnum(y));
  else if (type(x) == INT_T && type(y) == INT_T)
    return mkint(fromint(x) + fromint(y));
  else ERROR("type error");
}

Value _pi15;

VARSET(pi15, _pi15);

INIT {
  // Called before library is initialized.
  _pi15 = mknum(3.1415 / 1.5);
}

EXPORT(2) {
  FUN("add", DYAD, add),
  VAR("pi1.5", pi15)
};

Compiling:
$ cc -shared -fPIC lib.c -o lib.so
Using:
    use`lib
2
    add(1;2)
3
    add(1.;1.5)
2.5
    add(1;1.5)
|type error
|   add
    pi1.5
2.09433333333333