Nп/п : 92 из 93
 От   : Bipolar Transistor                  2:5075/128        24 сен 23 18:51:42
 К    : All                                                   24 сен 23 20:53:02
 Тема : Re: First-class functions and macros
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> 68467934
@REPLY: <87ilea50ce.fsf@axel-reichert.de>
ce1e3386
@REPLYADDR Bipolar Transistor
<yeoldeosciloscope@gmx.com>
@REPLYTO 2:5075/128 Bipolar Transistor
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References:
<87ilea50ce.fsf@axel-reichert.de>
@TZUTC: 0100
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:102.0)
Gecko/20100101 Thunderbird/102.15.1
@TID: FIDOGATE-5.12-ge4e8b94
On 05.04.2023 07:06, Axel Reichert wrote:
> Hello,

> both first-class functions and macros are very powerful features. When
> learning Lisp I especially loved the former and started to use them very
> often. I am still working towards becoming a macro writer/user. One
> thing that puzzled me:

>    (defun square (n)
>      (* n n))

>    (mapcar #`square (list 1 2 3 4))

> works fine and returns (1 4 9 16). But why cannot macros be used like
> first-class functions?

>    (defmacro cube (n)
>      (* n n n))

>    (mapcar #`cube (list 1 2 3 4))

> gives

>    COMMON-LISP-USER::CUBE is a macro, not a function.
>       [Condition of type UNDEFINED-FUNCTION]

> instead of (1 8 27 64). (Of course, "cube" should be a function, not a
> macro, but this is just an example.)

> I might overlook something obvious to you, but my gut feeling is that
> there is a deep theoretical reason for this "limitation". Can anyone
> please sketch a brief explanation?

> Best regards

> Axel
What you are talking about here reminds me of fexprs. They were 
basically like functions, that, like macros, received their arguments 
unevaluated, but, unlike macros, it would actually be possible to pass 
them to higher order functions because they were, well, functions.
They were used in the old times of LISP 1.5, maclisp and interlisp, but 
were later ditched in favour of macros because they hindered 
compilation. If you want to look at something that developed in a 
differend direction, take a peek at the kernel language, or fexpress 
language for racket.
 --- Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
 * 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    
                                                                                
В этой области больше нет сообщений.

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