User:ZCX islptng/Sandbox

From Esolang
Jump to navigation Jump to search

InDev Esolang: 高尔夫

This is a Chinese Golfing language by islptng, inspired by XENBLN.
Because we have so many Chinese characters, we can have more commands.

Data types

Datatype Description Example How to generate
Nil NoneType nil
Integer self-explanatory 123 Written in base 32(零-九 0-9, 甲-癸 10-19, 子-亥 20-31). Example: 114514 = 三己午壬 Also can be written in base 10, such as 123 becames 十进一二三(the "十进" part works like how hexadecimal is accepted in C++). Note that for 0, both 零 and 〇 are accepted. Add 负 to the start of integer to make negative number, such as -114514 is 负三己午壬.
Fraction/Float self-explanatory 123/45 or 123.45 Base 32, division sign is 分, decimal point is 点. such as 1/31 becames 一分亥. Also can be written in base 10, such as 3.14159 becames 十进三点一四一五九.
Boolean True or false True 真 or 假.
String self-explanatory "你好世界" 文你好世界止 To escape, use "特x". Available escape: 换 LF (回 CR), 表 tab, 退 backspace, 码 unicode, 止 “止”, 特 “特”, 铃 alarm.
Array a dictionary [1,2,[3,4],"你好世界"] 列...止
Undefined self-explanatory Undefined Some undefined behavior returns this, such as 1/0, or 负一和十进零点五幂(sqrt(-1), which returns imaginary number, but this programming language doesn't support complex number).

Besides, we have a type called "Lambda".

Type conversions

The following is a table of type conversions. The column of a conversion specifies what datatype it converts from, and its row indicates the datatype it converts to; x represents the value being converted. These conversions happen automatically.

Integer Fraction/Float Boolean String Array Nil Undefined
Integer floor(x) x ? 1 : 0 parseInt(x) or 0 length(x) 0 0
Fraction/Float x/1 x ? 1.0 : 0.0 parseFloat(x) or 0.0 length(x) / 1 0.0 0.0
Boolean x != 0 x != 0.0 x != "" x != [] true false
String toString(x) toString(x) x ? "true" : "false" "[" + ", ".join(x) + "]" "" 99 bottles of beer
Array [x] [x] [x] [x] [] [Undefined]

You will get an error when you tried to convert lambda to a normal data type. Convert from a normal data type to a lambda, you get a lambda that pushes that value onto stack.

Commands

Arithmetic & Logical

We push the arguments into a stack first, then call a function to pop it.

Commands Meaning Syntax example
加 减 乘 除 幂 模 根 对 Arithmetic(add, subtract, multiply, divide, power, modulo, root, logarithm) 三和六加 (should return 9)
子 母 Fraction operators(ordinal/cardinal) 一分亥母 (should return 31)
Negate on integer/fraction/float, Not on boolean, Reverse on list/string. 子反 (should return -20)
整 分 浮 字 表 逻 无 Type conversion(integer, fraction, float, string, list, boolean, NoneType(both nil and undefined belongs to this.) ) 一和零除字出 (should output 99 bottles of beers)
Input. Not on display.
Output. Not on display.
B-th item in A. Numbers will be converted into strings for A. Not on display.
Replace all of B in A with C. Numbers will be converted int strings for A. Not on display.
Equal. Not on display.
Greater than. Not on display.
Less than. Not on display.
Used for quines and self-interpreters. For example, if A = 114514, it will return "三己午壬". if A = "你好\n", it will return "文你好特换止". Not on display.
"range" in Python. Accepts all 3 arguments. Not on display.

Flow Control

Commands Meaning
a b赋 Assign value a to a variable called b.
循 code 止 Infinite loop.
x对i code止 For every object in i as x, do code. If x is integer, repeat x times.
退 / 下 Break / Continue
a若v1则code1止v2则code2止 ... 否default止 Switch-case block.
试code错code止 Try-except block.
函code止 Pushes a lambda function to stack.
Call the lambda function on the top of the stack.

Use 和 for separator.
Other characters are NOP. All non-Chinese characters except those in strings are ignored.

Examples

99 bottles of beer

Cheating

一和零除字出

Cheating 2

负一和十零点五幂字出

Serious

文春日宴。特换止出三七酒赋循酒若零则退止止文與君馕杯酒。可以窮歡宴。綠酒一杯歌一遍。特换止文馕止酒替出止文綠酒千杯腸已爛。止出

Hello World

文問天地好在。特换止出

Judge if a number is even or odd

入数和输赋文馕是槫数止文槫止输二模若一则文奇止止否文偶止止替文馕止输替出

Category List: Golfing language, Languages, CJK, 2024