User:JiminP

From Esolang
Jump to navigation Jump to search

Hello, esolangs!

I'm interested in following languages:

CoLa : Computer Language

CoLa is a programming language, which aims minimal code length like GolfScript does.

Encoding

All CoLa source code must be written in UTF-16 (LE preferred), and no Unicode character having character code >= 0xD800 and control characters are permitted.

Data Formats

There are four types of data, numbers, strings, lists, and functions.

Numbers

There are two kinds of numbers, integers and floats. Integers (must) have arbitrary-precision, and floats are (may be) binary128 as defined in IEEE 754.

"Number as integer" represents floor(number). (floor(0.6) = 0, floor(-0.1) = -1)

"Number as string" represents a string which Unicode character is abs(floor(number)).

"Number as list" represents a list which only element is the number.

"Number as function" represents a function which set the number as the value of the memory.

Strings

Strings are actually list of integers, which represents Unicode character of strings.

"String as number" represents an integer S[0] + S[1]*256 + S[2]*65536 + ....

"String as function" represents a function which puts the number to the array.

Lists

Lists have arbitrary-length, and it may contains numbers, strings, and other lists.

Recursions are permitted, if it's possible.

"Lists as string" represents a string, which all the elements are joined (consider all elements as string), except when recursion is happened (in this case, the empty string should be returned).

"Lists as number" represents the length of the list (int).

"Lists as function" represents a function which set the list as the value of the memory.

Functions

Functions are... functions.

"Functions as string" represents the code of the function if it is user-defined, the name of the function otherwise.

"Functions as list" represents "(Functions as string) as list".

"Functions as number" represents the length of "Functions as string" (int).

Basic Syntax

CoLa provides you a memory that can save anything, 24 stacks ('Α'(0391) ~ 'Ψ'(03A8)) and a queue ('Ω'(03A9)) (these 25 storages are called 'arrays'). At the beginning, a number 0 is pushed in all arrays, and stack 'Α' is selected. In the memory, the integer 42 is stored.

Let's call 'dequeue' as 'pop', and 'enqueue' as 'push', for convenience.

Basically, all CoLa syntax are functions (or nearly a function). For example, literals are actually functions pushing a literal to an array.

Functions

If a function can't pop a thing from an array, then the result behavior is undefined.

  • 'Α'(0391) ~ 'Ω'(03A9) selects the array it represents, and use it as the current array.
  • 'c' pops a thing from an array as an integer, and don't execute the next function if the thing is 0.
  • 'C' pops two things from an array, and don't execute the (second thing as function) if the (first thing as integer) is 0.
  • 'd' pops a thing from an array, and push it twice to the array.
  • 'e' pops a thing from an array as a function, and execute it.
  • 'f' pops a thing from an array, convert it to the float, and pushes it to the array.
  • 'F' pops a thing from an array, convert it to the function, and pushes it to the array.
  • 'I' pops a thing from an array, convert it to the integer, and pushes it to the array.
  • 'l' pushes the length of an array (int) to the array.
  • 'L' pushes something in the memory to the array.
  • 'n' pops a thing from an array, prints it as a number, and pushes it (original) to the array.
  • 'N' pops a thing from an array, convert it to the number, and pushes it to the array.
  • 'q' quits current user-defined function.
  • 'Q' quits the program.
  • 'r' pops a thing from an array (as a list), and push all elements of the thing (in order).
  • 'R' pops all things from an array until it's length becomes 0, make a list consist of those things (in order), then push it in the array.
  • 's' pops a thing from an array, prints it as a string, and pushes it (original) to the array.
  • 'S' pops a thing from an array, then save it to the memory.
  • 'T' pops a thing from an array, convert it to the string, and pushes it to the array.
  • 'w' prints a (platform-dependent) newline character.
  • 'x' pops two things from an array, pushes first thing to the array, then push second thing to the array.
  • 'X' pops a thing from an array, then throw it away.
  • 'y' pushes ((user's input considered as an integer) considered as a string) to the array.
  • 'Y' pushes (user's input considered as a string) to the array.
  • 'z' pushes (user's input considered as an integer) to the array.
  • 'Z' pushes ((users's input considered as an string) considered as an integer) to the array.
  • ' '(20) does nothing.
  • '`'(60) pushes the next function to the array. (The next function is not executed.)
  • '_' truncates the array.
  • '!' pops a thing from an array as an integer, and pushes 1 (integer) to the array if the thing is 0, 0 (integer) if otherwise.
  • '=' pops two things from an array, and pushes 1 (integer) to the array if two things are exactly same, or 0 (integer) to the array if two things aren't same.
  • '~' pops two things from an array, and
    • If two things are all list, then
      • if length of two things are same, and str(i th element of first) = str(i th element of second) for all i, pushes 1 (integer) to the array, else pushes 0 (integer) to the array.
    • Else, pushes 1 (integer) to the array if str(first) = str(second), or 0 (integer) to the array if it isn't.
  • '+', '-', '*', '/' pops two thing from an array, do following operations ((first thing popped) (operation) (second thing popped)), and pushes it to the array. str(n) means 'n considered as string'.
    • If a function is involved, change it to the string.
+ Second thing : integer Second thing : float Second thing : string Second thing : list
First thing : integer first+second (int) first+second (float) str(first)+second (string) add first thing to first of second thing.
First thing : float first+second (float) first+second (float) str(first)+second (string) add first thing to first of second thing.
First thing : string first+str(second) (string) first+str(second) (string) first+second (string) add first thing to first of second thing.
First thing : list add second thing to last of first thing. add second thing to last of first thing. add second thing to last of first thing. concentrate first thing and second thing.
- Second thing : integer Second thing : float Second thing : string Second thing : list
First thing : integer first-second (int) first-second (float) undefined undefined
First thing : float first-second (float) first-second (float) undefined undefined
First thing : string undefined undefined undefined undefined
First thing : list remove all second thing which is in first thing. remove all second thing which is in first thing. remove all second thing which is in first thing. first\second (list)
* Second thing : integer Second thing : float Second thing : string Second thing : list
First thing : integer first*second (int) first*second (float) undefined undefined
First thing : float first*second (float) first*second (float) undefined undefined
First thing : string first thing repeated by second thing times.
empty string if second thing <= 0.
ex. "1234"*2 = "12341234"
same as (first thing)*floor(second thing) undefined undefined
First thing : list first thing repeated by second times.
empty list if second thing <= 0.
ex. {1,2,3}*2 = {1,2,3,1,2,3}
same as (first thing)*floor(second thing) undefined undefined
/ Second thing : integer Second thing : float Second thing : string Second thing : list
First thing : integer first/second (int)
if second is 0, result is Infinity (float).
if second is -0, result is -Infinity (float).
first/second (float) undefined undefined
First thing : float first/second (float) first/second (float) undefined undefined
First thing : string undefined undefined first string delimited by second thing (list).
ex. "Axybyxycxxyd"/"xy" = {"A","by","cx","d"}
undefined
First thing : list undefined undefined undefined undefined

Literals

Despite of the fact that there are no literals, let's just call these methods "literals".

Numbers can be represented by functions '⠀'(2800) ~ '⣿'(28FF), which pops a thing from an array, multiply that with 256, add that by 0~255 (an integer which a braille is representing), and pushes it in the array.

'0'(30) ~ '9'(39) are aliases of '⠀'(2800) ~ '⠉'(2809). '⒈'(2488) ~ '⒛' (249B) do the same task '⠀'(2800) ~ '⠓'(2813) do, except the pushed value is float.

'○'(25cb) pushes 0 (integer) to the array. '⑴'(2474) ~ '⒇'(2487) each pushes 1 (integer) ~ 20 (integer) to the array.

For example, this program prints '3141592'.

⠯⣯⣘n

Strings are generated from numbers, by function '"'. It pops a thing from an array as an integer, represent it in base 256, consider it as list of integers (using big endian, ignore first n 0s) which encodes UTF-8 string, convert it to string and push it in the array.

For example, this program prints 'Hello, world!'(0x48 0x65 0x6c 0x6c 0x6f 0x2c 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21).

⡈⡥⡬⡬⡯⠬⠠⡷⡯⡲⡬⡤⠡"s

User-defined functions

If the code has more than one newline(0a) character, except the first line which is the main function (denoted by '가'(ac00)), is considered by user-defined functions. The first line under the main line is considered as definition of function '각'(ac01), the next line is considered as definition of function '갂'(ac02), ...., and the 11171th line under the main line is considered as definition of function '힣'(d7a3), the last possible user-defined functions.

When a user-defined function is called, then the codes of the user-defined functions are executed. For example, if

각nn갂nn
100○200
400○800각

is interpreted, '6553613107226214452428865536131072' is printed (65536, 131072, 262144, 524288, 65536, 131072).

The main function is considered as user-defined function.

Example programs

"Hello, world!" program

⡈⡥⡬⡬⡯⠬⠠⡷⡯⡲⡬⡤⠡"s
`각Ts
Hello, world!

Prints Fibonacci numbers

○⑴각
nwdS+Lx각