Labra

From Esolang
Jump to navigation Jump to search

Labra is an esoteric programming language created by User:DoggyDogWhirl.

"Labra" stands for "LAzy BRAckets", as it uses lazy evaluation and uses only brackets () [] {} <> as symbols.

Overview

As previously mentioned, the only symbols used are ()[]{}<>. This means that Labra code may look similar to code in Brain-Flak or BracketsLang. Like those languages, all brackets in Labra code must be matched. Unlike them, Labra uses the newline \n to separate sections of code. Also, Brain-Flak is stack-based, BracketsLang is cell-based, and Labra is neither. (I think it's declarative. I don't know.)

Labra uses two data types, integers and lists. Lists may be infinite, and may contain other lists. Labra uses 0-indexing.

Input and output are a list of numbers. ASCII is not used; "23" as input gives 23, and outputting 23 shows "23". Labra prints out the result of the last line, and the results of any OUTPUTs it finds along the way.

In Labra, a set of brackets may have a result inside and/or a result to its left, or neither. The arguments a set of brackets has determines its function.

Functions
Arguments ( ) [ ] { } < >
Niladic
_()
ONE
Returns 1.
() → 1
ZERO
Returns 0.
[] → 0
ARGUMENT
Input, or argument into function.
{} → input
PREVIOUS
The result of the previous line.
()
<> → 1
Monadic
_(X)
SUM
Sum of X.
(1,2) → 3
INDICES
The list of numbers up to X or the length of X.
[3,5,0] → 0, 1, 2
REPEAT
The infinite list of only Xs.
{1} → 1, 1, 1, 1, ...
CALL
The result of line X.
()
<0> → 1
Applied
A()
ADD ONE
Adds/appends 1.
2() → 3
ENCLOSE
Puts A in a list.
5[] → 5,
OUTPUT
Prints A.
1{} → 1
INVERT
-A. If list, swaps indexes and items.
4,2<> → ?, ?, 1, ?, 0
Dyadic
A(X)
ADD
Adds/appends X.
2(3,1) → 2, 3, 1
INDUCTION
The infinite list of X solved repeatedly.
{} is initially set to A.
1[{}()] → 1, 1+1, (1+1)+1, ...
MAP
Solves X for every element of A.
{} is set to elements of A.
2,3,4{{}()} → 2+1, 3+1, 4+1
INDEX
Gets the Xth element of A.
5,5,1<2> → 1

Examples

2

Outputs 2.

()()

Cat program

{}

Truth-machine

{}
{{}}
<{}>

Hello, world!

Prints the ASCII values.

[][{}()()()()()()()()()()()()]   0,12,24,...
<[]><()()()()()()>               H
<[]><()()()()()()()()>()()()()() e
<>()()()()()()(){}               ll  #The l OUTPUTted is the one printed first
<>()()()                         o
<[]><()()()>()()()()()()()()     ,
<[]><()()>()()()()()()()()
<()()()()>()()()()()()()()       w
<()()()()>                       o
<()()()()>()()()                 r
<[]><()()()()()()()()()>()()()   l
<[]><()()()()()()()>()()()()()   d
<()()()()()()>()                 !
<[<()><()>]{{}()}>

Anything that isn't a bracket or newline is a comment.

Fibonacci sequence

()[]()[{}<()>[](({}))]{{}<[]>}
()[]()                          1,1
      [
       {}<()>[]                   1,
               (({}))             1,(1+1)
                     ]         [1,1],[1,2],[2,3],...
                      {{}<[]>}  1,    1,    2,   ...

Implementation

I made a Haskell implementation, but it can't OUTPUT. It can be found here.

I tried to make Python implementation using iterators, but it activates every OUTPUT, can't CALL, and is buggy in general.

At this rate I might have to learn a new language to actually implement it in...