freenode/#lisp - IRC Chatlog
Search
8:59:31
solene
hello, I face an issue and I can't find a solution so here I am :) I reduced the whole thing to a few lines of code to try to figure out what's happening. when I read a file containing characters like ↓ , when I save that string into a file, sbcl adds 0x0 characters for each one found, and ecl adds 0x20 characters. I made an example easy to run here https://pastebin.com/pL0HiyGW
9:01:26
solene
sure no-defun-allowed , I didn't try it, only found :external-format :utf-8 but didn't help.
9:05:09
solene
I have this bug since years, I didn't notice it with ecl because spaces in an xml file wasn't an issue (but I'm not happy they are there) but when I switched to sbcl, adding 0x0 characters did break everything of course so I spotted that behavior.
9:05:28
no-defun-allowed
solene: I think that FILE-LENGTH is counting the number of bytes, not characters, in the file.
9:06:18
no-defun-allowed
But then READ-SEQUENCE reads in characters, leaving a gap at the end of the string.
9:06:46
no-defun-allowed
phoe: Compare the results of (make-string 20) on SBCL and ECL. SBCL fills it with (code-char 0), and ECL fills with spaces.
9:08:27
phoe
(coerce (load-file "test.txt") 'list) ;=> (#\DOWNWARDS_ARROW #\RIGHTWARDS_ARROW #\Newline #\Nul #\Nul #\Nul #\Nul)
9:08:34
no-defun-allowed
In this case, I would have expected FILE-LENGTH to count characters, but I think that would require decoding the file.
9:09:36
solene
I'd prefer to avoid external libraries, I use this in a 200 lines lisp program. But if this is the only way
9:10:12
phoe
https://gitlab.common-lisp.net/alexandria/alexandria/-/blob/master/alexandria-1/io.lisp#L53-71
9:18:49
solene
phoe, I switched to using alexandria from quicklisp. Less work and I guess I'll be able to live with this :) thank you very much phoe and no-defun-allowed
9:51:56
phoe
Only partially Lisp-related question: is it possible to get something equivalent to (lambda () (go :foo)) or (lambda () (return-from :bar 42)) in some of the currently-popular programming languages? We assume that these lambdas were established in suitable lexical environments within proper TAGBODY/BLOCK forms.
9:52:40
phoe
I'm thinking about this since I'm currently chewing on one comment related to my book that touches this topic.
9:55:27
phoe
I see, so instead of invoking a function that came from the provided lexical environment, one can emulate TAGBODY/BLOCK using an try-catch form, and transfer control via throwing that exception.
10:04:32
phoe
_death: I actually started re-reading that article moments before you posted it now; it was posted recently
10:05:17
_death
another good resource is the book Lisp in Small Pieces, which has a chapter about throw/catch