freenode/lisp - IRC Chatlog
Search
1:57:06
Xach
sjl: when i am faced with problems like that, i deal only with binary streams but make it easy to express the ascii codes as characters to be translated to code for parsing.
1:58:09
sjl
which brings me back to my request: how do I detect that they've given me what I've asked for, so I can fail with a nice error message if they don't
1:58:43
Xach
so, a character, a bare code, or a symbolic thingy could match, but obviously only against an integer underneath
1:58:49
sjl
I could live with (assert (stream-supports-binary-ops-p ...) ...) at the beginning of the function
1:59:13
sjl
but I don't want someone to pass a character input stream and get a stack trace from wherever the hell my first `read-byte` function call happens to be
2:00:04
sjl
I was hoping either flexi-streams or trivial-gray-streams might have something, but couldn't find anything
2:01:16
Xach
it's basically a way to get rainer joswig to dig into it, or sam steingold, or a handful of other prolific commenters who aren't usually here.
2:03:02
Xach
sjl: i like the noble goal of a nice direct error like "use a binary stream" but it feels somewhat out of reach to me in this situation
2:03:16
sjl
Streams are used all over the place in CL -- I don't want to have to force users to figure out how to use some weird byte-reading interface
2:04:06
pjb
sjl: this is idiotic. Will you be able to parse the image if the stream is a binary stream of (unsigned-byte 3)?
2:05:37
Xach
sjl: one thought is you could try to read the magic with a read-byte and if it fails, try a read-char, and if that succeeds signal a nice error of some sort.
2:05:59
dmiles
well one thing that is possible (thinking about what pjb is saying) is that you might be able to create a small sanity test for the stream type you get provided and test if certain bytes come back accurate based on a file that you know what should be therer
2:07:05
pjb
sjl: the point is that it's not up to your client to choose the stream type! You must open the file yourself using the kind of stream you want!
2:07:17
Xach
there are a handful of reasons read-byte could fail, so it would be speculative to mention non-binary-ness
2:08:18
pjb
sjl: alternatively, you could parse a in-memory string (or byte vector), and let the client do the I/O.
2:08:59
dmiles
ahah, what pjb said is really agood idea.. copy the stream data to a stream you know the details of
2:09:09
pjb
It's always a good idea to separate the concerns and avoid doing the I/O in the processing code.
2:09:21
sjl
sure, I could provide alternative interfaces. But it should also be able to take an input stream. What if they've implemented their own kind of stream (via trivial-gray-streams) and want to use its functionality?
2:10:39
sjl
I can't avoid interleaving the processing and the reading -- I need to know how much data to read, which is encoded partway through the file header
2:10:54
dmiles
(though i guess is just getting the stream copied correctly is the basic underlying problem)
2:10:56
sjl
I'm not just gonna copy the entire stream contents into a buffer or something. There could be more things in the stream after the file
2:12:39
dmiles
*not* what i am wondering is if you wanted to copy the data out of the stream is even really possible
2:13:16
sjl
Xach: I read an article somewhere that mentioned them, and they seem like a simple way to get graphics in/out, using e.g. imagemagic to reencode at the boundaries
2:13:40
Zhivago
sjl: Presumably you don't care about streams -- just about reading the next N bytes -- so why not just provide a function which does that?
2:14:31
sjl
Zhivago: I care about providing a simple interface to the user, not working around the streams problem by making them provide a function
2:14:42
dmiles
Zhivago: i assume slj is wanting to be able to in most cases be able to extract which accessor will make sense
2:14:58
sjl
I want them to say (read-ppm-from *standard-input*) not (read-ppm-with (alexandria:curry #'read-byte *standard-input*))
2:18:21
Zhivago
sjl: You have stream-element-type which should allow you to automatically select an appropriate accessor, no?
2:19:28
sjl
Zhivago: I want to ensure binary streams, but not exclude bivalent streams like sbcl's standard-input
2:19:33
Xach
it did give me some lemonodor-fame over 10 years ago though! http://lemonodor.com/archives/2004/06/flashy.html
2:22:29
dmiles
actualy what almost sounds reasonable is for the user to &key stream-type for bivaliant streams
2:23:12
sjl
I think Xach's idea of trying to read the magic byte with read-byte first is a good compromise
2:32:12
dmiles
i would have expected the user to use the wrong type of stream even out of no choices so reading for a magic would be required most cases
2:47:59
dmiles
in a program i work with, a user supplies concatenated ascii and binary mixed from FASLs over a socket opened as either ascii or binary .. so in most transmitions i must change the element types based on some headers and even then they tend to lie
3:03:05
Zhivago
dmiles: Just imagine how much simpler it would have been if they couldn't do that. :)
7:19:59
fiddlerwoaroof
So, I've noticed there's been a lot of talk about abandoned libraries and libraries that are about to be abandoned.
7:20:40
fiddlerwoaroof
I'd love to be able to be able to help maintain some libraries, but I don't have much spare time these days
7:56:33
Fare
so no big breakage expected. Actually, Xach and stassats will probably be relieved that I'm not there anymore... unless someone even more radical than I replaces me, of course.
8:35:36
jackdaniel
code doesn't belong to "self-documenting" type either, so maintaining it would require some motivation and time
12:09:30
dmiles
if someone use LABELS at the toplevel of a file, are these declared in the global environment?
12:13:35
jackdaniel
so if you define functions A and B in labels and you call B from A, it will call this B you have defined
12:14:11
jackdaniel
if you define them in flet, then it will call B from the environment in which you put flet/labels
12:15:12
jackdaniel
try (defun a () (pring "hi!")) ; (labels ((a () (print "hi from labels!")) (b () (a))) (b)) ; (flet ((a () (print "hi from flet!")) (b () (a))) (b))
12:21:57
elonopea
anyone know how to turn off auto-repeat-mode in CLX for the duration the program is running, and then ensure it's turned back on before gracefully exiting? I currently have the auto-repeat-mode turned off globally before the loop, and turn it back on on a key-release event, but this doesn't work unless I return nil from the key-release clause. if I close/destroy the window/display within the key-release clause, auto-repeat-mode gets
12:23:14
elonopea
I then issue Abort and get back to REPL with key repeat back on, but how to do this cleanly?
12:24:03
elonopea
sorry, auto-repeat-mode gets turned ON if I destroy the screen/display within the clause
12:25:43
elonopea
I thought I could just add the call to turn auto-repeat-mode off into the key-release event clause (within event-case) as that would return T, but although the program exits auto-repeat-mode stays off
12:28:57
elonopea
I'm not sure how to go about this. yes, key repeat remains off globally in X after the program exits.
12:31:50
elonopea
here is the code: https://pastebin.com/UTq1FXRr (sorry about horrid indentation, comments and stray parens, I've been moving stuff around in desperate attempt to fix this)
12:32:36
jackdaniel
I would appreciate if you could fix the indentation before I try to tread the code
12:51:12
elonopea
jackdaniel: https://pastebin.com/7qLiWsrq - hopefully better, though not necessarily perfect by the book...
12:54:22
elonopea
apparently sneaked in an indent inconsistency with the key-repeat declarations. I've been splitting the keywords on separate lines for clarity, and try to condense when I think I'm done twiddling with them
12:57:52
elonopea
jackdaniel: when I release key 's', the key-repeat is turned back on, but it throws me into debugger: https://pastebin.com/Nv6un6Yv
12:59:22
elonopea
I tried to put it after the event-case form, but it never changed the key-repeat, so when I get back to REPL it's off
13:00:45
elonopea
same if I only leave the change-keyboard-control call to turn repeat back on inside the key-release clause within event-case, then the program exits but key-repeat is still off. I don't get it to be honest.
13:02:29
jackdaniel
btw, what clx do you use? I see `require' call – what is your lisp implementation?
13:03:27
elonopea
with the current code, key-repeat is on (as supposed), but it throws me into the debugger. I don't really understand the event handling well, seems like it's async and I don't know how to bring the whole thing down in controlled manner
13:04:12
elonopea
the xembed is for something else entirely, it's from quicklisp. not sure if I even need it (for something else I'm doing)
13:15:38
elonopea
alright, thanks... I've been reading the manual but frankly the lack of examples is killing me. even google has been quite unhelpful on this particular topic and I've had to resort to somewhat unrewarding studying of random (mostly uncommented) code
13:16:35
jackdaniel
when you grok it, and if you are willing to spend some time, you could write a tutorial for CLX
13:22:14
elonopea
I glanced at it but often my problem with reading other people's CL sources is the (IMO) over-eager abstraction... people toss way too many layers upon layers of code for the sake of making everything general, tidy and purpose-built, but hiding the simple and obvious logic and structure in the process. or that's how I often feel. when I'm trying to get friendly with a new API I appreciate really, really stupid code that I can then h
13:23:30
elonopea
anyway I'm going to take a more careful look at the demos now... if I get somewhere with this stuff I'll take the tutorial into consideration :-)
13:29:25
pjb
elonopea: on the other hand, I don't find that most lisp code is too high level or abstracted at all; on the contrary, I find it rather rare to find multi-layered abstraction levels. The reason being that it's costly to produce (in time and IQ).
13:29:47
|3b|
Shinmera: isn't that a protocol problem, so clients can at best be "more conservative" rather than "not broken"?
13:30:38
Shinmera
|3b|: There is a way to make it perfect, but even just having an arbitrary limit that is low enough to not just split your messages is better than trimming your messages and not realising.
13:30:58
pjb
elonopea: you may want to read/study sicp Structure and Interpretation of Computer Programs http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/