88
99Chap is an easy to learn, dynamic, interpretive language written in Rust.
1010
11- Chap is like ** Communism** ✊, It's useless and people think it's because it's not implemented correctly 🫳🏻🎤, (We need to test it on an smaller society first).
11+ The Chap joke: Chap is like ** Communism** ✊, It's useless and people think it's because it's not implemented correctly 🫳🏻🎤, (We need to test it on an smaller society first).
1212
1313Besides the comedy part, It actually does have some cool new Ideas about programming languages in general.
1414
@@ -54,26 +54,20 @@ What makes a programming language hard to learn?
5454"Keywords"
5555```
5656
57- | Language | Keywords | Difficulty level |
58- | ----------| -----------| ------------------|
59- | C# | 102 | 5/5 |
60- | Java | 48 | 4/5 |
61- | Python | 35 | 3/5 |
62- | Lua | 22 | 2/5 |
63- | Chap | 0 | 0/5 |
64-
6557There are no keywords in Chap.
6658
6759## Syntax
6860
61+ There is only one syntax in Chap, Other ones are just sugar syntaxes.
62+
6963A normal line of code in chap has 3 chunks separated with -> operator:
7064
7165``` chp
7266chunk1 -> chunk2 -> chunk3
7367```
7468
75- | Chunk 1 | Chunk 2 | Chunk 3 |
76- | -------------- | --------------- | ----------------- |
69+ | Chunk 1 | Chunk 2 | Chunk 3 |
70+ | ------------ | ------------- | --------------- |
7771| input params | function name | output variable |
7872
7973``` chp
@@ -136,12 +130,14 @@ Input params are separated by comma character ",".
136130
137131Input params can be:
138132
139- 1 . Variable
140- 1 . String with " character around like: "hello world"
141- 1 . Int just a number: 5
142- 1 . Float just a normal form of floating point number 3.14
143- 1 . Bool is a boolean value which is a true or false
144- 1 . Tags start with @. [ (more on control flow)] ( #control-flow )
133+ 1 . Variable
134+ 1 . String with " character around like: "hello world"
135+ 1 . Int just a number: 5
136+ 1 . Float just a normal form of floating point number 3.14
137+ 1 . Bool is a boolean value which is a true or false
138+ 1 . Tags start with @. [ (more on control flow)] ( #control-flow )
139+ 1 . Lists can be created like this: [ 1 "hello" "world"] (space separated).
140+ 1 . Maps can be created like this: {"name":"Ali" "age":26} (space separated)
145141
146142``` chp
147143$a, "hello", 5, 3.14, false -> function_name -> $output_var
@@ -166,10 +162,10 @@ $#^3 // Ok
166162$a,b // comma not allowed
167163$really? // question mark at the end not allowed
168164$rea?lly // OK
169- $some->thing // "->" is not allowed
165+ $some->thing // "->" is not allowed
170166```
171167
172- ## Short syntax features
168+ ## Sugar syntaxes
173169
174170If a function has no output variable you can remove chunk3:
175171
@@ -294,13 +290,13 @@ Enter a number: 3
294290
295291Why? Because Python uses the same operator for math.multiply and strings.repeat.
296292
297- So * operator ** "IS NOT A TYPE SAFE"** operator and it will ** "DO UNEXPECTED THINGS"** when your forget to pass the right type to it and it will happen without throwing runtime errors (which is bad).
293+ So \ * operator ** "IS NOT A TYPE SAFE"** operator and it will ** "DO UNEXPECTED THINGS"** when your forget to pass the right type to it and it will happen without throwing runtime errors (which is bad).
298294
299295Same code in Chap:
300296
301297``` chp
302298input -> $number
303- $number, 5 -> multiply -> $result
299+ $number, 5 -> multiply -> $result
304300$result
305301// error in line 2: multiply function works only with numbers int and float
306302```
@@ -309,7 +305,7 @@ Runtime errors are much better than logical errors, and in chap we have the repe
309305
310306``` chp
311307"foo ", 3 -> repeat
312- // foo foo foo
308+ // foo foo foo
313309```
314310
315311In many languages "+" operator has the same problem:
@@ -466,18 +462,13 @@ you win
466462## christmas_tree.chp
467463
468464``` chp
469- // Editable
4704650 -> $counter
471466@loop
472467 $counter -> increase
473468
474- $counter, 2 -> multiply -> $stars_size
475- 10, $counter -> minus -> $space_size
476-
477- "*", $stars_size -> repeat -> $stars
478- " ", $space_size -> repeat -> $spaces
479-
480- $spaces, $stars -> cat
469+ (" ", (10, $counter -> minus) -> repeat),
470+ ("*", ($counter, 2 -> multiply) -> repeat) ->
471+ cat
481472@loop, $counter, 10 -> jump if not equal
482473```
483474
@@ -494,75 +485,6 @@ you win
494485********************
495486```
496487
497- ## christmas_tree_with_trunk.chp
498-
499- ``` chp
500-
501- // Editable
502- 0 -> $counter
503- @loop
504- $counter -> increase
505-
506- $counter, 1 -> multiply -> $stars_size
507- 19, $counter -> minus -> $space_size
508-
509- " * ", $stars_size -> repeat -> $stars
510- " ", $space_size -> repeat -> $spaces
511-
512- $spaces, $stars -> cat
513-
514- "`*-", $stars_size -> repeat -> $stars
515- " ", $space_size -> repeat -> $spaces
516-
517- $spaces, $stars -> cat
518- @loop, $counter, 10 -> jump if not equal
519-
520- 3 -> $c
521- @loop
522- $c-> increase
523-
524- $c, 2 -> multiply -> $stars_size
525- 22, $c-> minus -> $space_size
526-
527-
528- "*", $stars_size -> repeat -> $stars
529- " ", $space_size -> repeat -> $spaces
530-
531- $spaces, $stars -> cat
532-
533- @loop, $c, 7 -> jump if not equal
534-
535- ```
536-
537- ``` sh
538-
539- *
540- ` * -
541- * *
542- ` * -` * -
543- * * *
544- ` * -` * -` * -
545- * * * *
546- ` * -` * -` * -` * -
547- * * * * *
548- ` * -` * -` * -` * -` * -
549- * * * * * *
550- ` * -` * -` * -` * -` * -` * -
551- * * * * * * *
552- ` * -` * -` * -` * -` * -` * -` * -
553- * * * * * * * *
554- ` * -` * -` * -` * -` * -` * -` * -` * -
555- * * * * * * * * *
556- ` * -` * -` * -` * -` * -` * -` * -` * -` * -
557- * * * * * * * * * *
558- ` * -` * -` * -` * -` * -` * -` * -` * -` * -` * -
559- ********
560- **********
561- ************
562- **************
563-
564- ` ` `
565-
566488## DataTypes
567489
568490``` chp
@@ -575,11 +497,14 @@ float
575497"ali" -> TypeOf
576498string
577499
578- true -> type
500+ true -> type
579501boolean
580502
581- -> [1 2 3] -> type
503+ -> [1 2 3] -> type
582504list
505+
506+ -> {"name":"Ali"} -> type
507+ map
583508```
584509
585510## Memory Management
@@ -610,15 +535,15 @@ sudo cp ./target/release/chap /usr/bin
610535❯ chap
611536-> " hello world"
612537hello world
613- ->
538+ ->
614539```
615540
616541### File_executor
617542
618543[ ./file_executor/mod.rs] ( https://github.com/ali77gh/Chap/blob/master/src/file_executor/mod.rs )
619544
620545``` bash
621- ❯ chap number_guess_game.chp
546+ ❯ chap number_guess_game.chp
6225471
623548wrong
6245492
@@ -635,82 +560,10 @@ you win answer was: 3
635560cargo add chap # this include eval function
636561```
637562
638- or
639-
640- ` ` ` bash
641- cargo build --release --lib
642- ` ` `
643-
644- # # Release Note version 2.0.0
645-
646- - [x] Arrays
647- - [x] fix: ' random' module will not work on WASM
648- - [x] eval function
649- - [x] [ChapApp](https://github.com/ali77gh/ChapApp)
650- - [x] Piping syntax (1, 2 -> add -> toString -> print)
651- - [x] Parentheses (1, 2 -> add), (2, 3 -> add) -> concat -> $var // 35
652- - [x] New debugger syntax 1,2 -> add? -> $sum
653-
654563## Stars
655564
656565[ ![ Stargazers over time] ( https://starchart.cc/ali77gh/chap.svg )] ( https://starchart.cc/ali77gh/chap )
657566
658567## Builtin Functions
659568
660- [runtime/builtin_function](https://github.com/ali77gh/Chap/tree/master/src/runtime/builtin_function)\
661- Chap has 49 builtin function(version 2.0.0) (less than Java' s keywords)
662-
663- | Names | Input params | output | description |
664- |-------------------------|-------------------|----------|-------------------------------------------------------------|
665- | assign | any | any | put a value or variable in other variable 1 -> $a |
666- | std_out, print, show | any, any, any,... | any | prints params to console |
667- | std_in, input | nothing | string | read user input from console |
668- | exit, quit, kill, end | nothing | nothing | ends execution |
669- | jump | @tag | nothing | moves executor curser to closest tag with specified name |
670- | jump_if | @tag, bool | nothing | jumps to tag if 1st param is true |
671- | jump_if_not | @tag, bool | nothing | jumps to tag if 1st param is false |
672- | jump_if_equal, jeq | @tag, any, any | nothing | jumps to tag if 2th and 3th params are equal |
673- | jump_if_not_equal, jneq | @tag, any, any | nothing | jumps to tag if 2th and 3th params are not equal |
674- | new_tag | @tag | nothing | creates tag (you can call this just by writing tag name |
675- | add | num, num | num | adds two numbers 1 + 2 = 3 or 1.5 + 1 = 2.5 |
676- | add_many, add_all | num, num, num,... | num | adds many numbers 1 + 2 + 3 = 6 |
677- | minus | num, num | num | minus two numbers 3 - 2 = 1 |
678- | multiply | num, num | num | minus two numbers 3 * 2 = 6 |
679- | divide | num, num | num | divide two numbers 3 / 2 = 1.5 |
680- | modulus, mod | num, num | num | divide remaining 3 / 2 = 1 |
681- | power, pow | num, num | num | power 3 ** 2 = 9 |
682- | square_root, sqrt | num | num | square root 9 -> sqrt -> 3 |
683- | increase, inc | $num | nothing | adds one to variable short form of: $a,1 -> add -> $a |
684- | decrease, dec | $num | nothing | minus one from variable short form of: $a,1 -> minus -> $a |
685- | equal, eq | any, any | bool | true if 1st and 2nd are equal and false if they are not |
686- | not_equal, neq | any, any | bool | true if 1st and 2nd are not equal and false if they are |
687- | and | bool, bool | bool | and logical gate |
688- | or | bool, bool | bool | or logical gate |
689- | xor | bool, bool | bool | xor logical gate |
690- | not | bool | bool | not logical gate |
691- | greater_than, gt | num, num | bool | true if 1st param is bigger than 2nd param 3,2 -> true |
692- | less_than, lt | num, num | bool | true if 1st param is less than 2nd param 3,2 -> false |
693- | concat, cat | any, any | string | convert inputs to string and concat them "al","i" -> "ali" |
694- | repeat | any, int | string | convert inputs to string and repeat "a",3 -> "aaa" |
695- | length, len | any | int | convert input to string and returns length 456 -> 3 |
696- | contains, has | any | bool | convert inputs to string and returns 1st contains 2nd 11,1->true |
697- | slice, sub_string | any, int, int | string | "hello", 1, 3 -> "el" |
698- | insert | array, any | nothing | insert an item to list |
699- | get | array, int | any | get nth item of list second param is index of item |
700- | pop | array | any | remove last item of list and returns it |
701- | last | array | any | return lsat item of list (without removing it) |
702- | has | array, any | bool | check if an item exist in a list |
703- | remove | array, any | nothing | removes a given item from list |
704- | remove_at | array, int | nothing | removes item at index of second param |
705- | index_of | array, any | int | search for an item on list and returns index |
706- | to_string | any | string | convert input to string 1 -> "1" |
707- | to_float | string | float | convert input to float "1.5" -> 1.5 ; "a"->error |
708- | to_int | string | int | convert input to int "1" -> 1 ; "a"->error |
709- | dump, dump_memory | nothing | nothing | prints all variables with values |
710- | type_of, type | any | str | prints type of param 1 -> int; "s" -> string |
711- | now_sec, now, unixtime | nothing | float | unix time standard in seconds |
712- | wait_mil, wait_millis | int | nothing | delay code execution for 1st milliseconds |
713- | wait_sec, wait_sec | int | nothing | delay code execution for 1st seconds |
714- | wait_min, wait_minute | int | nothing | delay code execution for 1st minutes |
715- | wait_hour,wait_hour | int | nothing | delay code execution for 1st hours |
716- | wait_hour,wait_hour | int | nothing | delay code execution for 1st hours |
569+ [ builtin function docs] ( https://github.com/ali77gh/Chap/tree/master/src/runtime/builtin_function ) \
0 commit comments