freenode/#lisp - IRC Chatlog
Search
5:45:33
jackdaniel
russellw: maybe with (defun reference (array &rest subscripts) (if (apply #'array-in-bounds-p array subscripts) (apply #'aref …) (error (make-condition 'out-of-bounds))) ;?
5:46:21
jackdaniel
if you do not care about portability, you may of course reach to implementation conditions if they exist
5:47:26
jack_rabbit
I'd be surprised there's not some library somewhere that has implemented implementation-specific checks for these error conditions.
5:50:15
jack_rabbit
I'm sort of surprised that a specific error type isn't specified for out-of-bounds conditions.
5:50:45
russellw
hmm! What about something like opening a nonexistent file? Is there any way to catch that?
5:52:55
jackdaniel
if you want something more specifc, then I can only propose similar solution to the one proposed before
5:54:36
jackdaniel
or handle file-error, access fire-error-pathname, check it out with probe-file and signal your own condition if it does not exist (otherwise resignal condition you have received)
5:56:54
russellw
Suppose you are generating errors yourself - say writing a parser, that must signal errors. For that, you could use handle-case and define a suitable error, right? But is there a reason not to just use throw and catch instead? That would seem simpler?
5:59:52
russellw
Oh yes indeed, there is a nice tutorial about it at http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html and it's good that all those features are there for people who need them. But all I need is the ability to throw and catch errors :)
6:00:31
aeth
I should correct myself, type errors are warnings, not style-warnings. But not compilation errors, either.
6:00:41
jackdaniel
I have this: https://lisper.in/restarts but I'm not sure if this is the one I have remembered being so good
6:01:13
jackdaniel
if all you need is throw/catch, then you need a throw/catch and claiming otherwise would be denying a tautology ;-)
6:02:29
aeth
jack_rabbit: That's a flaw in the spec imo. It's really random what kind of error you could see for common things.
6:03:02
jackdaniel
I've been debugging McCLIM internal mechanism (one of the downstream functions which does not have access to the screen - no medium argument)
6:03:28
jackdaniel
and I wanted to display a rectangle of the pixarray size (without disrupting computation)
6:04:18
jackdaniel
so I've defined a display-rectangle-condition and signalled it from this function. it was handled higher on the call stack with handler-bind, rectangle was displayed and downstream function working has been continued after that
6:04:41
jackdaniel
when I didn't want to handle it I've simply removed handler bind and despite being signalled condition was ignored
8:35:47
phoe
I have a string containing bytes in hex. What is the agreed way to convert that into a ub8 array?
10:48:22
no-defun-allowed
If you want that, Haskell has that by default. Even their wiki admits that's a bad idea for big strings.
10:50:06
jackdaniel
nly: array representation and list representation are different things in common lisp, but both are sequences
10:50:29
jackdaniel
some CL implementations provide extension called "extensible sequences" as well, to define your own sequence types
10:55:14
_death
you can also coerce a string to a list of characters, though that's usually not what you should want
11:03:50
no-defun-allowed
I solved the problem of not having a Netfarm MOP yet by using a hash table as an intermediate form for schemas.
12:40:32
didi
So... if I call `with-open-file' with a filespec like "foo.png" and :direction :output, my implementation could generate an output stream with :element-type byte, right?
12:43:29
Josh_2
you could write a function that determines the filetype based on the extension and use that in place of 'unsigned-byte?
12:44:08
Bike
it's possible an implementation does that, but i wouldn't count on it. file type extensions are kind of unregulated, for one.
12:45:02
Bike
"The element-type specifies the unit of transaction for the file stream. If it is :default, the unit is determined by file system, possibly based on the file."
12:48:26
didi
Seems like a cool thing to do, tho I have no idea on how many things would break after such change.
12:50:48
scymtym
Bike: :default should actually mean bivalent as in (with-open-file (stream "/etc/motd" :direction :input :element-type :default) (list (read-char stream) (read-byte stream)))
12:57:34
didi
I hit the quote because I'm trying to use `uiop:run-program' to run a program that reads text from :input and outputs bytes to :output, but I'm struggling. Silly mismatching streams.
13:03:24
didi
`uiop:run-program' seems to apply :element-type to both streams, even if I supply a stream for :output.
13:07:08
didi
Hum, and according to SBCL manual, the same applies to `sb-ext:run-program': ‘:external-format’ The external-format to use for ‘:input’, ‘:output’, and ‘:error’ :STREAMs.
13:24:58
splittist
I like the example in stream-element-type of '(integer 0 1) to allow for (but not mandate) bitwise output (as it were)
13:26:46
didi
_death: What's the name of the construct that restrict evaluation of forms to certain compiler features?
13:29:10
_death
but there are better ways to do that.. for example have a file per implementation/platform and have a reader conditional or :if-feature (or whatever it's called) in the asdf definition
14:01:27
didi
How would you connect a function that writes to a stream and one that reads from a stream? I'm using a combination of `with-output-to-string', `make-string-input-stream', and `with-open-stream', but I feel there might be a better way.
14:14:53
_death
https://gist.github.com/death/2709ae6a9124968a86070bbb760b1629 for some sbcl-specific fun
14:17:17
didi
Ah, threads. I should have thought it. I think I kinda wished streams could accumulate stuff.
14:56:24
didi
How do I rewrite https://paste.debian.net/hidden/01f61fd9 to remove the duplicated `with-open-file'? I feel like I need `macrolet', but I can't figure it out. I don't want to always pass `if-exists' to `with-open-file' because it behaves differently whenever it receives `if-exists' or not.
14:59:18
Xach
didi: one option: instead of defaulting to NIL, default to the default value of if-exists
15:00:19
didi
Xach: The thing is, as far as I understand, there's no default value, because `with-open-file' behaves differently if it doesn't receive a value at all for :if-exists.
15:01:09
didi
"if-exists---one of :error, :new-version, :rename, :rename-and-delete, :overwrite, :append, :supersede, or nil. The default is :new-version if the version component of filespec is :newest, or :error otherwise. "