libera/#commonlisp - IRC Chatlog
Search
13:35:32
tfeb
Yes, I set up sly and slime to do that but I forget how (but it's not in any lisp-side inits I have in git, and I can't see my emacs-side inits from here)
13:36:45
nij-
And I'm being extremely lazy on my emacs config.. currently using doom, which automatically does many magics tooo..
14:11:34
beach
It could have been created using MAKE-SYMBOL, or from UNINTERN of a previously interned symbol.
14:11:55
lisp123_
Perhaps I should then store gensyms into a global list upon creation and then check against that?
14:13:44
lisp123_
In 'On Lisp', PG suggests one could use genysm as a value for failing a test, if I were to go down that route, I would need to be able to check that the return value was a gensym created during the process and hence a failure
14:15:39
lisp123_
Yeah it seemed strange to me as well. A condition may work, I will have to play around with it
14:19:31
pjb
lisp123_: (let ((eof (gensym))) (eql eof (with-input-from-string (input "") (read input nil eof)))) #| --> t |#
14:20:31
pjb
lisp123_: (let ((eof (gensym))) (with-input-from-string (input "#:foo") (let ((foo (read input nil eof))) (list (eql foo eof) (symbol-package foo))))) #| --> (nil nil) |#
14:21:06
pjb
lisp123_: (let ((eof 42)) (with-input-from-string (input "42") (eql eof (read input nil eof)))) #| --> t |# WRONG!
14:21:45
pjb
the point of the guard value is to make sure it cannot have been used in the data structure for anything else.
14:23:00
pjb
We could as well use (let ((eof (cons nil nil))) …) or any other unique object identity.
14:24:33
pjb
(let ((eof (gensym))) (let ((data (with-output-to-string (out) (prin1 eof out)))) (print data) (let ((obj (with-input-from-string (inp data) (read inp nil eof)))) (list obj (eql eof obj))))) #| "#:g12402" --> (#:g12402 nil) |#
14:25:30
pjb
ldb: you wouldn't write an eof guard, you would just truncate the file. But you could write another guard object in some data structure, as long as you keep a reference to it, and ensure its identity is not lost by the serialisation/deserialisation.
14:27:04
pjb
(let ((empty (gensym))) (let ((data (list 'foo empty 'bar empty))) (let ((*print-circle* t)) (prin1-to-string (cons empty data))))) #| --> "(#1=#:g12410 foo #1# bar #1#)" |#
14:28:54
pjb
this is only the initial one, to know which ## is empty. There could be other shared references.
14:42:40
jcowan
When I need a unique object, I usually use (copy-seq "End of file object"), which is self-documenting but guaranteed unique, even if the compiler merges identical string literals.
14:51:26
jcowan
This actually isn'tt realistic in Scheme, because Scheme has a distinguished eof-object which you can gett a hold of by calling (eof-object) and can be tested for with (eof-object? obj).
14:52:43
jcowan
It has the advantage of being of a distinguished type. So you could in CL declare a struct and call itts constructor once.
16:07:32
phoe
TIL that the reader macro for #\( cannot call READ-DELIMITED-LIST directly but must instead call something that handles the consing dot properly
16:38:03
pjb
jcowan: copy-seq is also suspicious. Try: (cons 'eof nil) or (list 'eof) as unique tokens.
16:39:20
pjb
I don't remember it in scheme. It's called copy-sequence in emacs lisp. (if you don't require 'cl)
16:40:44
pjb
nothing in r5rs ressembling copy-seq: https://groups.csail.mit.edu/mac/ftpdir/scheme-reports/r5rs-html/r5rs_14.html#SEC88 there's only string-copy.
16:41:24
pjb
Have a look at (intersection common-lisp emacs-lisp scheme) http://www.informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/intersection-r5rs-common-lisp-emacs-lisp/