DeltaLang

From Esolang
Jump to navigation Jump to search

DeltaLang is designed by PSTF. It is a formal programming language, roughly designed in Gödel's Incompleteness Theorems vs Programming Languages.

Note, the DeltaLang recorded here is version 2.0, and version 1.0 is almost like Python with semicolons and something modified.

Overview

Variables

For convenience, we usually use a single letter as a variable, but in Python, any valid identifier can be a valid identifier in DeltaLang (they can be used as variable names) (although the keywords of the two programming languages are different). Note that if two variable names are identical after NFC normalization, they will be considered the same variable name.

For example, these are valid identifiers:

pstf
k
ISOMORPHISM
k1
y____
你好
アイ
þ̶̷̸̧̨̛̣̥̦̈̉̊̋̌̏̒rift
u3u333u33333

While these are not:

1k # Error, identifier can't start with a digit
succ # Error, succ is used to return n+1 for every n∈Z
%u # Error, no special symbols allowed

Data types

  1. Numbers. All real numbers are valid 'number' types.
    • Integers. Any number that can be expressed without a decimal point or a slash (used to indicate a fraction) is an integer. Note that 1 and 1+0i are not the same thing.
    • Any 'number' that is not an integer is considered a floating-point number, regardless of whether it can be expressed in the form p/q or in the form shown in Figure 2-1.
      Figure 2-1
  2. Complex numbers. Any number that, when converted into an ordered pair, has a second component not equal to zero is a complex number. In other words, any number expressed as a + bi is a complex number. Note that i and 1i are not the same thing.
  3. Rune, A rune is enclosed in single quotes.
  4. List. Literally a list.
    • String. A string is enclosed in double quotes. A backslash represents an escape character. For example, "\"I know nothing except my own ignorance\" is a paradox." returns "I know nothing except my own ignorance" is a paradox..
      • Documents. A docstring begins with "'' and ends with ''". They are represented in character escape sequences as \\p\ and \\q\.
  5. Matrix. It is just a matrix of numbers, with elements in a row separated by commas and rows separated by line breaks.
  6. Lambdas. Simply put, it's basically a function, and it is defined with the following syntax: [parameterList] -> do code end. An isolated code block can be regarded as a lambda with no parameters.
  7. Ordered pairs. Ordered pairs follow the same arithmetic rules as complex numbers and are equivalent to the 'geometric' representation of complex numbers.
    • Key-value pairs. Key-value pairs are different from number pairs; the first value must be a string, while the second value does not have to be a number. It is expressed as 1st: 2nd rather than (1st, 2nd). In the following documents, we will call a list consisting entirely of key-value pairs a 'dictionary'.
  8. Type. A type itself is also a type.
  9. Unavailable values. Unavailable values include NULL and various erroneous expressions (for example, arcsin(2) or 5÷0).
  10. Boolean values. That is, true and false. Any empty element (including zero elements such as 0, 0.0, 0+0i, (0, 0), NULL, "": NULL, which are empty integer, empty float, empty complex number, empty number pair, empty value, empty key-value pair respectively) is equivalent to false; others are equivalent to true.

Basic Syntax

The most basic syntax is to follow the command with a space and then separate the actual parameters with commas to correspond to the formal parameters. The command must be a lambda (or, to put it more simply, a function). Parentheses expressions work as usual.

I/O

print arg_list, sep <- " ", file <- "CON" end <- "";

Outputs a series of specified values to a specified file (CON is the STDOUT) followed by a terminator.

input prompt <- "", file <- "CON";

Receives a line as string from a specified file, with specified input prompt. (CON is the STDIN)

Control Flow

if condition do {code} else {code} end
while condition do {code} end
repeat do {code} until condition end
for iterator in container do {code} end

Operators

Here I inherit the idea from CAPI rather than Python—the power operator is '^', bitwise XOR is '`', and logical XOR is 'xor'.

2 ^ (1/2) # It should return the value of the square root of 2,
          # which is approximately 1.4142135623730950488016887242097.

Variables and Constants

Here I was inspired by a series of programming languages from islptng and APL, using '←' to assign values to variables.

var a; # Declaration
a <- 1; # Assignment
var b <- 5.0; @ Declare + Assign
a <- # Abandon
print b # Usage

Class

Class definition:

class YourClassName
{
    # attributes
    decl a <- 1
}{
    # methods
    decl *init <- [self] -> do #*initialization*# end;
    decl your_method_name <- [self, *args, **kwargs] -> do #*function body*# end;
    decl *add <- [self, other] -> do #*Define + operator*# end;
}

To call a method, use a dot.

decl a <- [2,4,1,3];
a.sort;  # Built-in method of attribute "List"
print a; # [1,2,3,4]

Self-executing and Self-evaluating

eval x
exec x

Built-in Methods

typeof x # Type of x.
cast x, type # Convert x to the type and return the value but not assign to x.
replace src, before, after # Evaluates to the result of replacing all "before" with "after" in src.
succ x # Successor of x. Only when x ∈ Z.
swap x, y # Swap the value of x and y.
round x # Return x rounded but do not assign it.

Examples

Currently No.

Categories