Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Lack of skill dictates economy of style. -- Joey Ramone


devel / comp.lang.lisp / Struggling with quasiquote in MAL

SubjectAuthor
* Struggling with quasiquote in MALnone
`- Re: Struggling with quasiquote in MALKaz Kylheku

1
Struggling with quasiquote in MAL

<nnd$4c13067b$794419b5@47771a6dba92075b>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Newsgroups: comp.lang.lisp
Subject: Struggling with quasiquote in MAL
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$4c13067b$794419b5@47771a6dba92075b>
Organization: KPN B.V.
Date: Fri, 04 Aug 2023 13:48:22 +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!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 30
Injection-Date: Fri, 04 Aug 2023 13:48:22 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1834
 by: none - Fri, 4 Aug 2023 11:48 UTC

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.

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.

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

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: Struggling with quasiquote in MAL

<20230804095414.168@kylheku.com>

  copy mid

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

  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: Struggling with quasiquote in MAL
Date: Fri, 4 Aug 2023 17:11:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <20230804095414.168@kylheku.com>
References: <nnd$4c13067b$794419b5@47771a6dba92075b>
Injection-Date: Fri, 4 Aug 2023 17:11:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="42a4086d1e45385610f8b9f4428b75ac";
logging-data="1435943"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OnPfxkhyoMNPapEKcCfjAxm5wyuc4Sh8="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:eCNRN0BUYz7IW1jx+gK0Va+rmtI=
 by: Kaz Kylheku - Fri, 4 Aug 2023 17:11 UTC

On 2023-08-04, albert@cherry.(none) (albert) <albert@cherry> 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 . <whatever>) 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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor