Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Totally illogical, there was no chance. -- Spock, "The Galileo Seven", stardate 2822.3


devel / comp.lang.lisp / how do I do setf over recursive function?

SubjectAuthor
* how do I do setf over recursive function?Bigos
+* Re: how do I do setf over recursive function?Bigos
|`- Re: how do I do setf over recursive function?Bigos
`- Re: how do I do setf over recursive function?Kaz Kylheku

1
how do I do setf over recursive function?

<fe8cfb28-056e-4858-9e2b-f32b810667ddn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:620a:4015:b0:6ce:beaa:3915 with SMTP id h21-20020a05620a401500b006cebeaa3915mr11716509qko.375.1663595801854;
Mon, 19 Sep 2022 06:56:41 -0700 (PDT)
X-Received: by 2002:a9d:666:0:b0:655:d979:8a6 with SMTP id 93-20020a9d0666000000b00655d97908a6mr8395927otn.200.1663595801602;
Mon, 19 Sep 2022 06:56:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 19 Sep 2022 06:56:41 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=80.3.9.155; posting-account=7RMTtAoAAAAl53cGsT2A48BtOsVJ7mF2
NNTP-Posting-Host: 80.3.9.155
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fe8cfb28-056e-4858-9e2b-f32b810667ddn@googlegroups.com>
Subject: how do I do setf over recursive function?
From: ruby.object@googlemail.com (Bigos)
Injection-Date: Mon, 19 Sep 2022 13:56:41 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 26
 by: Bigos - Mon, 19 Sep 2022 13:56 UTC

Can the following be done with setf?

(defun pht (obj &key (test 'eql) (size 7))
(alexandria:plist-hash-table obj :test test :size size))

(defun recpath (root path)
(if (endp path)
root
(recpath (gethash (first path) root) (rest path))))

(defun hashpath (root path)
(if (null (cdr path))
root
(hashpath (gethash (first path) root) (rest path))))

(defun try-me ()
(let ((dat (pht
(list
:windows (pht (list
:win1 'win1
:win2 'win2))))))
(recpath dat '(:windows :win1))
(let ((h (hashpath dat '(:windows :win1))))
(setf (gethash :win1 h) :win111))
(recpath dat '(:windows :win1))
))

Re: how do I do setf over recursive function?

<6ca7e2b6-ef4f-499e-94d9-94e93e679fe4n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:620a:4155:b0:6ce:3e56:c1e5 with SMTP id k21-20020a05620a415500b006ce3e56c1e5mr13663074qko.350.1663596275952;
Mon, 19 Sep 2022 07:04:35 -0700 (PDT)
X-Received: by 2002:a05:6808:1916:b0:350:92a3:1543 with SMTP id
bf22-20020a056808191600b0035092a31543mr3957148oib.200.1663596275728; Mon, 19
Sep 2022 07:04:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 19 Sep 2022 07:04:35 -0700 (PDT)
In-Reply-To: <fe8cfb28-056e-4858-9e2b-f32b810667ddn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=80.3.9.155; posting-account=7RMTtAoAAAAl53cGsT2A48BtOsVJ7mF2
NNTP-Posting-Host: 80.3.9.155
References: <fe8cfb28-056e-4858-9e2b-f32b810667ddn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6ca7e2b6-ef4f-499e-94d9-94e93e679fe4n@googlegroups.com>
Subject: Re: how do I do setf over recursive function?
From: ruby.object@googlemail.com (Bigos)
Injection-Date: Mon, 19 Sep 2022 14:04:35 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1248
 by: Bigos - Mon, 19 Sep 2022 14:04 UTC

I mean the fragment

(let ((h (hashpath dat '(:windows :win1))))
(setf (gethash :win1 h) :win111))

Re: how do I do setf over recursive function?

<84c31237-87fe-4487-867d-9820c5d1cff7n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:6214:23c6:b0:491:99e3:80ce with SMTP id hr6-20020a05621423c600b0049199e380cemr14808603qvb.111.1663597397182;
Mon, 19 Sep 2022 07:23:17 -0700 (PDT)
X-Received: by 2002:a05:6870:178b:b0:12b:c621:b7a9 with SMTP id
r11-20020a056870178b00b0012bc621b7a9mr16222028oae.41.1663597396913; Mon, 19
Sep 2022 07:23:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 19 Sep 2022 07:23:16 -0700 (PDT)
In-Reply-To: <6ca7e2b6-ef4f-499e-94d9-94e93e679fe4n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=80.3.9.155; posting-account=7RMTtAoAAAAl53cGsT2A48BtOsVJ7mF2
NNTP-Posting-Host: 80.3.9.155
References: <fe8cfb28-056e-4858-9e2b-f32b810667ddn@googlegroups.com> <6ca7e2b6-ef4f-499e-94d9-94e93e679fe4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <84c31237-87fe-4487-867d-9820c5d1cff7n@googlegroups.com>
Subject: Re: how do I do setf over recursive function?
From: ruby.object@googlemail.com (Bigos)
Injection-Date: Mon, 19 Sep 2022 14:23:17 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1937
 by: Bigos - Mon, 19 Sep 2022 14:23 UTC

what about the following? How do I writhe variant with setf?

(defun hashpath (root path)
(if (null (cdr path))
root
(hashpath (gethash (first path) root) (rest path))))

(defun set-hashpath (root path new-value)
(if (null (cdr path))
(progn
(setf (gethash (car path) root) new-value)
root)
(set-hashpath (gethash (first path) root) (rest path) new-value)))

(defun try-me ()
(let ((dat (pht
(list
:windows (pht (list
:win1 'win1
:win2 'win2))))))
(recpath dat '(:windows :win1))
(set-hashpath dat '(:windows :win1) "win 11111")

(recpath dat '(:windows :win1))
))

Re: how do I do setf over recursive function?

<20220919091626.179@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: how do I do setf over recursive function?
Date: Mon, 19 Sep 2022 17:41:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <20220919091626.179@kylheku.com>
References: <fe8cfb28-056e-4858-9e2b-f32b810667ddn@googlegroups.com>
Injection-Date: Mon, 19 Sep 2022 17:41:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d9e9b66613bf29f686db845c04a6ebf6";
logging-data="1281201"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18x+xT2ocNOgxQzOousRZ1WwDeoXVV8xHA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Kz26jG9qe+Av0B18BiFnJWdJaZg=
 by: Kaz Kylheku - Mon, 19 Sep 2022 17:41 UTC

On 2022-09-19, Bigos <ruby.object@googlemail.com> wrote:
> Can the following be done with setf?
>
>
> (defun pht (obj &key (test 'eql) (size 7))
> (alexandria:plist-hash-table obj :test test :size size))
>
> (defun recpath (root path)
> (if (endp path)
> root
> (recpath (gethash (first path) root) (rest path))))
>
> (defun hashpath (root path)
> (if (null (cdr path))
> root
> (hashpath (gethash (first path) root) (rest path))))

The quick and dirty way would be to provide another function:

(defun set-hashpath (root path new-value) ...)

Then the short form of defsetf:

(defsetf hashpath set-hashpath)

The disadvantage is that modify operations like
(incf (hashpath ...)) and (push whatever (hashpath ...))
walk the path twice.

To improve that you can have some way of retrieving
a locative value from the path:

(hashpath-loc root path)
(hashpath-get loc)
(hashpath-set loc)

Then (let ((loc (hashpath-loc root path))) (hashpath-get loc))
is equivalent to (hashpath root path), but we keep that
function.

You can then use define-setf-expander to register the
hashpath place in such a way that the expander uses the
location-based API. E.g. (incf (hashpath ...))
turns into code like this

(let ((#:loc0023 (hashpath-loc ...)))
(incf (hashpath-get #:loc0023)))

We could probably capture this whole pattern into
a simple defining facility where you specify
the the function for getting the loc from
the arguments, and the loc accessors.

Here is how that might go:

(defmacro define-loc-setf (name loc-constructor loc-getter loc-setter)
`(progn
(defsetf ,loc-getter ,loc-setter)
(let ((loc (gensym "LOC-"))
(store (gensym "STORE-")))
(define-setf-expander ,name (&rest args)
(values (list loc)
(list `(,',loc-constructor ,@args))
(list store)
`(,',loc-setter ,loc ,store)
`(,',loc-getter ,loc))))))

;; Test: define a path place (COOL-PATH args ...) for which we can obtain
;; a location using (COOL-PATH-LOC args ...) and then get/set via the location.
;; None of these functions exist; we can use this to verify that we
;; get a right-looking expansion.

(define-loc-setf cool-path cool-path-loc cool-loc-get cool-loc-set)

Now try expanding a for which increments a cool-path place:

[1]> (macroexpand '(incf (cool-path a b c d e)))
(LET* ((#:LOC-3318 (COOL-PATH-LOC A B C D E))
(#:STORE-3319 (+ (COOL-LOC-GET #:LOC-3318) 1)))
(COOL-LOC-SET #:LOC-3318 #:STORE-3319)) ;
T

Looks about right. The place arguments are passed to cool-path-loc,
and then the transaction is done with the loc accessors.

Caveat: I've not tested this beyond just looking at expansions.

Note: the cool-loc-set function must return the new value, otherwise the
result value semantics of setf and other operators breaks.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor