x(y)

From Esolang
Jump to navigation Jump to search

X(y) is a language created by User:A for a simpler form of Function x(y).

Syntax

To start a function:

x()

Or:

x(y)

Or it can have as many arguments as you like:

x(a b c d e f g)

To do math (must use spaces before and after the operator used) (+, -, *, or /, here + is shown), and there are only infix operators:

a + b

Math in X(y) is BEDMAS by default, but you can also uses parentheses for grouping, so the following:

a + b * c

would evaluate to a + (b * c), but for (a + b) * c:

(a + b) * c

To do comparison (must use spaces before and after the operator used) (<, >, <=, =>, ==, or !=, here == is shown):

a == b

Ternary (spaces allowed before/after the { or }):

condition{valueIfTrue valueIfFalse}

To call a function:

x()

Or:

x(y)

Or with as many arguments as the function takes:

x(a b c d e f g)

To call a function recursively:

{y}

To return (default return value is 0):

-> a

Examples

Hello, World!

helloWorld() -> "Hello, World!"

Cat

cat(x) -> x

Absolute value function

abs(n) -> (n < 0){0 - n n}

Factorial function

factorial(n)
-> (n < 2){1 n * {n - 1}}

FizzBuzz

/ is integer divison.

main(n)
-> (n != 100){((fizz(n) + buzz(n)) == ''){[n] [fizz(n) + buzz(n)]} {n + 1} ["Fizz
"]}

fizz(n)
-> ((n / 3) * 3 == n )<"Fizz", "">

buzz(n)
-> ((n / 5) * 5 == n)<"Buzz", "">

Fibonacci sequence

fib(acc, num) -> fib(num, num + acc)