User:Hotcrystal0/CAPI
we need to add like one command that does one thing on the list (like a commands that just prints itself) because this is an esolang
CAPI is an esolang created by User:Hotcrystal0, User:PrySigneToFry and User:I am islptng [add yourself if you’ve been invited]. It is designed to be crystal-complete, aweosme-complete, PrySigneToFry-complete Lv.2, and islp-complete Lv.2.
Basic data types
- Number: Fractions and roots. For example,
2/5 sqrt(2) + 1 - 2i
is a valid number.3.1415926
is also valid. - Byte: 8 bits of information.
- List: Literally a list.
- String: Quote between ` and '. Can be nested and multi-lined (\p for ` and \q for '). They're list of Bytes. Escapes are also work in C++.
- Document string: Quote between "'' and ''". Can be nested too (\\p\ for "'' and \\q\ for ''").
- String: Quote between ` and '. Can be nested and multi-lined (\p for ` and \q for '). They're list of Bytes. Escapes are also work in C++.
- Matrix: Literally matrices of Numbers.
- Lambda: A function.
- Type: A type.
- Nonetype: NULL, Undefined behaviour, and invalid type.
Syntax
Commands are separated by semicolons. Arguments are passed to a function after a single space and separated with commas(no parentheses are needed for function call(use parentheses are also OK, but we didn't recommend to do that)).
Parenthese expressions also works.
I/O
Output
print *args, **kwargs, sep <- `,', file <- `CON', end <- `\n';
Outputs a series of specified values to a specified file (CON is the STDOUT) followed by a terminator.
Input
input file <- `CON', prompt <- `'
Receives a line as string from a specified file, with specified input prompt. (CON is the STDIN)
Control Flow
Like C++, we uses braces. There is no "for" loop.
if code{ ...code... } while cond{ ...code... } if expr1{code1} else{code2} if expr1{code1} elif expr2{code2} elif... else{codeN}
Operators
Unlike most languages, ^ means exponent instead of bitwise XOR.
3 ^ 5 # 243, not 6
Variable
Declare a variable:
decl a;
Assign (Unlike most languages, equality is = and assign is <-):
a <- 1;
Declare and assign at the same time:
decl a <- 1;
To use a variable, just write its name.
a <- 4; print a;
Assign with nothing will delete the variable.
decl a <- 5; print a; a <-; print a; # Error!
Functions
Lambda function:
fun arg1,arg2,arg3...{ ...code... }
You can, of course, assign it to a variable. Recursion is supported.
decl fib <- fun a{return fib a-1+fib a-2}; print fib 4;
Override function is supported.
decl add <- fun a, b{return a + b}; add <- fun s1, s2{return concat s1, s2}; print add 5, 5; # 10 print add `Hello, ', `world!'; # `Hello, world!'
Class
Class definition:
class YourClassName { # attributes decl a <- 1 }{ # methods decl *init <- fun {#*initialization*#}; decl your_method_name <- fun *args, **kwargs{#*function body*#}; decl *add <- fun other{#*Define + operator*#}; }
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]
Comment
# This is a one-liner #* This is a multi-liner #* Can be nested! *# *#
Self-evaluating and Self-executing
exec code;
Predefined functions
type x
Evaluates to x's type.
conv x,t
Evaluates to the result of converting x to type t.
replace src,before,after
Evaluates to the result of replacing all "before" with "after" in src.
apgsearch n `k' `rule' `symmetry'
Runs apgsearch with the specified parameters. n is a number, while the others are strings.
swap x,y
Swap the value of x and y.
abs x
Absolute value of x.
Proof for the completes
crystal-complete
print `TRANS RIGHTS';
print `x = 23, y = 11, rule = B3/S23\n110bo$4bo3bo5bo3bo$3bobo11bobo$3bobo11bobo$2obobob9obobob2o$2obo15bob2o\n$3bo15bo$3bobo4bobo4bobo$4b2o4b2obo3b2o$13bo$13b2o!';
decl self<-`decl self<-`T';self<-replace self,`T',self;print self;';self<-replace self,`T',self;print self;
decl x <- 1103;
aweosme-complete
decl n <- 7;while n>1{ print n,` bottles of tommyaweosme on the wall ',n,` bottles of tommyaweosme take one down get +100 health',sep<-`'; print `one last bottle of tommyaweosme on the wall one final bottle of tommyaweosme walk away keep it up there let it ferment into greatness';
decl tommyaweosme<-fun n{ n<-(n+5)*2;while n>=10{n<-n-10;} if n=0{print 87;}else{ while 1{print 56;}}}
n<-1;while 1{t<-0;while t<n{print 56;}print 87;n<-n+1;}
PSTF-complete
Lv 1
print `問天地好在';
print `0.';n<-1;while 1{t<-0;while t<n{print 0;}print n;n<-n+1;}
from math import sin decl pstf <- fun x{m<-1;t<-1;while t<=x{m<-m*sin t^3+1;}return m;}
print ((conv input, num) + (conv input, num))
i<-99;while i>=0{print i;i<-i-1;}
print (6!=5);
print x; # replace x with any number you want
decl x <- 10; x <- 0;
decl n <- 1; decl f <- input; f <- conv f, num; decl s <- `n is even!'; while n<=f{if n%2=0{print replace s `n' n}else{print n} n <- n+1;}
Lv 2
import internet internet.connect; internet.access `www.example.com'; internet.disconnect;
islp-complete
Lv 1
Lv 2
Example program
Quine
import sys print sys.argV[0]
Get length of list
decl x <- []; decl d <- ` '; while d!=`'{d <- input; x.append d;} print x.length;
Sort list but don't modify
decl x <- [2, 4, 1, 3, 8, 5, 7, 6]; print x.sorted;
Every-base to decimal
decl b <- conv input, num; decl x <- input; print parseint x, b;
parseint
receives two or three arguments, one is a string, another is base(2≤base≤36 because it is case-insensitive, or base=0 to convert with prefix). If third argument is true then it becomes case-sensitive(thus 2≤base≤3664, last two characters are plus sign and equal sign). Leave blank is false.