LIOD: Documentation
Basic Syntax
Every `parenthised expression` has this syntax: (macro args...), where macro `can't be` another parenthised expression, and arguments count is `infinite`.
Also, `empty` parenthised expression causes the same `error`. `Macro can't` be outside of parenthis.
`Definitions can be` outside of parenthesis.
>>> (+ 14 18)
32
>>> ((get-at (list / * - +) 3) 11 33)
LIOD00: The macro is not defined.
>>> ()
LIOD00: The macro is not defined.
Keywords
There are `4 keywords` in LIOD: use, def, mac,
con.
They are the most basic, so for normal programming you should use `framework` / `library` or even create you own.
There is `everything` about them:
Use
This keyword `includes` contents from `another file`.
Argument *file-path* is `path` to the file `within the folder`, where the main file in.
It `shouldn't` include extension, so it means that the file can `only` have .liod extension.
; usage
(use *file-path*)
; using library which is inside of the
; project folder
(use LIOD)
Def
This keyword allows to create `definitions`.
Argument *name* defines the `name` of the definition.
Name `can't` be `parenthised expression` or `integer`, but it can `start` from number or be a `float`.
So cheese, 12th, 1.1 are `valid` definition names,
and 1999 and (sand) are `not`.
Argument *value?* defines the `value` of the definition. It isn't necessary, if you won't use it, the value will be "".
All parenthised expressions, definitions and just text are `valid`.
; usage
(def *name* *value?*)
; text value
(def me Yurix) ; me = "Yurix"
; copying
(def i me) ; i = "Yurix"
(def me 1234) ; i = "Yurix", me = 1234
; nothing
(def nothing) ; nothing = ""
; ok
(def we i me) ; child = i me
Mac
This keyword allows to create `macros`.
Argument *name* defines the `name` of the macro.
Rules for macro naming are `similar to definition` naming.
Argument *args?...* defines all `arguments` of the macro.
It's count is `not limited`. If you won't use any arguments in your macro just leave (def).
Argument *conts...* defines `contents` of the macro.
It `can't` be ungiven and it's length is `unlimited`.
; usage
(mac *name* (def *args?...*) *conts...*)
; example
(mac flag (def n c) (deflg n) (def n c))
; usage
(flag france blue white red)
(print france) ; blue white red
(print france-type) ; flag
Con
This keyword creates `new s-expr` from given contents.
Argument *conts...* defines `contents` of the container.
It `can be` ungiven and it's length is `unlimited`.
Main function of the keyword is to `expand nesting`.
It's better `not to use` this outside of `libraries` and macros with `return value`.
; usage
(con *conts...*)
; return macro
(mac ++ (def a) (con (return (+ a 1))))
(pixel (++ x) (++ y)) ; expands to
; (++ x) (++ y) (pixel tmp1 tmp2)
Purity
To write pure code in LIOD you should follow this rules:
- The `enclosing parenthis` should be on the `individual line` like in JS and C.
- To name `libraries` use `PascalCase`, and separate subdivisions by ' . ' or ' / '.
- To simulate `overloading` of macro use ' * ', ' ? ', ' : ' characters `in the and` of the name.
- The ' * ' character in the end of the macro's name means, that this macro is `second+ version` of this macro, but gives pretty `same result`.
- Character ' ? ' means that the macro `returns` something like `boolean value`.
- Character ' : ' means that the macro does `pretty much the same` but `multiple` times.
- To name `macros` or `definitions` use `kebab-case`.
- To name `class` or something like this use `lowercase`.
- To separate class name from macro use ' : '.
- For `comments` use `any style` but I would recommend to `combine UPPERCASE`(for something global) and `lowercase`
- `Comments are such a good thingy` to understand the code well.
- Use `indents`: they are useful to make code `reading easier`.
;;;; GOOD CODE
(use LIOD)
(use Spherium.Sphere) ; sph class
; defining variables
(num: x y)
; main function
(mac main (def)
(for (= x 0) (\l x 256) (+= x 16)
(for (= y 0) (\l y 256) (+= y 16)
(sph shpere (sph:create))
(sph:setpos sphere x y)
)
)
)
; overload with no z coord
(fn sph:setpos* (def shpere x y)
(if (sph? sphere)
(sph:set-x sphere x)
(sph:set-y sphere y)
)
)
;;;; BAD CODE
(use liod) (use spherium-Sphere)
(manynums x y)
(mac Main (def)
(for (= a 0) (\l a 256) (+= a 16)
(for (= b 0) (\l b 256) (+= b 16)
(sph shpere (sph_create))
(sph_setPosXY sphere a b))))
(fn sph_setPosXY (def shpere a b)
(sph_set-x sphere a)
(sph_set-y sphere b))