Closed ghost closed 3 years ago
You don't need apply... map is enough for what you are doing:
; pushes (1 4 9) on the stack
(1 2 3) (dup *) map
You don't need apply... map is enough for what you are doing:
; pushes (1 4 9) on the stack (1 2 3) (dup *) map
I know i don't need apply
but um... why isn't apply
working?
(1 2 +) apply ; -> (3)
(4 3 -) apply ; -> (1)
((1 2 3) (dup *) map) apply ; -> error
((1 2 3) (dup *) map) => ; -> error
Well... apply
works by evaluating each item in the quotation in a separate stack.
So here's what happens:
(1 2 3)
is evaluated, so 1, 2, and 3 are pushed on the stack:
(dup *)
is evaluated so dup and * are pushed on the stack:
map
is pushed on the stack:
(!) <repl>(1,20) [map]: Incorrect values found on the stack:
It's like writing 1 2 9 map
, which of course doesn't make much sense.
apply
is typically useful to evaluate symbols within a quotation:
1 :a
2 :b
3 :c
(a b c) apply ;outputs (1 2 3)
If you simply want to dequote the outer quotation, use dequote
or ->
:
quotation:
((1 2 3) (dup *) map) ->
; outputs: (1 4 9)
Well...
apply
works by evaluating each item in the quotation in a separate stack.So here's what happens:
- a new stack is created
(1 2 3)
is evaluated, so 1, 2, and 3 are pushed on the stack:
- stack: 1
- stack: 1 2
- stack: 1 2 3
(dup *)
is evaluated so dup and * are pushed on the stack:
- stack: 1 2 3 3
- stack: 1 2 9
finally,
map
is pushed on the stack:
- stack:
(!) <repl>(1,20) [map]: Incorrect values found on the stack:
- expected: quot quot map
- got: int map
It's like writing
1 2 9 map
, which of course doesn't make much sense.
apply
is typically useful to evaluate symbols within a quotation:1 :a 2 :b 3 :c (a b c) apply ;outputs (1 2 3)
If you simply want to dequote the outer quotation, use
dequote
or->
: quotation:((1 2 3) (dup *) map) -> ; outputs: (1 4 9)
I was playing with the builtin symbols of min v0.3.0 and then i found your (1 2 3 4 5) (dup *) map
example. I decided to try it within quotes. After that, i got this error that i presented it to you for solving it. Exactly, symbols are very confusy things.
But thanks so much!
or
Result are: