Nп/п : 88 из 93
 От   : Kaz Kylheku                         2:5075/128        22 сен 23 14:57:00
 К    : none) (albert                                         22 сен 23 17:59:04
 Тема : Re: Understanding apply in MAL (clojure dialect)
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230922073617.480@kylheku.com> f62c7ce5
@REPLY:
f8bde87c
@REPLYADDR Kaz Kylheku <864-117-4973@kylheku.com>
@REPLYTO 2:5075/128 Kaz Kylheku
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <20230922073617.480@kylheku.com>
@RFC-References:
<20230921065214.723@kylheku.com>

@TZUTC: -0000
@PID: slrn/pre1.0.4-9 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-09-22, albert@cherry.(none) (albert)  wrote:
> In article <20230921065214.723@kylheku.com>,
> Kaz Kylheku  <864-117-4973@kylheku.com> wrote:
>>On 2023-09-21, albert@cherry.(none) (albert)  wrote:
>>> (apply symbol? (list (quote two))
>>> We arrive at the list to be evaluated
>>> (<#4623388> ) 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.
--- slrn/pre1.0.4-9 (Linux)
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх