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
10:08:38
_death
in metacircular, the catch macro in catch/throw emulated by tagbody/go is missing a parenthesis :x
11:08:50
jackdaniel
speaking of terms, any volunteers for proofreading and testing the terminal access tutorial?
11:53:51
jdz
jackdaniel: If it's about moving cursor around and switching terminal to non-canonical mode count me in.
11:55:41
jdz
Besides the one ECL issue I already reported I'm having another one with receiving SIGWINCH.
12:20:00
adlai
ACTION tried reading all of `man 1 kill`, it is worse than eating a whole page of lsd
12:20:46
adlai
in case you are unfamiliar with the latter metaphor, it does not fit within a metabolic segment, and is thus slang for "way too much"
12:23:49
phoe
I kind of disbelieve that I have an urge to ask "what is a metabolic segment" in context of discussing LSD on #lisp
12:32:45
jackdaniel
jdz: please report it of course. and yes, it is about moving cursor and switching terminal to non-canonical mode
14:10:22
theseb
Is it necessary to sometimes explicitly use eval in your code? I've been racking my brain on little projects and it seems sometimes you *must* use an eval in your code?
14:12:00
theseb
Bike: i'm writing a for loop ...i can do it as a macro or function...in both cases i can't see how to get everything w/o eval
14:12:33
Josh_2
in the one case where I could have used eval, instead I just compiled the source code and called the function
14:12:34
Bike
assuming you mean something like C for, that executes some code in a loop until a condition is met.
14:12:52
theseb
Bike: i create macro that allows....(for i (3 5 6) ....) that executes ..... for i = 3, 5, 6
14:13:20
theseb
Bike: problem is sometimes I need to do (for i foo ...) where foo evaluates to a list
14:13:40
Bike
You don't need eval for that either, and you should decide whether your macro evaluates the list or not.
14:14:26
Bike
e.g., if you have (for x (get-list y z) ...), is that supposed to be a list of three elements GET-LIST, X, Z, or is it supposed to call the GET-LIST function?
14:14:56
theseb
Bike: but if i do that using a regular function...I need eval to actually eval the .... !!! AHHHH!!
14:15:29
Bike
or the evaluated version, (defmacro for (var list &body body) `(loop for ,var in ,list do (progn ,@body)))
14:16:16
phoe
once you solve that problem, please just quote your lists and use (for i '(3 5 6) ...)
14:17:49
Bike
the question is whether (gethash x y) is evaluated, or treated as a list of three symbols
14:18:15
Bike
this is part of the semantics of your macro, and unrelated to using eval or not to implement it
14:18:33
Bike
but just to emphasize, either way, you definitely don't need to use the eval function.
14:19:05
Bike
FOR is a macro. It can just expand into code that involves evaluating the form. You don't need to call eval yourself.
14:19:06
phoe
theseb: (let ((y (make-hash-table)) (x :some-key)) (setf (gethash x y) '(1 2 3 4 5)) (for i (gethash x y) (print i)))
14:19:41
theseb
Bike: i'll need to define for as a regular function so that it evaluates the arguments...hence...i would do (for 'i (gethash x y) '...)