diff --git a/Khayyam.md b/Khayyam.md index db34706..5789b9c 100644 --- a/Khayyam.md +++ b/Khayyam.md @@ -6,52 +6,47 @@ We choose .kh for files that have Khayyam language codes. ## Top Level Keyword -### include -Khayyam allow developers to include multi file by use `include ()`, so use `include` more than once in a file is not legal. -Khayyam use `include ({name} {addr})` keyword e.g. -- `include ("/lib/error")` to include all exported types, vars, functions, ... without need indicate package name to call them e.g. `fn test() error {}` that `error` can be type, ... indicate in included file. -- `include ({NewError} "/lib/error)"` to include just `NewError` e.g. `var ErrBadThing = NewError("oops...") ` - -### import -Khayyam use `import ({name} {addr})` keyword e.g. `import (json "../json)"` to import other code file to local one. import desire file and use needed logic by this way e.g. `json.Marshal()` -- Khayyam allow developers to import multi files by use `import ()`, so use `import` more than once in a file is not legal. - -### type -> data type -Khayyam force you naming a type with one of below type as `type {Name} [Type]`. `Type` can be one of below items. -- ptr as [Pointer]() to point specific memory location as [Digital computing](). Size depend on CPU architecture(32||64||...bit). e.g. `type buf ptr` -- `Function` can indicate by -- `Interface`: We can't decide yet that Khayyam must support interface type in old fashion way. -- Any other `structure` - -Any library use above fundamental types and implement any types like: -- `bool` to work on any boolean logical. It will usually cost 8bit memory. It can hold value 1 or 0 as true or false. e.g. `type ok Bool` if it is included to this package or file. -- Numerical can indicate by e.g. `type testNum [x][NS]`. They can `Init` by any natural number (x>0) to indicate fixed array length in bit that number can hold. `x` itself just to indicate it can get any length. library decide to how handle this type of logic e.g. with any hardware accelerator or do many logic in large length. -Libraries can decide to implement `Arithmetic` rule. This rule can be done on `bool`, `Numerical` and `array(list)` type. In Numerical if either operand is not the same number system, It always converts to a higher system range e.g. if one of the operands is [1]N and the other is [2]W, the result type is [2]W. - - NS can any [Number systems](https://en.wikipedia.org/wiki/Number#Main_classification): - - N as [Natural](https://en.wikipedia.org/wiki/Natural_number) is any number > 0 - - W as [Whole]() is any number >= 0 - - Z as [Integer](https://en.wikipedia.org/wiki/Integer) also know as signed number is any number <>= 0 - - Q as [Rational](https://en.wikipedia.org/wiki/Rational_number) also knows as decimal, float, ... - - R as [Real](https://en.wikipedia.org/wiki/Real_number) also know as Irrational, Fractional - - C as [Complex](https://en.wikipedia.org/wiki/Complex_number) -- `Array` or `List` or `List of List` or ... can indicate by this syntax `[List]` and it is fixed size. e.g. `type testArray List`, `type emails emails` and can `Init` by any number `email.Init(256, 8)` - -### st -> structure as encapsulation-pattern -- structure indicate by `struct{...}` that has some other types inside itself. - -### self -> point to other members in the capsule! -- fn (type receiver) name(args) (returns) >> method function +### type +Type or data type is a subdivision of a particular kind of things. All things MUST define in below shape to understand by Khayyam compiler. +```khayyam +type {name} [Type] [subtype defined value] + +type ( + {name1} [Type1] [subtype defined value] + {name2} [Type2] [subtype defined value] +) +``` -### cn -> Constant -const, unlike other languages, is not very hard immutable data. Dev can change in runtime but unlike var, it will change binary code and don't need to get it by memory call. Compiler and runtime just let to change the value with the same memory size. +### Types +- **Include**: Khayyam allow developers to include multi file by use `in`. + - use `include` more than once in a file is not legal. + - Khayyam use `type {name} in {addr}` keyword e.g. + - `type * in "/lib/error"` to include all exported types, vars, functions, ... without need indicate package name to call them e.g. `fn test() error {}` that `error` can be type, ... indicate in included file. + - `type NewError in "/lib/error"` to include just `NewError` e.g. `var ErrBadThing = NewError("oops...")` -### vr -> Variable -Like other programming languages, var keyword uses to store data in any mutable device. But unlike other, vars declare inside a function store +- **Import**: Khayyam allow developers to imports other file codes by use `im`. + - Khayyam allow developers to import multi files by use `import ()`, so use `import` more than once in a file is not legal. + - Khayyam use `type {name} im {addr}` keyword e.g. `type json im "memar/json"` to import other code file to local one. import desire file and use needed logic by this way e.g. `json.Marshal()` -### fn -> Function +- **Function**: Khayyam allow developers to indicate functions by use `fn`. Two type function supported: -- fn name(args) (returns) >> pure standalone function + - type {name} fn (args) (returns) >> pure standalone function + +- **Abstraction**: Khayyam allow developers to indicate abstraction by use `ab`. +We don't introduce any other syntax for Polymorphism(generic) like Golang(`[{name} {TYPE}]`) for other types. Compiler decide smartly to do it by runtime(Golang interface) or compile time(Golang generic). + +- **structure**: Khayyam allow developers to indicate encapsulation-pattern by use `st`. + - structure indicate by `type {name} st {...}` that has some other types inside itself. + - Inside a structure can omit `type` keyword in each line to indicate fields. + +- **Constant**: Khayyam allow developers to indicate constant by use `cn`. +const, unlike other languages, is not very hard immutable data. Dev can change in runtime but unlike var, it will change binary code and don't need to get it by memory call. Compiler and runtime just let to change the value with the same memory size. + +- **Variable**: Khayyam allow developers to indicate constant by use `vr`. +Like other programming languages, `vr` keyword uses to store data in any mutable device. But unlike other, variables declare inside a function store. +### sf -> self as point to other members in the capsule! +- fn (type receiver) name(args) (returns) >> method function ### rt -> return - Just use to indicate return in body of a function. @@ -59,34 +54,25 @@ Two type function supported: - It is pure keyword and must end with [commands break](#Commands_Break) style so dev can't use like "return 0". ### Commands Break -each command must end with new line or ';' +each command must end with new line or ';' ## Operators -https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B -https://maxbase.org/my-programming-language/et-operat]Nor-precedence-en/ - -### Comparison or Relational -### Logical -### Bitwise -### Compound assignment -### Member and pointer -### Other -### Precedence +Since we have no primitive types in language syntax, We don't need to provide any operators! ## Rules ### Inline Function - Inline function return const as declare const globally. Below codes are same when compile them. ```Khayyam -fn fixedLen() (fixedSize Natural) { - const fixedSize Natural.Init(326) - return fixedSize +fn fixedLen() (fixedSize integer.U16) { + fixedSize.FromASCII(326) + return } -const fixedLen Natural.Init(326) +const fixedLen integer.U16.FromASCII(326) ``` ### getter and setter methods -For each structure field developer must define global get & set methods, otherwise compiler throw compile error if any read||write be in codes. +For each structure field developer must define global get & set methods, otherwise compiler throw compile error if any read||write directly to fields be in codes. ## Runtime We offer very simple but with some unique logic @@ -101,6 +87,13 @@ You can write code to change binary code in runtime. ## Not implement features!? In this part, we say why not choose something that be real in some other programming languages. +### Methods Overloading +It seems we need this feature if we want to have very simple generic and polymorphism. +Due to Khayyam not support primitive types, All disadvantages disappear and JUST advantages will shine. + +### Method overriding +Method overloading is a compile-time polymorphism. Method overriding is a run-time polymorphism. CAN provide runtime feature when not provide rich runtime?? + ### Packaging We can't decide yet to offer any package some files code. @@ -114,12 +107,12 @@ Tuples are implemented by two dynamic and static type languages. ### Type Inference Khayyam don't support type inference and also you can't assign to var before you decare it. ``` -var x = 41 >> var x [1]W = 41 -var y = 3.14 >> var y [32]Q = 3.14 +var x = 41 >> type x vr whole.W8.FromString(41) +var y = 3.14 >> type y vr rational.R32.FromString(3.14) ``` ### Loop -We think loop can implement easily by `goto` instead of while, for, do, ... +We think loop can implement easily by `goto` instead of `while`, `for`, `do`, ... if and just if `Iterator` interface not implement by desire type. ### Dependency Management We don't offer any version control for your codes, So we must not offer any dependency management too. @@ -127,12 +120,12 @@ We don't offer any version control for your codes, So we must not offer any depe ## Keyword in a glance | type | Logical | *********** | *********** | *********** | | :---: | :---: | :---: | :---: | :---: | -| ptr | if | | | | -| bool | else if | | | | -| struct | else | | | | -| const | true | | | | -| var | false | | | | -| fn | goto | | | | +| type | if | | | | +| fn | else if | | | | +| st | else | | | | +| cn | | | | | +| vr | | | | | +| | goto | | | | | | | | | | | | | | | |