add documentation for let and while forms
This commit is contained in:
parent
acb1e1c126
commit
896ed567fd
2 changed files with 39 additions and 61 deletions
43
Readme.org
43
Readme.org
|
|
@ -69,9 +69,38 @@ Function calls are executed as soon as the tree is evaluated. See the following
|
|||
|
||||
In this example, ~(add 5 2)~ is evaluated first, its result is then passed to ~(add 3 ...)~. In infix form: ~3 + (5 + 2)~.
|
||||
|
||||
*** TODO Control flow
|
||||
**** TODO if
|
||||
**** TODO while
|
||||
*** Control flow
|
||||
**** if
|
||||
An if form is the most basic form of conditional evaluation offered by Relish.
|
||||
It is a function that takes lazily evaluated arguments: a condition, a then clause, and an else clause.
|
||||
If the condition evaluates to true, the then clause is evaluated and the result returned.
|
||||
Otherwise the else clause is evaluated and the result is returned.
|
||||
If the condition evaluates to neither true nor false (a non-boolean value) a type error is returned.
|
||||
|
||||
#+BEGIN_SRC lisp
|
||||
;; simple condition
|
||||
(if true
|
||||
(echo "its true!")
|
||||
(echo "its false!"))
|
||||
|
||||
;; more advanced condition, with hypothetical data
|
||||
(if (get-my-flag global-state)
|
||||
(echo "my flag is already on!")
|
||||
(turn-on-my-flag global-state))
|
||||
#+END_SRC
|
||||
|
||||
**** while
|
||||
Another popular control flow structure is the *while loop*.
|
||||
This is implemented as a condition followed by one or more bodies that are lazily evaluated only if the condition is true.
|
||||
Like the *if form*, if the conditional returns a non-boolean value the *while loop* will return an error.
|
||||
|
||||
#+BEGIN_SRC lisp
|
||||
(while (get-my-flag global-state) ;; if false, returns (nothing) immediately
|
||||
(dothing) ;; this is evaluated
|
||||
"simple token" ;; this is also evaluated
|
||||
(toggle-my-flag global-state)) ;; this is also evaluated
|
||||
#+END_SRC
|
||||
|
||||
**** TODO let
|
||||
**** TODO circuit
|
||||
*** TODO quote and eval
|
||||
|
|
@ -166,7 +195,13 @@ Errors during configuration are non-terminal. In such a case any defaults which
|
|||
- CFG_RELISH_PROMPT (default (echo "λ ")): A *function* definition which is called in order to output the prompt for each loop of the REPL.
|
||||
This function will be reloaded each REPL loop and will be called by the interpreter with no arguments.
|
||||
|
||||
** TODO Further configuration
|
||||
*** Further configuration
|
||||
Further configuration can be done by loading scripts that contain more functions and data to evaluate.
|
||||
Variables and functions defined in an external script loaded by your interpreter will persist in the symbol table.
|
||||
|
||||
#+BEGIN_SRC lisp
|
||||
(load "my-extra-library-functions.rls")
|
||||
#+END_SRC
|
||||
|
||||
** Compilation
|
||||
#+BEGIN_SRC sh
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue