return()zero
- The title of this article is not correct because of technical limitations. The correct title is actually return()->0.
return()->0 is a language that returns a value for everything you do.
Data types
Strings: "Hello!", "", "1234", etc.
Any non-empty string is treated as true or 1, and any empty string is treated as false or 0. Characters of a string can be accessed in the same way elements of a list can. If possible, the character selected will be converted to an integer. For example, "asdf1234"[5]
would return 1
and "asdf1234"[1]
would return "a"
Integers: -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, etc.
Any value that is greater than 0 is treated as true or 1, and any value that is less than or equal to zero is treated as false or 0.
Lists: [0,1,2], [[1,2],[3,4],1], etc.
A list can contain integers, strings, and/or lists. If the list is used in the context of a condition, the elements in the list are summed and evaluated in the same way an integer is.
Syntax
Order of Operations
()
can be used to specify order of operations. Everything else is done left to right. For example:
2+3*4 evaluates to 20
2+(3*4) evaluates to 14
Boolean Logic
!
returns the opposite of the following value. For example, !1
returns 0
.
|
returns 1
if one or more of the values before or after it are 1
. For example, 1|0
returns 1
, 1|1
returns 1
, and 0|0
returns 0
.
^
returns 1
if one of the values before or after it are 1
. For example, 1^0
returns 1
, 1^1
returns 0
, and 0^0
returns 0
.
&
returns 1
if both of the values before or after it are 1
. For example, 1&1
returns 1
, 1&0
returns 0
, and 0&0
returns 0
. If the value before it is 0, the value after it is not calculated. For example, 0&function()
will not run function
.
Integer Logic
==
returns 1
if the both of the values before or after it are equal. For example, 2==2
returns 1
, -2==-2
returns 1
, and 1==0
returns 0
. This is the only integer logic operator that also works with lists and strings.
<
returns 1
if the value before it is smaller than the value after it. For example, 1<2
returns 1
, 2<1
returns 0
, and 1<1
returns 0
.
>
returns 1
if the value before it is larger than the value after it. For example, 2>1
returns 1
, 1>2
returns 0
, and 1>1
returns 0
.
Operations
+
Returns the sum of the values before and after it.
-
Returns the difference of the values before and after it.
*
Returns the product of the values before and after it.
/
Returns the integer quotient (5/3
evaluates to 1
) of the values before and after it.
%
Returns the remainder of the division of the values before and after it.
$
Returns the power of the values before and after it.
ax=b
is a shorthand that expands to a=axb
, where x
is an operation and a
and b
are values.
Comments
Any characters following whitespace will be treated as a comment up to the next @
character.
Variables
Variables are both defined and re-assigned using the =
(equals) symbol. When defining a variable, it returns the value the variable was set to. When re-assigning a variable, it returns the new value of the variable.
Lists
Elements of a list can be accessed with the [
and ]
characters surrounding the index (1-based) of the list element. For example, a[4]
can be used to access the 2 in a=[0,3,1,2,5,4]
. To add to a list, +=
followed by the element to add can be used. To remove elements from the end of a list, -=
followed by the number of elements to remove can be used.
Loops
The only loop available in return()->0 is a while loop. The syntax for a while loop is:
while(condition){optional_index_variable};code;
A while loop will repeat the code
until the condition
is false. The optional_index_variable
starts at 1 and increments by 1 every time the code
repeats. It can be used in the code
, but not outside of the while loop. If the brackets and variable name are omitted, this variable will not be used.
A while loop will return the evaluation of the condition
when the first loop starts.
Functions
The syntax for a function is:
:function_name(function_arguments)->return_type:code::((return_value))
A function will run the code
when called. Any variable names defined in the function_arguments
can be used in the code
as a variable, but not outside of the function. The return_type
and return_value
must match. The return_type
is included to make it easier to read the language.
The return_type
can be any of the following:
1 Integer
A function can be called using the following syntax:
[] List
"" Stringfunction_name(function_arguments)
A function will return its return_type
when defined.
IO
The function write()
will write output to the terminal and return the output.
The function read()
will read input from the terminal and return it.
Example programs
Hello World
write("Hello World!")
write("ASDFJKL;") Note that "ASDFJKL;" will not be outputted since a newline is considered whitespace.
Cat Program
i=read()&write(i)
Truth Machine
i=read() note that a non-empty string is always treated as true @|(i[1]==1&while(1==1);write(1);)|write(0)
Fibonacci
The &
character can be used to separate statements, as shown in this example:
!:fibo(upto)->[]:!fibos=[]&a=1&b=1&!c=0&while(a<upto);c=a&a+=b&b=c&fibos+=a;::((fibos))&write(fibo(20))
Fibonacci Rewritten
!:fibo(upto)->[]:
|--@!fibos=[]
|--@&a=1
|--@&b=1
|--@&!c=0
|--@&while(a<upto);
|----@c=a
|----@&a+=b
|----@&b=c
|----@&fibos+=a
|--@;
@::((fibos))
@&write(fibo(20))
Leap Year
:isLeap(y)->1:r=(1&!(!(y%400==0)&(y%100==0))&(y%4==0))::((r))
Implementations
This language currently has no implementations.