mirror of https://github.com/rusefi/bldc.git
Squashed 'lispBM/lispBM/' changes from c097f5c6..15fd3dea
15fd3dea change order of arguments in take and drop 14d19c68 added tests of spawn 476845e4 fix bug in spawn argument handling git-subtree-dir: lispBM/lispBM git-subtree-split: 15fd3dea56f361967ba69e69a8e37026f33dcd0b
This commit is contained in:
parent
d664184ef8
commit
2e82399a2f
|
@ -1317,32 +1317,32 @@ The `apa` pair is now `(1 . 42)`.
|
|||
### take
|
||||
|
||||
`take` creates a list containing the `n` first elements of another list.
|
||||
The form of a `take` expression is `(take n-exp list-exp)`.
|
||||
The form of a `take` expression is `(take list-exp n-exp)`.
|
||||
|
||||
Example that takes 5 elements from a list:
|
||||
```clj
|
||||
(define ls (list 1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(take 5 ls)
|
||||
(take ls 5)
|
||||
```
|
||||
|
||||
In the example above, the result of `(take 5 ls)` is `(1 2 3 4 5)`.
|
||||
In the example above, the result of `(take ls 5)` is `(1 2 3 4 5)`.
|
||||
|
||||
---
|
||||
|
||||
### drop
|
||||
|
||||
`drop` creates a list from another list by dropping the `n` first elements of that list.
|
||||
The form of a `drop` expression is `(drop n-exp list-exp)`.
|
||||
The form of a `drop` expression is `(drop list-exp n-exp)`.
|
||||
|
||||
Example that drops 5 elements from a list:
|
||||
```clj
|
||||
(define ls (list 1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(drop 5 ls)
|
||||
(drop ls 5)
|
||||
```
|
||||
|
||||
Here `(drop 5 ls)` evaluates to the list `(6 7 8 9 10)`.
|
||||
Here `(drop ls 5)` evaluates to the list `(6 7 8 9 10)`.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -1943,7 +1943,7 @@ static void apply_spawn_base(lbm_value *args, lbm_uint nargs, eval_context_t *ct
|
|||
while (lbm_is_cons(curr_param) &&
|
||||
i <= nargs) {
|
||||
|
||||
lbm_value entry = cons_with_gc(lbm_car(curr_param), args[1], clo_env);
|
||||
lbm_value entry = cons_with_gc(lbm_car(curr_param), args[i], clo_env);
|
||||
|
||||
lbm_value aug_env;
|
||||
WITH_GC_RMBR(aug_env,lbm_cons(entry, clo_env),2, clo_env,entry);
|
||||
|
|
|
@ -1189,17 +1189,17 @@ static lbm_value fundamental_reg_event_handler(lbm_value *args, lbm_uint nargs,
|
|||
|
||||
static lbm_value fundamental_take(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
||||
(void) ctx;
|
||||
if (nargs != 2 || !lbm_is_number(args[0]) || !lbm_is_list(args[1]))
|
||||
if (nargs != 2 || !lbm_is_number(args[1]) || !lbm_is_list(args[0]))
|
||||
return ENC_SYM_TERROR;
|
||||
|
||||
return lbm_list_copy(lbm_dec_as_i32(args[0]), args[1]);
|
||||
return lbm_list_copy(lbm_dec_as_i32(args[1]), args[0]);
|
||||
}
|
||||
|
||||
static lbm_value fundamental_drop(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
||||
(void) ctx;
|
||||
if (nargs != 2 || !lbm_is_number(args[0]) || !lbm_is_list(args[1]))
|
||||
if (nargs != 2 || !lbm_is_number(args[1]) || !lbm_is_list(args[0]))
|
||||
return ENC_SYM_TERROR;
|
||||
return lbm_list_drop(lbm_dec_as_u32(args[0]), args[1]);
|
||||
return lbm_list_drop(lbm_dec_as_u32(args[1]), args[0]);
|
||||
}
|
||||
|
||||
const fundamental_fun fundamental_table[] =
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
(define ls '(1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(define sub-ls (drop 5 ls))
|
||||
(define sub-ls (drop ls 5))
|
||||
|
||||
(check (eq sub-ls '(6 7 8 9 10)))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
(define ls '(1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(define sub-ls (drop 10 ls))
|
||||
(define sub-ls (drop ls 10))
|
||||
|
||||
(check (eq sub-ls nil))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
(define ls '(1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(define sub-ls (drop 100 ls))
|
||||
(define sub-ls (drop ls 100))
|
||||
|
||||
(check (eq sub-ls nil))
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
(defun f (x) (+ x 1))
|
||||
|
||||
(defun g (x) (check (= (f x) (+ x 1))))
|
||||
|
||||
(spawn 20 g 100)
|
|
@ -0,0 +1,5 @@
|
|||
(defun f (a b c) (list a b c))
|
||||
|
||||
(defun g (a b c) (check (eq (f a b c) (list 1 2 3))))
|
||||
|
||||
(spawn 20 g 1 2 3)
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
(defun f (x) (+ x 1))
|
||||
|
||||
(defun g (x) (check (= (f x) (+ x 1))))
|
||||
|
||||
(spawn g 100)
|
|
@ -0,0 +1,5 @@
|
|||
(defun f (a b c) (list a b c))
|
||||
|
||||
(defun g (a b c) (check (eq (f a b c) (list 1 2 3))))
|
||||
|
||||
(spawn g 1 2 3)
|
|
@ -1,5 +1,5 @@
|
|||
(define ls '(1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(define sub-ls (take 5 ls))
|
||||
(define sub-ls (take ls 5))
|
||||
|
||||
(check (eq sub-ls '(1 2 3 4 5)))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(define ls '(1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(define sub-ls (take 100 ls))
|
||||
(define sub-ls (take ls 100))
|
||||
|
||||
(check (eq sub-ls ls))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(define ls '(1 2 3 4 5 6 7 8 9 10))
|
||||
|
||||
(define sub-ls (take 0 ls))
|
||||
(define sub-ls (take ls 0))
|
||||
|
||||
(check (eq sub-ls nil))
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
|
||||
(check (eq (take 100 (iota 1000)) (iota 100)))
|
||||
(check (eq (take (iota 1000) 100) (iota 100)))
|
||||
|
|
Loading…
Reference in New Issue