Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Cogito ergo I'm right and you're wrong." -- Blair Houghton


devel / comp.lang.lisp / Understanding apply in MAL (clojure dialect)

SubjectAuthor
* Understanding apply in MAL (clojure dialect)none
+- Re: Understanding apply in MAL (clojure dialect)Spiros Bousbouras
+* Re: Understanding apply in MAL (clojure dialect)Kaz Kylheku
|+* Re: Understanding apply in MAL (clojure dialect)none
||`- Re: Understanding apply in MAL (clojure dialect)Kaz Kylheku
|`* Re: Understanding apply in MAL (clojure dialect)none
| `- Re: Understanding apply in MAL (clojure dialect)Kaz Kylheku
`- Re: Understanding apply in MAL (clojure dialect)none

1
Understanding apply in MAL (clojure dialect)

<nnd$76e3788b$0d113101@627a67ea51c23339>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17501&group=comp.lang.lisp#17501

  copy link   Newsgroups: comp.lang.lisp
Newsgroups: comp.lang.lisp
Subject: Understanding apply in MAL (clojure dialect)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$76e3788b$0d113101@627a67ea51c23339>
Organization: KPN B.V.
Date: Thu, 21 Sep 2023 09:36:56 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 65
Injection-Date: Thu, 21 Sep 2023 09:36:56 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2726
 by: none - Thu, 21 Sep 2023 07:36 UTC

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.

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Understanding apply in MAL (clojure dialect)

<ylmfNUDgQTdj6gFU6@bongo-ra.co>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17502&group=comp.lang.lisp#17502

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: Understanding apply in MAL (clojure dialect)
Date: Thu, 21 Sep 2023 11:10:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <ylmfNUDgQTdj6gFU6@bongo-ra.co>
References: <nnd$76e3788b$0d113101@627a67ea51c23339>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 21 Sep 2023 11:10:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e0ee6be171a5aaedd1293dbffa14143e";
logging-data="3684375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19v2r4H/PYmK04TCGtcK5wQ"
Cancel-Lock: sha1:mYQ5mJ6pD2TKXsm6kpuEYlLz6Z8=
X-Server-Commands: nowebcancel
In-Reply-To: <nnd$76e3788b$0d113101@627a67ea51c23339>
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Thu, 21 Sep 2023 11:10 UTC

On Thu, 21 Sep 2023 09:36:56 +0200
albert@cherry.(none) (albert) wrote:
> 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).

Either the specification is inaccurate or MAL does things differently than
Common Lisp ; it is probably the former. Probably what it means is that

(apply F A B [C D]) is equivalent to doing the call
(F <value of A> <value of B> <value of C> <value of D>)

> There is no mention that it is a special function. So all the arguments
> of apply are evaluated.

Correct.

> 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.

True. Also I assume there is no variable named symbol? although there is
a function named symbol? .It could be of course that in MAL there is no
such distinction.So you do
(apply symbol? (quote (two)))
or
(apply (quote symbol?) (quote (two)))

depending on whether MAL is a Lisp 1 or Lisp 2.

> 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))

Your parentheses don't match. But you probably mean
(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 ; you are supposed to call function symbol? with 1 argument which is the
symbol two .In other words
(apply symbol? (list (quote two)))

is *not* the same as typing on the REPL

(symbol? two)

> 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.

If you had to jump through hoops like that , apply would be a lot
less useful. Hence I'm thinking that the MAL specification is inaccurate.

--
From a slasher to a comedy to a sci-fi, is there anything that this
franchise hasn't done? Yeah, a horror musical. Do that for twentieth
film in the franchise, if you can make it up to that point.
www.imdb.com/review/rw4741732

Re: Understanding apply in MAL (clojure dialect)

<20230921065214.723@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17503&group=comp.lang.lisp#17503

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Understanding apply in MAL (clojure dialect)
Date: Thu, 21 Sep 2023 14:02:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <20230921065214.723@kylheku.com>
References: <nnd$76e3788b$0d113101@627a67ea51c23339>
Injection-Date: Thu, 21 Sep 2023 14:02:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d3d54e4b74191d06bda8ef3fd3367eb7";
logging-data="3744855"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4aTaQeU0iQwWrhBK+xk6Z6aLBBfvYbQ0="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Gw9OXTu4MaFAX1HedqWPzpbYoQE=
 by: Kaz Kylheku - Thu, 21 Sep 2023 14:02 UTC

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>.

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.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Understanding apply in MAL (clojure dialect)

<nnd$274179f7$49c6b9ae@27bc456bc6ac13be>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17504&group=comp.lang.lisp#17504

  copy link   Newsgroups: comp.lang.lisp
Newsgroups: comp.lang.lisp
Subject: Re: Understanding apply in MAL (clojure dialect)
References: <nnd$76e3788b$0d113101@627a67ea51c23339>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$274179f7$49c6b9ae@27bc456bc6ac13be>
Organization: KPN B.V.
Date: Fri, 22 Sep 2023 10:39:40 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!94.232.112.246.MISMATCH!feed.abavia.com!abe006.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 32
Injection-Date: Fri, 22 Sep 2023 10:39:40 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2029
 by: none - Fri, 22 Sep 2023 08:39 UTC

In article <nnd$76e3788b$0d113101@627a67ea51c23339>,
none) (albert <albert@cherry.> wrote:
>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.

Sorry I have goofed.
The test in mal is actually,
(apply symbol? (list (quote two)) )

Kaz noticed that in his last line.

My conclusion is that `apply' is not a normal function but special.
It follows its own rules whether things should be evaluated.
The problem is that the last parameters is a list, and
I cannot pass a list without involking the (list..) construction
In my book that is an evaluation of the list procedure called
#2189218 whatever. So the second parameter is to be evaluated.

What I understand is that `symbol? has a bald underlying procedure.
`apply takes care that this procedure is called with the elements
of list.

>Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Understanding apply in MAL (clojure dialect)

<nnd$28e38fce$15eff6f7@d409c0977043e813>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17505&group=comp.lang.lisp#17505

  copy link   Newsgroups: comp.lang.lisp
Newsgroups: comp.lang.lisp
Subject: Re: Understanding apply in MAL (clojure dialect)
References: <nnd$76e3788b$0d113101@627a67ea51c23339> <20230921065214.723@kylheku.com>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$28e38fce$15eff6f7@d409c0977043e813>
Organization: KPN B.V.
Date: Fri, 22 Sep 2023 10:51:45 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 59
Injection-Date: Fri, 22 Sep 2023 10:51:45 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2532
 by: none - Fri, 22 Sep 2023 08:51 UTC

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.
>
>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>.
What we do with #<4623388>, is that not called evaluation?

I attached the property that a procedure is special or normal
to the underlying procedure of `symbol? not to `symbol? itself.
Is that correct?

>
>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.

That was a mistake. See my separate post.
(apply symbol? (list (quote two)))

>Kaz
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Understanding apply in MAL (clojure dialect)

<nnd$61abdae5$1800c6b7@9178d210cca8264b>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17506&group=comp.lang.lisp#17506

  copy link   Newsgroups: comp.lang.lisp
Newsgroups: comp.lang.lisp
References: <nnd$76e3788b$0d113101@627a67ea51c23339> <20230921065214.723@kylheku.com>
Subject: Re: Understanding apply in MAL (clojure dialect)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$61abdae5$1800c6b7@9178d210cca8264b>
Organization: KPN B.V.
Date: Fri, 22 Sep 2023 14:52:32 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 88
Injection-Date: Fri, 22 Sep 2023 14:52:32 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 3542
 by: none - Fri, 22 Sep 2023 12:52 UTC

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.

Groetjes Albert

>--
Kaz
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: Understanding apply in MAL (clojure dialect)

<20230922073617.480@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17507&group=comp.lang.lisp#17507

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Understanding apply in MAL (clojure dialect)
Date: Fri, 22 Sep 2023 14:57:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 100
Message-ID: <20230922073617.480@kylheku.com>
References: <nnd$76e3788b$0d113101@627a67ea51c23339>
<20230921065214.723@kylheku.com> <nnd$28e38fce$15eff6f7@d409c0977043e813>
Injection-Date: Fri, 22 Sep 2023 14:57:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="325231"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kwpORhbSTix/AaUbvUEAcy39N4D0GtZs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:IaDQL02UW3Giw/67RxGaUsZ7mNw=
 by: Kaz Kylheku - Fri, 22 Sep 2023 14:57 UTC

On 2023-09-22, albert@cherry.(none) (albert) <albert@cherry> wrote:
> 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.
>>
>>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>.
> What we do with #<4623388>, is that not called evaluation?

There are two apply calls here. One of them is conceptual (it need
not be literally done that way). When evaluation notices a function
form (f ...), conceptually, that can be handled via the apply function.
All constituent expressions are evaluated and then apply can be used
to call the function f with those arguments. That apply is part of
evaluation, as a subroutine.

Here we have (apply ...). So expressions are evaluated and arguents
are applied to the apply function.

That apply function is external; it has its own evaluations going on
inside but they are not part of the evaluation of the
(apply fun (list a b c)) expression.

We are not walking the syntax of the apply implementation; it could be
coded in machine langauge.

In any case, what apply does to the symbol? function is called
application.

> I attached the property that a procedure is special or normal
> to the underlying procedure of `symbol? not to `symbol? itself.
> Is that correct?

Not sure what you mean. In traditional Lisps, in fact the difference
between kinds of procedures in the evaluation model, like EXPR vs SUBR
in very old Lisp or macro expander versus ordinary function in Common
Lisp, those differences are not attached to the function, but to the
binding. A macro-expanding lambda doesn't know it's a macro-expanding
lambda.

apply isn't "special" in any way, except that implementations of apply
are usually privy to the implementation of functions. apply has to have
the know how to be able to take a function and list, and spread the list
into function arguments to which the function is applied.

If you take a Lisp dialect and remove apply (not necessarily remove it
physically, but make it inaccessible to programs) there may be no other
way for a program to bring back apply other than this:

(define (apply fun . args)
(eval `(,fun ,@args)))

We work around the missing apply by generating code and feeding it to
eval, which somehow knows how to apply functions to arguments.

Needless to say, the real apply doesn't have to do things via eval; it
can be a lower-level procedure (e.g. coded in machine language) which
knows how to manipulate function calls.

Since all we do is call apply in the same way as we call any other
function, there is nothing special about it from the caller's point of
view.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Understanding apply in MAL (clojure dialect)

<20230922075713.867@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17508&group=comp.lang.lisp#17508

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Understanding apply in MAL (clojure dialect)
Date: Fri, 22 Sep 2023 15:16:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 137
Message-ID: <20230922075713.867@kylheku.com>
References: <nnd$76e3788b$0d113101@627a67ea51c23339>
<20230921065214.723@kylheku.com> <nnd$61abdae5$1800c6b7@9178d210cca8264b>
Injection-Date: Fri, 22 Sep 2023 15:16:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="332195"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2b6K4/gms/illVU7meUJwDzCoKHNQc7s="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:LpLiZIeswVhJQ9XABpbhoVh0lHM=
 by: Kaz Kylheku - Fri, 22 Sep 2023 15:16 UTC

On 2023-09-22, albert@cherry.(none) (albert) <albert@cherry> wrote:
> 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.

Actually, no, not implicitly. If something is multiply evaluated, it's
because you coded extra evaluations into it.

> 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?

While that is possible, I don't know of any Lisp dialect which
does this kind of iteration.

The second and subsequent rounds of evaluation would be working
with run-time data: whatever value is pulled out of the fx binding.

Evaluating that would be a possible security issue.

Lisps are compiled languages; only the first evaluation round could be
compiled, unless the compiler can deduce the value of fx. Otherwise the
subsequent evaluation rounds would have to be promoted to run-time.

>>
>>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?

That once that takes place, the resulting #<4623388> object isn't
evaluated any more.

>
>>
>> (#<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!

Well, that's right; you can pass arguments in the implementation of
Lisp, such as inside primitive procedures like apply and funcall.

The classic description of Lisp eval in Lisp itself assumes that a
primitive procedure apply is available, which doesn't have to be
written.

That description itself is evalued somehow, by an existing
primitive eval. That eval somehow knows how to perform the function
calls that occur in the syntax of the eval-in-Lisp source code.

That eval-in-Lisp code itself knows how to to do the same thing,
via the apply helper function.

> 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.

#1222 should only need to access its arguments. In the body (+ a b), a
and b are just local variables that have been given values in by the
application of that function. Evaluating a just means retrieving the
value of a, not evaluating the original expression.

In a purely interpreted Lisp, a function's representation retains
the source code pieces, like the names of the arguments and the body
as-is (usually after macro-expansion).

The apply procedure, when it sees such an interpreted function, has to
perform the binding: extract the function object's list of parameter
names, and create an environment which binds them to the argument
values. Then it evaluates the body in that environment using an
evaluator. (That evaluator is not necessarily the one you are writing!)
If the funtion is compiled, or written in a lower level language by
hand, such as C or assembly, then the process of calling it may
be quite different. Apply has to generate a function call in that
language. It may involve pushing values on the stack, or preparing
them in registers, and getting a result value or values in a certain
way like from certain registers or on the stack.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor