libera/#commonlisp - IRC Chatlog
Search
16:34:44
Shinmera
jackdaniel: CLASS-PRECEDENCE-LIST may fail if the class has not been finalised yet.
16:37:50
jackdaniel
even if so, I'd still call finalize-inheritance and then class-precedence-list (for aesthetics if not anything else) - if the class can't be finalized compute will also fail miserably
16:39:16
Shinmera
in real code, sure. in the context it was originall suggested; just to look at the resulting precedence at the repl; idk.
16:40:31
jackdaniel
that's why I've said "if not aything else [but aesthetics]" ,) I agree that this does not matter (aesthetics aside) when you want to look at the resulting precedence at the repl
16:45:02
jackdaniel
(sufficienly clever implementation would call finalize-inheritance when the slot is unbound)
18:41:03
piethesailor
I am getting an error trying to parse the JSON I get from a succesful api call
18:43:06
jackdaniel
I doubt that any json parser wants to concern itself with encodings and coercing to a string
18:50:52
Bike
i have never used drakma, but i can look at its manual, and it says that :decode-content relies on the Content-Encoding header in the webpage. so maybe you're not getting one.
18:50:52
jackdaniel
the thing is that you pass a vector (not a stream nor a string) to parsing functions
18:52:06
Bike
if you know the encoding used by some other means (like guessing) you can do babel:octets-to-string or something.
18:53:45
piethesailor
I suppose drakma isnt really giving me json though now that I think about it, right? I am getting a vector, 200, and then a property list.
18:54:47
Bike
maybe this hasn't been made clear to you, but what's happening is that drakma is giving you the actual bytes it got over the wire. it cannot decode those into a string without knowing the character encoding those bytes were made with.
18:59:07
piethesailor
Bear with me, this might be a nonsensical statement.. So then the vector is just a bytes over the wire and the plist is the common lisp representation of those bytes?
18:59:50
jackdaniel
the first value is the result (be it a string or a byte vector that needs to be decoded if it is not binary)
19:03:14
Bike
oh, even better, RFC 8259 specifies that json in the wild must be utf-8, so i guess that's why you're not getting a header - you're supposed to assume that from the MIME
19:04:33
Bike
so yeah, just throw it at babel:octets-to-string and hopefully it will work out (pretty sure UTF-8 is the default for babel)
19:07:56
piethesailor
Yeah that works! So let me regurgitate somethings to make sure I am understanding everything..
19:10:42
piethesailor
The drakma script returned, as jackdaniel mentions, a vector of bytes that is utf-8 encoded, the http return code 200 or "ok", and then the http headers in the form of a plist.
19:14:08
jackdaniel
generally if you bind a result with (let ((result (call-function))) ...) then you bind only the first result
19:14:43
jackdaniel
but you may do (multiple-value-bind (result return-code plist) (call-function) ...) then if the function returns more values then they are bound
19:20:49
Bike
well - basically computers are creatures of arithmetic - they only know about numbers. when you "send text" over a line, what actually happens is that your text is encoded into a series of numbers which are actually sent. for example in ASCII or UTF-8, "A" becomes 65, whereas in EBCDIC "A" becomes 193.
19:21:05
Bike
In this case you have received a bunch of numbers, but without knowing how they were encoded, you can't get the corresponding text back.
19:21:30
Bike
(fsvo of "actually sent", since the numbers become electrical pulses, etc. irrelevant details)
19:28:37
piethesailor
Nice! Thanks for the explanation, Bike. I am curious though. I now have json from that babel:octets-to-string, which I have parsed with yason:parse. the result is a hash-table
19:33:36
piethesailor
how do I access the information in the hash table? I know I can click on #<HASH-TABLE :TEST EQUAL :COUNT 8 {10045A6943}> and emacs opens a buffer with the information pretty printed, but I am getting nil for (gethash 'results *my-hash*)
19:34:25
minion
piethesailor: please look at pcl: pcl-book: "Practical Common Lisp", an introduction to Common Lisp by Peter Seibel, available at http://www.gigamonkeys.com/book/ and in dead-tree form from Apress (as of 11 April 2005).
19:35:06
jackdaniel
generally you may map over hash table (maphash (lambda (key val) (format t "~s :: ~s~%" key val)) *hash-table*)
19:39:22
louis77
piethesailor: btw. you should be able to right click on the object in emacs and select "Inspect"... at will show you the contents of the hash table
19:42:15
piethesailor
Yes! That does work. I am thinking of how to access those data points with code. So far jackdaniels suggestion of maphash prints first level information like: ' "ticker" :: "AAPL" "queryCount" :: 1 "results" :: (#<HASH-TABLE :TEST EQUAL :COUNT 9 {10045A70F3}>) '
19:43:25
piethesailor
but I suppose I want to get information in "results" which is i guess another hash table
20:04:59
paulapatience
piethesailor: you may be interested in https://github.com/AccelerationNet/access to faciliate access to elements in nested hash tables (and other data structures)
2:23:54
patrix
ok so I haven't built anything with CL in over 2 years, so I don't really remember *why* I disliked all the json libraries back then.. but I tried shasht yesterday and it was so smooth.. thanks to whoever made it :) (yitzi?)
2:54:36
Josh_2
I rewrote a critical part of my software system and it seems to have come together nicely. There was a lot of deleting and rewriting :joy:
3:39:56
patrix
Nice. I’m about to embark on some refactoring as well, though my project is only 2 weeks old haha