Nп/п : 26 из 93
 От   : Kaz Kylheku                         2:5075/128        04 авг 23 17:11:16
 К    : none) (albert                                         04 авг 23 20:18:19
 Тема : Re: Struggling with quasiquote in MAL
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230804095414.168@kylheku.com> 55f7fdb7
@REPLY:
2b504478
@REPLYADDR Kaz Kylheku <864-117-4973@kylheku.com>
@REPLYTO 2:5075/128 Kaz Kylheku
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <20230804095414.168@kylheku.com>
@RFC-References:

@TZUTC: -0000
@PID: slrn/1.0.3 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-08-04, albert@cherry.(none) (albert)  wrote:
> I`m busy with mal
https://github.com/kanaka/mal
> a dialect of lisp similar to lisp.
>
> Most types of objects evaluate to herself. number strings.
> quotation is necessary for lisp insists that the first item
> of a list is a function. All exceptions must be quoted.
>
> Suppose we adapt the rule, that we leave lists alone unless the
> first item is a function or a symbol that points to a function.

PicoLisp does this, if I recall correctly. For instance, because
in (1 2 3) 1 is not a function, (1 2 3) evaluates to itself.

If you`re implementing Mal, this is decide for you, I think.

> The expansion of quasiquote / splice-unquote / unquote
> suddenly becomes easy in this context.
> Switch to an environment where only quasiquote / splice-unquote / unquote
> are known. Evaluate. Then continue with the real evaluate.
>
> (quasiquote 1 "A" ( 1 2 3) unquote(a) b ) is to expand to
> (cons 1 (cons "A" (cons (1 2 3) (cons (eval a) ( cons b () ) )..)
> as a first step, contrary to a tricky choice of possibilities.

The unquoting splice still needs to be handled. To achieve
that you can give the operators this semantics

  (quasiquote a b c) ->   (append a b c)

  (unquote x)        ->   (list x)

  (splice x)         ->   x

However, we need all other arguments which are not unquotes
or splices to be turned into lists somehow:


  `(1 "A" (1 2 3) ,a ,@b)

  (quasiquote a "A" (1 2 3) (unquote a) (splice b))

  (append (list a) (list "A") (list (1 2 3)) (list a) b)

I don`t see how you can easily escape from quasiquote having to analyze
the interior according to its own rules, rather than just setting up
some environment.

One possibility might be:

  (quasiquote a b c) ->   (funny-list a b c)

Where funny-list lists all items except for specially
annotates ones. The special annotation is produced by splice.
We have:

  (unquote x)        ->   x

  (splice x)         ->   (cons `sys:splice x)

When funny-append sees an object like (sys:splice . whatever)
it will spread whatever into a list, and add the items
individually.


The only problem with this is that we are relying on this
specific funny-list run-time support function which has
to do a run-time check.

If the Lisp dialect has to handle dotted quotes and unquotes,
that is an issue also.


> (quasiquote 1 "A" ( 1 2 3) unquote(a) b ) is to expand to
Then your expression reduces to

  (append 1 "A" (1 2 3) a

>
> There is a hidden quotation in cons.
> I find that disenginuous.

No there isn`t, except for the one you have introduced here
whereby (1 2 3), which is (1 . (2 . (3 . nil))) in CL-like
dialects, is self-evaluating. You put the hidden quotation
into (1 . ) based on the rule that 1 is not
a function.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
--- slrn/1.0.3 (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    
                                                                                
В этой области больше нет сообщений.

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