User:PrySigneToFry/Sandbox/Draft of AGPL

From Esolang
Jump to navigation Jump to search

AGPL(A golfing programming language) is designed by PSTF.

Overview

AGPL is mostly inspired by APL, is designed for golfing.

Data types

  1. Numbers. Every valid real numbers are number type, even if in complex. 1i is not equal to i. ①
  2. Strings. Strings are quoted in "", \" for " and \\ for \, every escapes are work in C++. Ⓐ
  3. Arrays. They're quoted in [], and seperate with comma. ●
  4. Booleans. True or False. ※
  5. Lambdas. They're simple functions. Return value is ŕ. Code block is quoted in {} and seperate with semicolon. ★

Assignment

To assign a value to an unused variable, or assign a new value to a variable, you write this:

var ← value

Or, you can also assign with types:

var ← type

You can also assign in array index:

array[index] ← value

Index is start from 1.

Arithmetics

Addition

The addition sign is +.

Number + Number

Add two number up will get their sum. For example, 1 + 1 should get 2.

Array/String + any other type

Append the element into the tail of array.

Array + array, or string + string

Join arr2 or str2 to the tail of str1 or arr1.

Boolean + other

False will be treat as 0, true is 1.

Subtraction

The subtraction sign is -.

Number - Number

Subtract the two numbers and get their difference.

String/Array - Number

Delete last x things from the array.

Boolean - Other

Same as above.

String - String/Array - Array

This is illegal.

Multiplication

The multiplication sign is ×.

Number × Number

Returns the product of two numbers.

Array/String × Number

Repeat the array x times. For example, [2, 3] × 3 should get [2, 3, 2, 3, 2, 3, 2, 3, 2, 3].

Division

The division sign is ÷.

Number ÷ Number

Directly return the result of dividing two numbers by real numbers. If only the quotient is required, use a slash; If only the remainder is required, μ is used.

Exponent

The exponent sign is *.

Number * number

If first number is x, and second is y, return xy.

Natural logarithm

The natural logarithm sign is ł. You can use l / <TAB> to input it.

ł Number

Get ln(x).

loga(x)

You write ł(x)÷ł(a) to get it. Also, you can write log ← {ŕ ← ł(x)÷ł(a)}.

It is not for only math!

Some compact between APL and AGPL

STDOUT&STDIN

An empty quad(⎕) is STDOUT or STDIN. Assign it to variable means to input the variable. Assign it with value means output the value.

!

This is factorial sign. It gets the factorial of the operand before operator, such as 5! is 120.

?

This is "roll" sign. In AGPL, it receives two operands(?x, y), then get the random number between x and y.

Conditionals