Txlyre's website

Main page


My contacts


Marmelade programming language (my most featured project)


Têhhlrúrzhál constructed language (Têhhlrúrzsá hálye)


Nyol-ya constructed language


Aliosmo alt-history


Marmelade programming language

Marmelade - is a tacit, array-based, semi-functional programming language inspired by K, J, APL and A+

Examples

/ Hello world
sayln "Hello, world!"

/ Calculate factorial number
fac : { [n] product range[1;n] }
sayln fac 5 / -> 120

/ Calculate Nth fibonacci number
fibn : { [n] :[n<2;1;_f[n-1]+_f[n-2]] }

/ Calculate fibonacci numbers
fib : { [n] fibn'range[1;n] }

/ Sort list
sort : { [a] a[<a] }
/ Sort list descending
sortd : { [a] a[>a] }


More complex examples
Fully working interpreter for the brainfuck
Program that prints the 99 bottles song lyrics


Downloads

You can find latest builds here.
At the moment available only Windows builds, but the m0.0.5+ must be working under Wine.



Quick reference

Syntax
/ starts a comment. Must begin a line or have a space before.
a:1 is assignment
a::1 is global assignment (works in functions)
a+:1 is like a+=1.
a-: negates a in place.
a[]:1 sets all the entries of a to 1
a[0]:1 sets the 0th entry of a to 1
a[0;1]+:2 increments the 0th entry's 1st entry by 2
.[a;();+;1] returns a+1 but does not affect a on the environment
.[`a;();+;1] updates a in place, returns `a

@[a;b;c;d] is .[a;,b;c;d]
a:1 is .[`a;();:;1]
a+:1 is .[`a;();+;1]
a-: is .[`a;();-:]
a[]:1 is .[`a;_n;:;1]
a[0]:1 is .[`a;0;:;1] or .[`a;,0;:;1]
a[0;1]+:2 is .[`a;0 1;+;2]

@[a;b;:] and .[a;b;:] are error handlers

f:{[a;b;c] a+b+c} defines a function. f[1;2;3] yields 6
Functions may be anonymous.
Functions may have default arguments x,y,z.
So {x^2} 3 conveniently yields 9
Datatypes -4 -3 -2 -1 0 1 2 3 4 5 6 7
'type' reveals type, type 1 2 3 yields -1
-4 vector symbol `a`b`c or ,`a
-3 vector character(string) "abc" or ,"c"
-2 vector float 1.0 2.0 3.33 or ,1.0
-1 vector integer 1 2 3 or ,1
0 list general (`a;1 2 3) or (`a;(1 2 3;(3 4;"c")))
1 integer 1
2 float 1.0
3 character "c"
4 symbol `s
5 dictionary .((`a;10;);(`b;20;)) or .() or .,(`a;5;)
6 nil nil or _n
7 verbs/functions + +: {1+x} +[1;] (|+) {[a;b]1+a+b} {x+y}[1;]
Empty Lists:
-4 0#`
-3 ""
-2 0#0.0
-1 !0
0 ()
0N null integer
0n null float
-0I infinity integer negative
0I infinity integer positive
-0i infinity float negative
0i infinity float positive
Create empty dictionary d:.()
Start by making a dictionary d[`k]:4
d[] values
!d keys
d[`k] value at k
d@`k value at k

:[x1;t1;x2;t2;...;xn;tn;else] evaluate xi until true and return ti, otherwise return else. :[0;10;0;20;1;30;40] yields 30
if[x;e1;...;en] if x then evaluate all e. if[j>i;a:1;b:2]
do[m;e1;...;en] do all e m times. do[100;f[i];i+:1]
while[x;e1;...;en] while x do e. while[a>b; f a; a-:1]

Most important of stdlib
use x - Include a Marmelade code file named x
sayln x - Print x and a trailing newline to stdout
say x - Print x to stdout
input x - Print prompt x, and reads line fron stdin
get x - Read file x
put[x;y] - Write y to file x
eval x - Evaluate x as Marmelade expression and return result
tostr x - Cast x to string
toint x - Parse x as integer
tonum x - Parse x as float
tosymb x - Convert x to symbol
gett x - Get current time in format specified by x
getft[] - Get current time in format "YYYY-MM-DD HH:MM:SS"
error x - Invoke user error x
join[l;g] - Join list l with glue g
split[s;d] - Split string s by d
exec x - Execute shell command x
rand[x;y] - Random number in range between x and y(inclusive)
randr x - Random number between 0 and x
chr x - Convert ASCII char code to char
ord x - Get char ASCII code
_getenv `x - Get environment variable x
_setenv[`x;y] - Set environment variable x to value y
len x - Length of x. len (3;4;5) yields 3
reverse x - Reverse x. reverse range[1;3] yields 3 2 1
range[x;y] - Build list of ints from x to y(inclusive)
repr x - Returns string representation of x
last x - Returns last elements in list x
elementat[x;y] - Return Yth element from list x
cat[x;y] - Cast x and y to strings and concatenate them
_a - Command line arguments as list
Values
Integers/floats

m> 5
5
m> 5.5
5.5
m> 5.999999
5.999999
m> 5.9999999   / Note that Marmelade will attempt to ceil any float
6.0   (!!!!)
String/chars
m> "a"
"a"
m> "Hello"   / Strings internally represented as list of chars
"Hello"
Lists/vectors(matrixes)
m> 1 2 3  / List(lists are represented as 1D-vector)
1 2 3
m> (1;2;3)  / List too
1 2 3
m> 1,2,3  / List
1 2 3
m> !10  / Creates list using monadic operator "!"
0 1 2 3 4 5 6 7 8 9
m> (1 2 3;4 5 6)   / 2D-vector(matrix)
(1 2 3
4 5 6)
Verbs(operators)
+ monadic flip. transpose a matrix (a depth-2 list)
+ dyadic plus. add numbers together
- monadic negate. invert sign
- dyadic minus. subtraction
* monadic first. first element from the list
* dyadic times. multiply two numbers
% monadic reciprocal. 1 over x
% dyadic divide. x divided by y (not mod)
| monadic reverse. reverse order of list
| dyadic max/or. MAX(x,y) or OR(x,y)
& monadic where. &0 0 1 0 3 yields 2 4 4 4.
& dyadic min/and. MIN(x,y) or AND(x,y)
^ monadic shape. #elts at each depth (min over)
^ dyadic power. x to the exponent y
! monadic enumerate. !4 yields 0 1 2 3
! dyadic mod/rotate. 5!3 yields 2; 1 ! 4 5 6 yields 5 6 4
< monadic grade up. indices of list sorted ascending
< dyadic less. boolean is x less than y
> monadic grade down. indices of list sorted descending
> dyadic more. boolean is x greater than y
= monadic group. =3 4 3 4 4 yields (0 2;1 3 4)
= dyadic equals. 1 2 3 = 1 2 4 yields 1 1 0 (tolerantly)
~ monadic not. ~ 0 1 0 2 0 yields 1 0 1 0 1
~ dyadic match. 1 2 ~ 1 2 yields 1 (types must match)
@ monadic atom. boolean is arg an atom (as opposed to a list)
@ dyadic at. elts from x at indices y
@ triadic monadic amend.
@ tetradic dyadic amend.
? monadic unique. distinct elts from a list
? dyadic draw. n?m yields n numbers < m
? dyadic deal. -n?m yields n ints < m without replacement
? dyadic sample. n?y yields n random elements from list y (-n for no replacement)
? dyadic find. x?y yields index of y in list x (or #x)
? dyadic invert. {x^2} ? 2 yields sqrt(2)
? triadic invert-guess. secant method with clues
_ monadic floor. tolerant floor function
_ dyadic drop/cut. lose x elts from list y / separate into pieces
, monadic enlist. put x inside a 1-element list
, dyadic join. "ab","cd" yields "abcd"
# monadic count. number of elements in list
# dyadic take/reshape. fill x elts from y
$ monadic format. cast to string
$ dyadic form/format. cast
. monadic eval/make dictionary. ."1+1" yields 2
. dyadic value. 1 2 3 . ,2 yields 3.
. triadic monadic amend.
. tetradic dyadic amend.
: overloaded with many operations.
Over and scan behave differently depending on whether their left argument is monadic or dyadic.
/ over dyad +/1 2 3 or 4+/1 2 3 */1+!5 / Calculate factorial number of 5
\ scan dyad +\3 4 5 or 6+\3 4 5 *\10#2
/ over monad apply until fixed f/x (%%[;2.0])/9999.0
/ over monad apply n times n f/x 4 (2+)/0
/ over monad apply while true b f/x {x<10} {x+1}/ 3
\ scan monad trace until repeat f\x (1!)\1 2 3 4
\ scan monad trace n times n f\x 10(|+\)\1 1
/ over {x+y+z}/[1 2 3;4;7 8 9] f/[x;y;z]
\ scan {x+y+z}\[1 2 3;4;7 8 9] f\\[x;y;z]
/ join ","/("a";"b")
\ split ","\"a,b"
' each "abc" ,' "def" join each
' each !:' 2 3 4 enumerate each
/: eachright #:/:(2;2 2;2 2 2) count each right
/: eachright 2 #/: ("x";"y";"z;) take each right
\: eachleft 0 1 2 3 #\: "abc" take each left
': eachpair apply pairwise -':1 3 4 8 10