Nп/п : 83 из 93
 От   : Spiros Bousbouras                   2:5075/128        21 сен 23 11:10:36
 К    : none) (albert                                         21 сен 23 14:13:05
 Тема : Re: Understanding apply in MAL (clojure dialect)
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <ylmfNUDgQTdj6gFU6@bongo-ra.co> 26b36b6e
@REPLY:
fe9d7b71
@REPLYADDR Spiros Bousbouras <spibou@gmail.com>
@REPLYTO 2:5075/128 Spiros Bousbouras
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <ylmfNUDgQTdj6gFU6@bongo-ra.co>
@RFC-References:

@TZUTC: -0000
@TID: FIDOGATE-5.12-ge4e8b94
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        )

> 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> ) 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
--- FIDOGATE 5.12-ge4e8b94
 * 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    
                                                                                
В этой области больше нет сообщений.

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