Implementing mal according to https://github.com/kanaka/mal
I have problems with the implementation of apply.
(apply symbol? (list two) )
should give true, but this test fails.
This is the description with MAL.
apply: takes at least two arguments. The first argument is a function
and the last argument is a list (or vector). The arguments
between the function and the last argument (if there are any) are
concatenated with the final argument to create the arguments that
are used to call the function. The apply function allows a
function to be called with arguments that are contained in a list
(or vector). In other words, (apply F A B [C D]) is equivalent to
(F A B C D).
There is no mention that it is a special function. So all the arguments
of apply are evaluated.
I imagine myself as a naive user.
A naive user would apply to a list with the non-interned symbol two.
(apply symbol? (two) )
This doesn't work. (two) is not a list, but a call.
We must do.
(apply symbol? (list two) )
But again list is not a special function. It evaluates its arguments.
In order to have a list that contains the symbol `` two ''
we must do:
(apply symbol? (list (quote two))
We arrive at the list to be evaluated
(<#4623388> <two>) where #4623388 is the actual function symbol? refers to.
This is an abstract structure tree: a list consisting of a a function
and a symbol.
Now we are supposed to evaluate this list.
symbol? is not a special function. So we evaluate its arguments :
`` two ''.
Bang! ERROR 8010.
8010 : Symbol not in environment
My test succeeds if we
(def! two 2)
2
(apply number? (list two) )
true
I cannot reasonably interpret the specification such that the
given test succeeds.
(apply symbol? (list (quote(quote two)))
gives true if I test it.
(apply symbol? (list (quote two))
We arrive at the list to be evaluated
(<#4623388> <two>) where #4623388 is the actual function symbol? refers to.
This is an abstract structure tree: a list consisting of a a function
and a symbol.
Now we are supposed to evaluate this list.
On 2023-09-21, albert@cherry.(none) (albert) <albert@cherry> wrote:What we do with #<4623388>, is that not called evaluation?
(apply symbol? (list (quote two))
We arrive at the list to be evaluated
(<#4623388> <two>) where #4623388 is the actual function symbol? refers to. >>
This is an abstract structure tree: a list consisting of a a function
and a symbol.
Now we are supposed to evaluate this list.
No, that would be a double evaluation.
In a Lisp-1 dialect,
(apply fun (list a b c))
is the same as
(fun a b c)
You're talking about:
((eval fun) (eval (list a b c)))
apply is an ordinary function. After evaluating the arguments
we have these items
(#<4580123> #<4623388> (two))
^ ^
apply symbol?
we are now ready to call the function: we call #<4580123>,
which is apply, passing it #<4623388> and (two).
apply doesn't eval anything: apply takes the list (two) and spreads
it into individual arguments, which are passed to #<4623388>.
The expectation that (apply symbol? (list two)) will yield
true requires either very weird semantics that depart far from
classic Lisp, or else that two is a variable which holds a symbol.
Kaz--
Implementing mal according to https://github.com/kanaka/mal
I have problems with the implementation of apply.
(apply symbol? (list two) )
should give true, but this test fails.
Groetjes Albert--
On 2023-09-21, albert@cherry.(none) (albert) <albert@cherry> wrote:
(apply symbol? (list (quote two))
We arrive at the list to be evaluated
(<#4623388> <two>) where #4623388 is the actual function symbol? refers to. >>
This is an abstract structure tree: a list consisting of a a function
and a symbol.
Now we are supposed to evaluate this list.
No, that would be a double evaluation.
In a Lisp-1 dialect,
(apply fun (list a b c))
is the same as
(fun a b c)
You're talking about:
((eval fun) (eval (list a b c)))
apply is an ordinary function. After evaluating the arguments
we have these items
(#<4580123> #<4623388> (two))
^ ^
apply symbol?
we are now ready to call the function: we call #<4580123>,
which is apply, passing it #<4623388> and (two).
apply doesn't eval anything: apply takes the list (two) and spreads
it into individual arguments, which are passed to #<4623388>.
--Kaz
In article <20230921065214.723@kylheku.com>,
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
On 2023-09-21, albert@cherry.(none) (albert) <albert@cherry> wrote:What we do with #<4623388>, is that not called evaluation?
(apply symbol? (list (quote two))
We arrive at the list to be evaluated
(<#4623388> <two>) where #4623388 is the actual function symbol? refers to.
This is an abstract structure tree: a list consisting of a a function
and a symbol.
Now we are supposed to evaluate this list.
No, that would be a double evaluation.
In a Lisp-1 dialect,
(apply fun (list a b c))
is the same as
(fun a b c)
You're talking about:
((eval fun) (eval (list a b c)))
apply is an ordinary function. After evaluating the arguments
we have these items
(#<4580123> #<4623388> (two))
^ ^
apply symbol?
we are now ready to call the function: we call #<4580123>,
which is apply, passing it #<4623388> and (two).
apply doesn't eval anything: apply takes the list (two) and spreads
it into individual arguments, which are passed to #<4623388>.
I attached the property that a procedure is special or normal
to the underlying procedure of `symbol? not to `symbol? itself.
Is that correct?
In article <20230921065214.723@kylheku.com>,
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
On 2023-09-21, albert@cherry.(none) (albert) <albert@cherry> wrote:
(apply symbol? (list (quote two))
We arrive at the list to be evaluated
(<#4623388> <two>) where #4623388 is the actual function symbol? refers to.
This is an abstract structure tree: a list consisting of a a function
and a symbol.
Now we are supposed to evaluate this list.
No, that would be a double evaluation.
That clears up nothing to me.
lisp does double evaluations all the time.
Suppose you have `fx a user defined function.
(fx 1 2)
The first item of the list is not a function, we are not happy thus:
step 1 evaluate fx, the result is a list.
The first item of the list is not a function, we are not happy thus:
step 2 evaluate the list, the result is a function
Now we are in a position to tackle (#111 1 2)
Is that not a third evaluation then what is it?
In a Lisp-1 dialect,
(apply fun (list a b c))
is the same as
(fun a b c)
You're talking about:
((eval fun) (eval (list a b c)))
apply is an ordinary function. After evaluating the arguments
we have these items
fun is a symbol. It *got* to be evaluated, if we want the underlying function. What am I missing here?
(#<4580123> #<4623388> (two))
^ ^
apply symbol?
we are now ready to call the function: we call #<4580123>,
which is apply, passing it #<4623388> and (two).
apply doesn't eval anything: apply takes the list (two) and spreads
it into individual arguments, which are passed to #<4623388>.
I managed to
(apply symbol? (list (quote two)))
to succeed giving true,
passing the symbol `two to the now disembodied symbol?
by relying on functions in the underlying implementation language.
That is no solution, you can't pass arguments in lisp!
You can only evaluate lists, or more precisely you got to put
the function and arguments into a list
The following tests now fails:
;; Testing apply function with user functions
(apply (fn* (a b) (+ a b)) (list 2 3))
You can abstract the fn* in a disembodied function #1222
but it is supposed to be in a list, such as
(#1222 3 4) otherwise the function can not find its arguments
to fill it in on the places a and b.
Now the story goes on. #1222 doesn't know better better than to
evaluate its arguments and the problem only shifts.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 299 |
Nodes: | 16 (2 / 14) |
Uptime: | 26:26:09 |
Calls: | 6,681 |
Calls today: | 4 |
Files: | 12,222 |
Messages: | 5,342,288 |
Posted today: | 2 |