mirror of https://github.com/rusefi/bldc.git
Merge commit '105c6682a53cbaab6efa7c30114cd0059dc44427'
This commit is contained in:
commit
3b65f9095b
|
@ -28,15 +28,14 @@ all integer comparisons.
|
||||||
|
|
||||||
You associate values with symbols using, <a href="#define">define</a>,
|
You associate values with symbols using, <a href="#define">define</a>,
|
||||||
<a href="#let">let</a> and you can change the value bound to a "variable"
|
<a href="#let">let</a> and you can change the value bound to a "variable"
|
||||||
using <a href="#setvar">setvar</a>
|
using <a href="#set">set</a>, <a href="#setvar">setq</a> or <a href="#setvar">setvar</a>.
|
||||||
|
|
||||||
Not all symbols are treated the same in LBM. Some symbols are treated as
|
Not all symbols are treated the same in LBM. Some symbols are treated as
|
||||||
special because of their very fundamental nature. Among these special symbols
|
special because of their very fundamental nature. Among these special symbols
|
||||||
you find `define`, `let` and `lambda` for example. These are things that you
|
you find `define`, `let` and `lambda` for example. These are things that you
|
||||||
should not be able to redefine and trying to redefine them leads to an error.
|
should not be able to redefine and trying to redefine them leads to an error.
|
||||||
There are two classes of symbols that are special by naming convention and
|
Symbols that start with `ext-` are special and reserved for use together
|
||||||
these either start with a `#`, for fast-lookup variables, and `ext-` for
|
with extensions that are loaded and bound at runtime.
|
||||||
extensions that will be bound at runtime.
|
|
||||||
|
|
||||||
Examples of symbols used as data are `nil` and `t`. `nil` is used the
|
Examples of symbols used as data are `nil` and `t`. `nil` is used the
|
||||||
represent nothing, the empty list or other similar things and `t`
|
represent nothing, the empty list or other similar things and `t`
|
||||||
|
@ -44,6 +43,25 @@ represents true. But any symbol can be used as data by quoting it
|
||||||
`'`, see <a href="#quotes-and-quasiquotation"> Quotes and
|
`'`, see <a href="#quotes-and-quasiquotation"> Quotes and
|
||||||
Quasiquotation </a>.
|
Quasiquotation </a>.
|
||||||
|
|
||||||
|
### Valid symbol names
|
||||||
|
|
||||||
|
A symbol is string of characters following the rules:
|
||||||
|
1. The first character is a one of 'a' - 'z' or 'A' - 'Z' or '+-*/=<>#!'.
|
||||||
|
2. The rest of the characters are in 'a' - 'z' or 'A' - 'Z' or '0' - '9' or '+-*/=<>!?_'.
|
||||||
|
3. At most 256 characters long.
|
||||||
|
|
||||||
|
Note that lower-case and upper-case alphabetical letters are considers identical
|
||||||
|
so the symbol `apa` is the same symbol as `APA`.
|
||||||
|
|
||||||
|
examples of valid symbols
|
||||||
|
```
|
||||||
|
apa
|
||||||
|
apa?
|
||||||
|
!apa
|
||||||
|
kurt_russel_is_great
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Arithmetic
|
## Arithmetic
|
||||||
|
|
||||||
|
@ -400,7 +418,7 @@ explicit true makes sense.
|
||||||
## Quotes and Quasiquotation
|
## Quotes and Quasiquotation
|
||||||
|
|
||||||
Code and data share the same representation, it is only a matter of how
|
Code and data share the same representation, it is only a matter of how
|
||||||
you look at it. The tools for changing how your view are the quotation and
|
you look at it. The tools for changing view, or interpretation, are the quotation and
|
||||||
quasiquotation operations.
|
quasiquotation operations.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -738,9 +756,9 @@ Example
|
||||||
### setvar
|
### setvar
|
||||||
|
|
||||||
The `setvar` form is used to change the value of some variable in an environment.
|
The `setvar` form is used to change the value of some variable in an environment.
|
||||||
You can use `setvar` to change the value of a global definition, a local definition
|
You can use `setvar` to change the value of a global definition or a local definition.
|
||||||
or a variable defintion (`#var`). An application of the `setvar` form looks like
|
An application of the `setvar` form looks like `(setvar var-expr val-expr)` where
|
||||||
`(setvar var-expr val-expr)` where `var-expr` should evaluate to a symbol. The `val-expr` is evaluated before
|
`var-expr` should evaluate to a symbol. The `val-expr` is evaluated before
|
||||||
rebinding the variable. `setvar` returns the value that `val-expr` evaluates to.
|
rebinding the variable. `setvar` returns the value that `val-expr` evaluates to.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
@ -761,15 +779,6 @@ You can also set the value of a let bound variable.
|
||||||
(let ((a 10)) (setvar 'a 20))
|
(let ((a 10)) (setvar 'a 20))
|
||||||
```
|
```
|
||||||
|
|
||||||
And you can change the value of a `#var`.
|
|
||||||
|
|
||||||
```clj
|
|
||||||
(define #a 10)
|
|
||||||
|
|
||||||
(setvar '#a 20)
|
|
||||||
```
|
|
||||||
`#a` is now 20.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### set
|
### set
|
||||||
|
|
|
@ -2055,7 +2055,6 @@ static void cont_wait(eval_context_t *ctx) {
|
||||||
static lbm_value perform_setvar(lbm_value key, lbm_value val, lbm_value env) {
|
static lbm_value perform_setvar(lbm_value key, lbm_value val, lbm_value env) {
|
||||||
|
|
||||||
lbm_uint s = lbm_dec_sym(key);
|
lbm_uint s = lbm_dec_sym(key);
|
||||||
lbm_value res = val;
|
|
||||||
if (s >= RUNTIME_SYMBOLS_START) {
|
if (s >= RUNTIME_SYMBOLS_START) {
|
||||||
lbm_value new_env = lbm_env_modify_binding(env, key, val);
|
lbm_value new_env = lbm_env_modify_binding(env, key, val);
|
||||||
if (lbm_is_symbol(new_env) && new_env == ENC_SYM_NOT_FOUND) {
|
if (lbm_is_symbol(new_env) && new_env == ENC_SYM_NOT_FOUND) {
|
||||||
|
@ -2068,8 +2067,10 @@ static lbm_value perform_setvar(lbm_value key, lbm_value val, lbm_value env) {
|
||||||
lbm_set_error_reason((char*)lbm_error_str_variable_not_bound);
|
lbm_set_error_reason((char*)lbm_error_str_variable_not_bound);
|
||||||
error_at_ctx(ENC_SYM_NOT_FOUND, key);
|
error_at_ctx(ENC_SYM_NOT_FOUND, key);
|
||||||
}
|
}
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
return res;
|
error_at_ctx(ENC_SYM_EERROR, ENC_SYM_SETVAR);
|
||||||
|
return ENC_SYM_NIL; // unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
static void apply_setvar(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
static void apply_setvar(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
||||||
|
|
Loading…
Reference in New Issue