Raymond

From Esolang
Jump to navigation Jump to search

Raymond is a programming language designed by PSTF.

It is designed to be Turing-Complete.

Overview

Raymond supports I/O, conditions, loops, subroutines, classes, and R&R.

Most Basic Things: Variable

There are 6 basic data types.

  • Algebraic expressions. They are essentially various numbers (an algebraic expression that does not contain any open variables or unknowns is called a constant). Letters are used as identifiers, and we use μ as the identifier for an unknown (derived from the Greek word for 'secret'). We define μ24 as x, μ1 as a, μ1_ as uppercase A, με1 as the Greek letter α, με1_ as uppercase Greek letter Α, and so on. When used as a type identifier, it is denoted as ②.
  • String. Enclosed in double or single quotes. The backslash can be used as an escape character. Denoted as Š.
    • Document. Enclosed in triple quotes, without using backslashes for escaping.
  • Boolean. Either true or false, which is represented by ! and ¡. Denoted as ⍜.
  • Lambda. Denoted as Λ.
  • List. A list can store any number of any elements (including none, and including another list). It is represented by □.
  • Pair. Just simply (a, b). Represented by ⌒.
    • Complex numbers. As special pairs of numbers, complex numbers have their own unique operations—check Xonovile yourself, because Raymond is a remake of Xonovile. Represented by Ⓘ.
  • Type. Just type. Represented by Ⓩ.

In addition, we also have the following types:

  • Everything. All types are its subsets. Represented by ✝.
  • Nothing. It's the subset of all types. Represented by ○.
  • Port. Connect to a specified port, such as standard output.

To define a variable, we use this:

name@type ← value

You can also omit the type when the variable is already defined, or assign with another type to change its type. You can use ⌗x to get the type of x.

I/O

We have reserved some symbols as built-in variables and built-in constants, such as ⎕, which represents standard output and standard input.

If we assign a variable with a port, it means that to get things from the port to the variable.

If we assign a port with a variable, it means that to send things to the port by the variable.

So, we have this program:

⎕ ← ⎕

This means to output what inputted.

Arithmetic

A plus sign means addition, append or concatenate.

  • For x + y,
    • If both x and y are numbers, they're added together.
    • If x is list and y is another element(must be string literal if x is string literal), it means to concatenate y to the tail of x.
    • If both x and y are ordered pairs, let x = (a1, b1) and y = (a2, b2), then x + y = (a1 + a2, b1 + b2). Also suitable for if both x and y are complex numbers(Real numbers can be treated as complex numbers that has an imaginary part of 0. Complex numbers are formed by a + bi, where 1i is not equal to i).

A subtraction dash means subtraction. It only exist when both x and y are numbers, ordered pairs, or complex numbers.

A "×" means multiplication.

  • For x × y,
    • If both x and y are numbers, the result is multiply x by y.
    • If x is list/string literal and y is number, x is repeated for y times.
    • If both x and y are ordered pairs, let x = (a, b) and y = (c, d), then x × y = (ac - bd, bc - ad). Also suitable for if both x and y are complex numbers.

A "÷" means float division. Only exist when both x and y are numbers, ordered pairs, or complex numbers. If x = (a, b) and y = (c, d) then x ÷ y = ((ac + bd) ÷ (c² + d²), (bc - ad) ÷ (c² + d²)) where (c, d) ≠ (0, 0).

A slash means truncated division. It first get the result of x ÷ y, then round it towards 0. Use backslash for modulo.

An ASCII-circumflex means exponent.

  • For x ^ y,
    • If y can be represented by a ÷ b,
      • If b is even, then for x which is below 0, return √|x| · i.
    • If y is 0, then ignore x and return 1.
    • If x is complex number that can be represented by a + bi, let r = a² + b², and convert x into r(cos(θ) + i sin(θ)) where θ = tan-1(b ÷ a), return rn(cos(nθ) + i sin(nθ)).

y√x is the shorthand of x^(1 ÷ y). If y = 0 then return NaN, represented by ⍬.

log_y(x) returns k if yk = x.

A list is represented by elements wrapped in bracket and seperated by comma.

Control Flow

〖I am a comment. The interpreter will not notice me.〗
b?a:c 〖If b is true, evaluates in a, otherwise c.〗
(b)↘{a}↖ 〖Do a until b is not true.〗
[i∈c]`{a} 〖Do a for every i in c.〗
∗label_name: 〖Define label.〗
⇱label_name 〖Goto label.〗
〖From left to right, ∧∨¬⊻ means AND, OR, NOT and XOR.〗
〖a∈A returns if x is the lement of 𝔸, and A⊂B returns if 𝔸 is a subset to 𝔹.
⌈x⌉ is round x away from 0 and ⌊x⌋ is round x towards 0. _[[x]]_ is round as usual. .|x|. is absolute value.

= is equal, ≠ is not equal, < is below, ≤ is not above, > is above, ≥ is not below.〗

Data manipulations

Xιn means to return nth element(count up from 0 but -1 means last and -2 is second-to-last and so on) from the X. If n ≥ X.length or n < -X.length then return error. We try to avoid using Latin letters as commands whenever possible.

⍰𝕏 means to grab out a random element from 𝕏. ℂ, ℕ, ℚ, ℝ, and ℤ are reserved for Complex numbers, Natural numbers, Rational numbers, Real numbers, and Integers. Do not convert them into numbers. If you really did that, ℝ*, ℤ and ℚ will return ℵ0, ℝ is ℵ1 and ℂ is ℵ2. ℵ0 is used as infinity and has a short hand of ℵ0 or even just ∞.

ρabc will generate a range with the start value of a(including), end value of b(including if c can divide b else excluding) and a step of c.

“XXX” is a string. Use ⎋ as escaping, such as ⎋“ is “ and ⎋n is newline. ⎋⎋ means the character ⎋.

〖〖〖XXX〗〗〗 is a document that didn't support ⎋ as escaping but is multi-lined.

(XXX)#{$k} is a number in base k. If k is below 1 or above 64, throw an error. Base-1(or Marchal, or maybe Unotial) is just to count how many zeroes are there in the parentheses and reduce the value by 1.

Σ𝕏 means to sum up all elements in 𝕏. If 𝕏 is a list of string literals, concatenate them together according to the real index instead of dictionary-style order.

∪ represents joining two lists together and removing duplicate elements (keeping only one) to form a new list, while ∩ represents forming a list of elements that are common to both lists. For example,

A: 1 2 3 4 5 6
B: 1 3 5 7 9 11
A∪B: 1 2 3 4 5 6 7 9 11
A∩B: 1 3 5

∅ is an empty list. Note: ∅ = [], but ∅ ≠ [∅].

Lambda Definition and Usage

To define a function, we use λarg_list.{code_block}. Code blocks can also be seen as lambda expressions, except that they are not defined and have no parameters. Two commands are separated by a newline or a semicolon. Very similar to Lambda calculus(To be verified), isn't it?

To use a function, we assign it to a variable then use var_name(arg_list).

Example

No.

Categories