Vyxal

From Esolang
Jump to navigation Jump to search
Vyxal
Paradigm(s) imperative
Designed by User:Lyxal
Appeared in 2020
Memory system Stack based
Dimensions One dimensional
Computational class Turing complete
Major implementations Official
Influenced by Fish, Keg, 05AB1E, Jelly, Husk
File extension(s) .vy

Vyxal is the latest addition to the plethora of stack-based languages used for code golfing. But unlike its competitors, Vyxal has a special focus upon readability and elegancy. Indeed, the codepage has been specially chosen to be as mnemonic as possible. Further, constructs from practical languages (such as functions, lambdas and easy list manipulation) are present.

(Vyxal is pronounced Vikesal)

How to use the interpreter:

python3 Vyxal.py <file> <flags (single string of flags)> <input(s)>

For a list of command-line flags: python3 Vyxal.py h

Data Types

There are 4 data types supported by Vyxal:

  • Numbers (integers and reals/floats)
  • Strings
  • Lists
  • Generators

Basic Operators

  • +-*/% perform addition, subtraction, multiplication, division and modulo respectively.
  • , prints the top of the stack
  • :_ duplicates the top of the stack and pops the top of the stack respectively
  • ! pushes the length of the stack

Syntax Constructs

If statements

[truthy_branch|falsey_branch]
[truthy_branch]

The if statement pops the top of the stack, and if it is truthy, executes the truthy branch. Otherwise, if a falsey branch is present, it will branch to execute that.

For loop

(variable|body)
(body)

The for loop pops the top of the stack and iterates through each item. If the value popped is an integer, it loops through the range [0, n). If variable is present, the iteration value is stored in that. Otherwise, the iteration value is stored in the context variable n.

While loop

{condition|body}
{body}

The while loop repeats body until condition evaluates as true. If there is no explicit condition, 1 is used as the condition, meaning that {...} is an infinite loop.

Functions

@name|code;
@name:number_of_arguments|code;
@name:variable|code;
@name:argument_list|code;
@name;

If code isn't present, the function with name name is called. Otherwise, the function is defined. The arguments can be a combination of variables and numbers. Numbers tell the function how many items to pop from the main stack as arguments, and variables store a single value in the variable. Numbered arguments are pushed to the function's stack -- functions operate on their own scoped stack with scoped variables (much like Python).

For example:

@triple:1|3*;

Takes 1 parameter and pushes it to the function's stack

@triple:value|←value 3*;

Takes a single argument and stores it in variable value.

@add_and_halve:1:rhs|←rhs +2/;

Takes two arguments: pushes the first onto the stack and stores the second in variable rhs

@average:*|W:L$∑$/;

Takes however many arguments as defined by the first value popped from the stack. A function call of 2 3 3 3 @average; would take three arguments.

Lambdas

λarity|code;
λcode;

Where the @...; function stores the definition for infinite re-use, the lambda pushes a reference to the code inside it. This is similar to python's lambdas, which are temporary functions, or literal functions (for lack of a better word).

These can be applied using . For example: 3 λ3*; ⍎ will result in 9. Lambdas are also useful for mapping/filtering/reducing a vector according to the lambda's code.

Implicit input and output

  • At the end of program execution (EOF), if nothing has been printed (using , or other printing commands), the top value on the stack is automatically printed.
  • If there aren't enough values on the stack to perform an operation, implicit input is taken. If input is passed through command line arguments, then the input used is cycled.
  • Input can be either through arguments or STDIN. STDIN is used if arguments aren't avaliable. If no input is avaliable at all, 0 is returned.
  • In functions (and lambdas), if implicit input is needed, the argument(s) passed are used as the input "list".

Commands

Vyxal has so many commands, each with overloads, that it is impractical to list them all here. Here is the reference page

Examples

Hello, World!

`Hello, World!`

Try it Online!

`ƈṡ, ƛ€!

Try it Online!

The above program uses dictionary compression: words in a predefined list are indexed using a subjective base-162 literal.

kH

Try it Online!

Fizzbuzz

₁ƛ₍₃₅kF½*∑⟇

Try it Online! Explanation

Prime Checking

æ

Try it Online!

KL2=

Try it Online!

Links