Search
Thursday, 13th of January 2022, 0:19:31 UTC
0:49:52
nij-
Hello! Is it possible to define setf-expander that does file reading and writing on the file?: https://bpa.st/LMUA
0:51:29
nij-
Hmm what I typed cannot be possible. But this could:
0:51:32
nij-
(setf (getf (get-sexpr "/tmp/record.sexpr") :a) 8) ; => 8
0:59:21
_death
(defsetf get-sexpr write-sexpr)
1:18:25
nij-
Amazing. Thanks! I was trying (defun (setf ..)).
1:23:27
_death
that could also work
1:53:51
nij-
While it works, it's kinda leaky.. especially used with access:accesses.
1:54:42
nij-
I might try another way. Instead of defsetf, is there a way to monitor the value cell of a symbol, so that whenever the value cell is changed, we invoke a certain function?
1:56:36
_death
define-symbol-macro?
1:57:53
nij-
Does that help add a hook to the value cell watcher?
1:58:15
_death
no.. there's no standard hook for that
1:58:52
Catie
You could define a :before method on the (setf ...) function, but that only handles the case where it's mutated via setf
2:00:09
moon-child
(define-symbol-macro x '(get-x)) (let (x) (defun (get-x) x) (defun (setf get-x) (nx) (notify-about nx)))
2:01:03
nij-
Feels like dark magic. Lemme think..
2:02:08
nij-
Maybe I can use MOP for this too.
2:02:18
moon-child
could also do it without the symbol macro, and simply use get-x
2:02:19
moon-child
no magic required
2:03:49
nij-
I don't understand the syntax (defun (name) ..).
2:09:19
nij-
moon-child: Oh I see I think you mean: (let (x) (defun get-x () x) (defun (setf get-x) (nx) (setf x nx)))
2:10:36
moon-child
oh, oops, my bad, yes
2:11:08
moon-child
tired, and I was thinking about wrapping the parentheses around (setf get-x), my fingers got ahead of me
4:00:22
beach
Good morning everyone!
9:35:35
nij-
Those who have used accesses - while it is great to access a place given by a variable, it doesn't seem to be working for a general place form like this
9:35:40
nij-
(setf *X* '(:a 1)) (setf (access:accesses (nth *X* 0) :a :b) 10) ;; error
9:36:51
nij-
If I want to extend the behavior, I need to hack the function accesses to expand the inner forms, right? Is it possible in principle?
9:40:06
nij-
Grrrr stupid me. It should have been (nth 0 *X*).. please ignore.. :(
9:43:59
nij-
Ok.. without stupid mistake (hopefully), here's a case that's expected to work but not:
9:44:05
nij-
(setf *X* '((:a 1))) (setf (access:accesses (nth 0 *X*) :a :b) 10) ;; => error
9:44:36
nij-
It seems to be a complicated problem to expand (nested) setfable forms correctly.
9:56:17
pve
nij-: don't know about access, but it looks like you're trying to modify a quoted list
9:56:33
phoe
other than modifying a literal
9:56:52
phoe
first, (setf (access:accesses (nth 0 *X*) '(:a :type :plist)) nil) because it is 1 at the moment
9:57:10
phoe
then, (setf (access:accesses (nth 0 *X*) '(:a :type :plist) '(:b :type :plist)) 10) to push into the new plist
9:57:25
phoe
the error is because access is trying to treat 1 as a plist
9:57:36
phoe
because, seemingly, you tell it to treat it like a plist
9:59:27
phoe
seems that you need to maintain some sort of typing discipline while playing with
9:59:49
phoe
either that, or implement type errors in access itself - it should tell you that it cannot treat 1 as a plist
11:10:35
nij-
I see, phoe, that makes sense.
Thursday, 13th of January 2022, 12:19:31 UTC