Levy
Paradigm(s) | imperative |
---|---|
Designed by | Wolfram Xenakis |
Appeared in | 2024 |
Memory system | Variable-based |
Dimensions | one-dimensional |
Computational class | Turing complete |
Reference implementation | Unimplemented |
File extension(s) | .levy |
Levy is an array-based programming language created by Wolfram Xenakis. It is mainly a derivative of APL with some more traditional flow control integration as well as some unique functions. It is not much of an esolang, but it's still very unusual due to it's lineage. It currently has no compiler.
Basic Features
Comments, Input and Output
Comments are made with ◻.
·/ 1 2 3 ◻ THIS IS A COMMENT
Output is handled with ⚲.
⚲ + 17 13 Output: 30
Input is handled with ⫰. ⫰ can also write a prompt to the screen.
a ⊧ ⫰ 'Enter your number: '
Assignment
Assignment is done with ⊧. It takes the assigned value on the right, and the variable it has been assigned to on the left. You can re-assign variables.
a ⊧ 24 ◻ first assignment, a is created a ⊧ 33 ◻ second assignment, a is changed to be 33 ⚲ a Output: 33
Functions
Functions are almost always monadic or dyadic (1 or 2 inputs), but there are also a few triadic functions. Levy uses Postfix notation. Levy uses generic function variables. Every function is of the form
f α/φ β/ψ γ/θ
where α,β,γ are variables or φ,ψ,θ are functions. Each of the three inputs may be one or the other. These variables are the names to be used where defining a function. To define the procedure for a function, put the procedure in curly braces. If there is an evaluation that is left unassigned, it is treated as the return value.
f ⊧ {+ α β} ◻ declare a function with two inputs. returns the sum of the two inputs. ⚲ f 1 2 ◻ print the sum of 1 and 2 Output: 3
Flow Control
Flow control is available in if/else, while and for loops. For an if loop, simply put the condition, then a colon, then the resulting procedure in curly braces.
f ⊧ { = α 0: { ◻on the condition that α is zero 1 ◻ return 1 } ♭ α ◻ return α-1 }
As you may notice, curly braces are what deliminates a procedure. For a while loop, the idea is similar, but a delta symbol is put instead of a colon.
f ⊧ { x ⊧ 0 ◻ declare a variable x in the function > α 0 Δ{ ◻ while α is greater than zero α ⊧ ♭ α ◻ subtract one from α x ⊧ ♯ a ◻ add one to x } }
And finally, a for loop takes in each element of an array and does something to it. It is done by writing Φ, then the array, then the assigned name to each element of the array, and finally a semicolon.
Φ ι10 x: { ◻ for x in [1 2 3 4 5 6 7 8 9 10] ⚲ x ◻ print x }
Types and Type Conversion
Types are usually not necessary in Levy, but if wanted are available.
Types
- Boolean: Shown with 𝔹, takes on two values: True (⊤) and False (⊥). Conditionals return this type.
- Integer: Shown with ℤ, takes on any whole value.
- Real: Shown with ℝ, a standard floating-point.
- Complex: Shown with ℂ, a standard complex number.
- Character: Shown with 𝕊, stores a single character.
Note that declaring a variable to be of a single type locks it into being of that type. An untyped variable may take on various types.
Type Conversion
A strict type may be converted to any other type.
⚲ 12.3 Output: 12.3 ⚲ ℤ 12.3 Output: 12.3
Arrays, Dimensions and Indexing
An array is a list of other variables, including other arrays. Arrays are written with brackets, and with spaces between entries.
x ⊧ [1 2 3] ◻ create an array with elements 1, 2 and 3
An array can contain multiple data types at once.
x ⊧ [1 2 'a']
An array containing only other arrays makes it a higher-dimension array.
x ⊧ [[1 2] [3 4]] ◻ essentially acts as a matrix.
The amount of nesting gives you the dimension.
It is possible to index an array. Arrays are 1-indexed.
[4 3 2 1][1] ◻ gives 4 [[1 2] [3 4]][1,2] ◻ gives 2
Arrays of a certain variable type can be shown with 𝔸 followed by the only allowed data type. The more 𝔸's the higher the dimension.
ℤ x ⊧ 1 ◻ single integer 𝔸ℤ x ⊧ [1 5] ◻ array of integers 𝔸𝔸ℤ x ⊧ [[1 5] [2 3]] ◻ array of array of integers
Built-in Functions
Levy has useful pre-made functions that are mostly taken from APL. THIS IS A WORK IN PROGRESS. PLEASE WAIT UNTIL I HAVE TIME TO ADD THINGS.