function x(y)

From Esolang
Jump to navigation Jump to search

function x(y) is a language created by User:PythonshellDebugwindow.

Datatypes

function x(y) uses strings (example: "Hello World") and integers (example: 123 or -456).

Syntax

To start a function:

function x()

Or:

function x(y)

Or it can have as many arguments as you like:

function x(a, b, c, d, e, f, g)

Default values:

function f(requiredParameter, optionalParameter | defaultValue)

To print with a newline:

[a]

To print without a newline:

`a

To get user input:

[~]

To get a live user input character:

`~

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

a + b

Math in function x(y) uses BDMAS (shortened version of 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 (no spaces 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

To create a variable inside a function:

var v: a

To access that variable:

v

To set that variable:

v; a

To use compound assignment (+=, -=, *=, and /= in C, but in function x(y) +&, -&, *&, and /& respectively, here +& is shown):

v +& a

Comment until End of Line:

#Comment
someCode # Comment

Execution

Execution starts at the first function in the program, which is passed no arguments.

Examples

Hello, World!

function helloWorld()
["Hello, World!"]

Cat

function cat()
[[~]]

Absolute value function

function abs(n)
-> (n < 0)<0 - n, n>

Factorial function

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

FizzBuzz

function fizzbuzz(n | 0)
(n != 100)<((fizz(n) + buzz(n)) == "")<[n], printAndRecurse(n)>

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

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

function printAndRecurse(n)
[fizz(n) + buzz(n)]
fizzbuzz(n + 1)

Fibonacci sequence

function fib(acc | 0, num | 1)
[num]
-> fib(num, num + acc)