CJKGolfer

From Esolang
Jump to navigation Jump to search

CJKGolfer is designed by PSTF, which is inspired from Sclipting.

Most basic syntax

Execution

CJKGolfer has a stack, and infinity amount of variables.

Many of the instructions are based on stack.

Data types

  1. Numbers(数). Every real numbers are allowed to 数, such as 二根三加五七分六减四点三七八.
  2. Complex(复). Write as 数实数虚. They converts to its geometrical absolute value when converts to integer.
  3. Strings(字). Quote by 『』. \『 is 『 , \』 is 』, \\ is \, \控x is U+x.
  4. Boolean(逻). 真 or 假.
  5. Array(列). Quote by 【】, and seperate by ,.
  6. Nil(空). Only 空.
  7. Undefined behaviour. Something that weird, such as 五除〇.
  8. Lambda(函). Simply a function.
Number Complex Boolean String Array Nil Undefined
Number |x| x ? 1 : 0 parseInt(x) or 0 length(x) 0 0
Complex x+0i x ? 1.0 : 0.0 parseFloat(x) or 0.0 length(x) / 1 0.0 0.0
Boolean x != 0 x != 0+0i x != "" x != [] true false
String toString(x) toString(x) x ? "true" : "false" "[" + ", ".join(x) + "]" "" 99 bottles of beer
Array [x] [x] [x] [x] [] [Undefined]

Both base 10 and base 100 are accepted. Base 100 is quoted in 百……百.

〇一二三四五六七八九
甲乙丙丁戊己庚辛壬癸
子丑寅卯辰巳午未申酉
戌亥零壹贰叁肆伍陆柒
捌玖乾兑离震巽坎艮坤
氢氦锂铍硼碳氮氧氟氖
钠镁铝硅磷硫氯氩钾钙
钪钛钒铬锰铁钴镍铜锌
镓锗砷硒溴氪铷锶钇锆
铌钼锝钌铑钯银镉铟锡

instruction

There are currently two type of instruction.

  1. Non-argumented individual instructions. Many statements fall into this category, they are not passed arguments, and they just do a separate thing.
    • Argumented individual instructions. Same as above, but argumented.
  2. Block of code. They're stopped by 止(zhi3) and started by 作(zuo4).

Program will directly run, and throw SyntaxError when not matched code block. Comments are quoted in 「」.

Stack manipulations

Discard

Command Table
Command Pronounciation Corresponding English Meaning
la1 Pull This is Argumented individual instruction. It receives x, and pop top x-th item from the stack and return it(1-based). Leave blank means top.
diu1 Throw This is Non-argumented individual instruction. It pop top item from the stack and return it.
qi4 Abandon This is Argumented individual instruction. It receives x, and pop top x items from the stack and return them as array. Leave blank means 1.
hui3 Destroy This is Non-argumented individual instruction. It pop top item from the stack and discard it.
mie4 Destroy This is Argumented individual instruction. It receives x, and pop x-th item from the stack and discard them. Leave blank means top.
qiu2 Beg This is Argumented individual instruction. It receives x, and return top x-th item from the stack but not pop it. Leave blank means top.

Push

Command Table
Command Pronounciation Corresponding English Meaning
tui1 Push This is Argumented individual instruction. It receives x, and push x into stack.
reng1 Throw This is Non-argumented individual instruction. It duplicates stack top.
kua4 Across over This is Argumented individual instruction. It receives x, and push a copy top x-th item of stack. Leave blank means 1.

Control flow

Command Table
Command Pronounciation Corresponding English Meaning
若 x 则 ... 否 ... 止 ruo4 ze2 fou3 zhi3 If x then ... else ... endif This is statement block. If x returns true, then do code 1, else code 2. You can construct elif by 否若.
循 ... 止 xun2 zhi3 Loop ... endloop This is statement block. It is an infinity loop.
若 x 作 ... 止 ruo4 zuo4 zhi3 If x then do ... endloop This is statement block. It is a conditional loop.
对 i 之 r 作 ... 止 dui4 zhi1 zuo4 zhi3 For r in i do ... endloop This is statement block. It is an iterative loop.
退 tui4 Exit This is Non-argumented individual instruction. It exit the current loop. 退!退!退! will exit current program.
guo4 Pass This is Non-argumented individual instruction. It jumps to next round of the loop.
xu1 Void This is Non-argumented individual instruction. It does nothing.
diao3 D*ck This is Non-argumented individual instruction. It quits the programming environment.

Calculation

Two argumented infix

Syntax: x⊙y

Command Table
Command Pronounciation Corresponding English Meaning
jia1 Addition This is Argumented individual instruction. Return x + y.
jian3 Subtraction This is Argumented individual instruction. Return x - y.
kou4 Reduce This is Argumented individual instruction. Return y - x.
cheng2 Multiplication This is Argumented individual instruction. Return x × y.
chu2 Division This is Argumented individual instruction. Return x ÷ y. Result in Float.
bai1 Break This is Argumented individual instruction. Return x ÷ y. Result in Integer(quotient of it).
fen1 Divide This is Argumented individual instruction. Return x/y. It is simply a fraction.
sheng4 Remain This is Argumented individual instruction. Return x mod y. Result in Positive Integer, even if x is negative, just like Python(-1 % 3 = 2).
mi4 Power This is Argumented individual instruction. Return xy.
gen1 Root This is Argumented individual instruction. Return x1/y. Leave y blank means y = 2.
zi3/zi0 Numerator This is Argumented individual instruction. Return numerator of x/y.
mu3 Denominator This is Argumented individual instruction. Return denominator of x/y.
shuang1 Double This is Argumented individual instruction. Return x AND y.
ling4 Other This is Argumented individual instruction. Return x OR y.
lia3 Two This is Argumented individual instruction. Return x XOR y.

Two argumented prefix

Syntax: ⊙x,y

Command Table
Command Pronounciation Corresponding English Meaning
dui4 Logarithm This is Argumented individual instruction. Return logyx. Leave y blank means y = e.
dian1 Mad This is Argumented individual instruction. Return a random integer between x and y.
feng1 Crazy This is Argumented individual instruction. Return a random float between x and y.

One argumented prefix

Syntax: ⊙x

Command Table
Command Pronounciation Corresponding English Meaning
quan1 Circle This is Argumented individual instruction. Round x towards zero.
yuan2 Circle This is Argumented individual instruction. Round x away from zero.
wei2 Around This is Argumented individual instruction. Round x towards +∞.
huan2/yuan2 Circular This is Argumented individual instruction. Round x towards -∞.
rao4 Surround This is Argumented individual instruction. Round x as usual(If the decimal part is less than 0.5, the decimal part is discarded. If the decimal part is greater than or equal to 0.5, add 1 to the integer part after discarding the decimal part).
zheng3 Integer This is Argumented individual instruction. Round x to the nearest integer (halves are rounded to even).
xian2 Epilepsy This is Argumented individual instruction. Return a random integer between 0 and x.
bing4 Sick This is Argumented individual instruction. Return a random float between 0 and x.
jue2 Absolute This is Argumented individual instruction. Return |x|. If x is complex, return its geometrical absolute value.
mei2 No This is Argumented individual instruction. Return NOT x.

Non-argumented

Command Table
Command Pronounciation Corresponding English Meaning
hun4 Chaos This is Argumented individual instruction. Return a random integer between 0 and 127.
dun4 Chaos This is Argumented individual instruction. Return a random integer between 0 and 2147483647.
ye3 Wild This is Argumented individual instruction. Return a random integer between 0 and 9223372036854775807.
man2 Savage This is Argumented individual instruction. Return a random float between 0 and 1.

Logical

Command Table
Command Pronounciation Corresponding English Meaning
duo1 More This is Argumented individual instruction. Return true if x>y, else false.
shao3 Less This is Argumented individual instruction. Return true if x<y, else false.
chen2 Sink This is Argumented individual instruction. Return true if x≥y, else false.
fu2 Float This is Argumented individual instruction. Return true if x≤y, else false.
tong3 Same This is Argumented individual instruction. Return true if x=y, else false.
yi4 Different This is Argumented individual instruction. Return true if x≠y, else false.
yu3 And This is Argumented individual instruction. Return true if both x and y return true.
huo4 Or This is Argumented individual instruction. Return true if either x or y return true.
you4 One in pair This is Argumented individual instruction. Return true if one in x and y(but not both) return true.
bu4 No This is Argumented individual instruction. Return true if x return false.

I/O

Command Table
Command Pronounciation Corresponding English Meaning
chu1 Out This is Argumented individual instruction. Print the value of x.
ru4 In This is Argumented individual instruction. Input a string with specified prompt and return it.
xie3 Write This is Argumented individual instruction. Print a serie of value, with specified seperator(割) and terminator(终).
du2 Read This is Argumented individual instruction. Input an expression with specified prompt and evaluate its result, and return it.

Variable

Command Table
Command Pronounciation Corresponding English Meaning
zhi4 Set This is Argumented individual instruction. It receive a name, a type, and a value. Name can be any other Chinese Characters, Kanas, and Hangul Syllables. Define a variable with specified name, type, and value. Name must not exist. This is inspired by SLet.
rang4 Let This is Argumented individual instruction. It receive a name, and a value. Assign the new value to the variable. Assign with type will change its type. This is inspired by SLet.

List operations

Command Table
Command Pronounciation Corresponding English Meaning
li3 Tidy up This is Argumented individual instruction. Sort a list immediately. Strings are sorted by dictionary order, array also do that, false < true, complex are sorted by their absolute value. Such as, 3+4i > 1+1i(because 5 > sqrt(2)). Empty < Bool < Number < Complex < String < List.
jiao3 Stir This is Argumented individual instruction. Suffle a list randomly.
ban4 Mix This is Argumented individual instruction. Generate a shuffled list.
qie1 Slice This is Argumented individual instruction. It receive a list and two integers(x and y), and return the slice from x to y of the list(0-based indexing).
jie1 Join This is Argumented individual instruction. It receive two list, and join second in the tail of first, then return it.
ri4 F**k This is Argumented individual instruction. Join two list, and shuffle the result.
tao3 Beg This is Argumented individual instruction. It receive a list and an integer(x), and return the x-th item of the list(0-based indexing).
cha1 Insert This is Argumented individual instruction. Insert the specified element in the x-th place of the list. Leave x(integer) blank means insert at tail.
beng1/beng0 Boom! This is Argumented individual instruction. Pop the element in the x-th place of the list, and return it. Leave x blank means tail.
peng1/peng0 Boom! This is Argumented individual instruction. Pop the element in the x-th place of the list, but not return it. Leave x blank means tail.

Function

Command Table
Command Pronounciation Corresponding English Meaning
han2 Function This is Head of code block. It starts a lambda function. You can allocate a lambda function to a variable. Syntax: 函arg_list作code止.
hu1 Call This is Argumented individual instruction. Calls the function with specified name(anonymous is 功), and with specified argument list.

Class

Command Table
Command Pronounciation Corresponding English Meaning
类Name性Attr置初函我作Initialization止置名函args作methods止止 let4 xing4 zhi4 chu1 han2 wo3 zuo4 zhi3 zhi4 ming2 han2 zuo4 zhi3 zhi3 Class, attributes, initializations, methods This is Full code block. Define a class.
? ? This is Operator. Points to the method or attribute of a class.

Import

Command Table
Command Pronounciation Corresponding English Meaning
yin3 Import This is Argumented individual instruction. Imports a library. Library can be used as class.

Example

Add by yourself. I was constructed this for three nights, I have no effort on the example.

Categories, Notes, and References