freenode/#lisp - IRC Chatlog
Search
20:33:36
imjacobclark
Hello - I am trying to hook cl-json and MAKE-ARRAY up to get a JSON object printed to screen, however I keep running into Value #2A((("hello" . "world"))) is not of a type which can be encoded by ENCODE-JSON.
20:33:43
imjacobclark
This is the code I am trying... (print (json:encode-json (make-array '(1 1) :initial-contents '( (("hello" . "world") )))))
20:38:06
imjacobclark
Bike: so my main problem really is when passing encode-json a list that has a variable in it, the variable isn't evaluated, the variables name ends up in the JSON
20:38:15
imjacobclark
For example the following code... (json:encode-json '#( ((foo . (1 2 3)) (bar . path) (baz . #\!)) "quux" 4/17 4.25 ))
20:38:55
imjacobclark
Sorry, I'm learning Lisp and this is me trying to solve a real world problem in it
20:39:38
imjacobclark
Right I see - is there a way to get it to be evaluated? I was thinking make-array could do that
20:39:38
Bike
You could do, e.g., (json:encode-json (list foo 14)), and then encode-json will be passed a list with two elements, the first of which is whatever value the variable FOO has
20:41:37
Bike
'(a b) is the constant version of (cons 'a (cons 'b nil)), while '(a . b) is (cons 'a 'b)
20:42:29
jmercouris
imjacobclark: this will be a very useful chapter for you: http://www.gigamonkeys.com/book/they-called-it-lisp-for-a-reason-list-processing.html
20:42:56
imjacobclark
Still fighting with this example though, can't settle my mind until I get it working
20:43:04
imjacobclark
I've tried converting it to a list... (print (json:encode-json (list (("test" . (1 2 3))))))
20:44:00
Bike
You realize that "test" is a string, and not a symbol, so it doesn't mean a variable in any context?
20:44:05
imjacobclark
(json:encode-json '#( ((foo . (1 2 3)) (bar . path) (baz . #\!)) "quux" 4/17 4.25 ))
20:45:43
imjacobclark
yes variable, e.g in javascript I would do... let myvar = "test"... {"myKey": myvar};
20:46:28
White_Flame
man, sometimes the array types can be annoying. clack wants a (simple-array (unsigned-byte 8)), and flexi-streams output returns a (vector (unsigned-byte 8)). Simple-vector always uses element type T, so there's no "simple-vector" type that can be specialized to (unsigned-byte 8)
20:47:17
imjacobclark
a dotted pair - right... goes to read up on dotted pairs via http://www.gigamonkeys.com/book/they-called-it-lisp-for-a-reason-list-processing.html
20:47:43
Bike
White_Flame: i think the conversion is just (coerce flexi-streams-output 'simple-array), though.
20:56:47
White_Flame
Bike: yeah, I have the coerce in there; not sure if it actually performs a data copy. i would nope not, but the extra type checking is annoying in the inner core of I/O
20:59:15
_death
it does copy.. maybe flexi-streams should be fixed to return a (simple-array (unsigned-byte 8))
21:00:42
White_Flame
well, which "more defining" of a datatype, the fact that it's simple, or the fact that it's a vector?
21:33:57
whartung
while I can dispatch a generic function on a structure type, I can’t “inherit” from a structure, I need to recode them all as classes first in CLOS, right? (I have a bunch of structs and am just lazy enough to not convert them into defclass if I don’t have to)
21:54:45
whartung
so if I have (defstruct xxx a b c) and (defstruct (yyy (:include xxx)) x y z) and (defmethod m1 (arg1 xxx)) and (defmethod m2 (arg1 xxx)) and (defmethod m2 (arg1 yyy)), will those work as expected? Is there a relationship between xxx and yyy or is it simplty structural?
21:57:34
whartung
ah cool! Well, that makes it easy then — I don’t have to class-ify them then…Because I mostly want to specialize behavior, not structure. So I should be able to (defstruct xxx a b c) and then simply (defstruct (yyy (:include xxx))) and method dispatch should Just Work.
0:19:28
mfiano
Does anyone know how to use the type pattern in trivia, on arguments of a list, and also bind the arguments for use in the clause body?
1:24:08
jack_rabbit
Ahh, I see: https://github.com/pkhuong/string-case/commit/718c761e33749e297cd2809c7ba3ade1985c49f7
2:54:38
White_Flame
of course, for erlang-style mailbox based asynchronous message passing, there are libs in quicklisp
3:06:33
White_Flame
in the simplest case, (defmacro send (obj message) `(,(first message) obj ,@(rest message))), where the first element of the message is a generic function name
3:38:46
loke
I recall having an extended debate with someone on social media where it was claimed to me that “message passing” was a fundamentally different way to do object orientation. I desperately tried to get this person to explain exactly how it was different, other than a superficial syntactic different (and a difference in the way the actual technical working were explained to the programmer), but I never got any proper answer.
3:55:21
pillton
I am not sure about that. Alan Kay said "I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages ..." (http://www.purl.org/stefan_ram/pub/doc_kay_oop_en). I am probably misquoting.
3:58:42
pillton
Anyway, I'll shut up because I don't really know and because I have to go to a meeting.
4:01:54
mfiano
Is anyone really familiar with the trivia library? I cannot seem to figure out how to compose the 'struct/class' and 'place' patterns, such that I can match a struct and define symbol macros for their slots in the process. Thanks.
4:09:30
beach
MichaelRaskin: I don't know how feasible your idea of hooking Clordane up to SBCL is, but you gave me a similar, but different, idea. I can create a Cleavir-based compiler for SBCL that propagates source information to executable code and that adds the interaction code required by Clordane. Again, it won't be as fast as native SBCL, but it will me much easier than to wait for a native SICL executable.
4:15:28
beach
MichaelRaskin: It would still take some time to create Clordane and this Cleavir-based SBCL compiler, of course. But such a thing would allow me to debug SICL code in a very comfortable environment without having to deal with the additional problems of a native SICL executable.
4:16:27
beach
MichaelRaskin: So I will probably move Clordane closer to the top of the list of projects to work on.
5:12:55
asarch
bar and baz both have the foo function. How could I shado baz::foo instead of bar::foo?
5:14:03
beach
asarch: It is a bad idea to :USE packages other than COMMON-LISP. Use explicit package prefixes instead.
5:14:39
beach
asarch: your code will be much clearer, because the person reading it will know from which package the symbols came.
5:15:08
beach
asarch: Plus, if you find yourself needing two ::, then you are doing something wrong.
5:15:54
beach
It means you are violating the public protocol of those packages, OR that you didn't design those packages correctly (in case you are the author).
5:17:47
MichaelRaskin
beach: I thought a bit, and as long as you accept limitations about not being able to see return value of top-level eval-when, the rest seems very feasible and not too much work.
5:17:56
beach
If a package P is not yours and you do a :USE P, you expose yourself to future modifications of P. If, in the future, the author of P decides to add new functions to the public protocol(s), then your code could break with a conflicting-symbols error even though you have not changed anything.
5:19:37
MichaelRaskin
Probably the eval-when problem can be solved with a few tons of annoying special-casing.
5:20:32
jack_rabbit
asarch, So double colon references symbols interned by a package. Single colon can only be used to reference symbols *exported* by the package.
5:21:16
jack_rabbit
asarch, So packages export symbols they intend to be used. A library will export functions it wants library users to call, constants, variables, etc.
5:21:53
jack_rabbit
asarch, internal variables, functions, etc. that it doesn't want a user to use, it doesn't export.
5:22:21
jack_rabbit
asarch, So when using a package, you should (almost always) only use the exported symbols (single colon)
5:23:10
jack_rabbit
asarch, That's why beach said you're either doing something wrong, or the package creator did something wrong, if you're using the double colon to use non-exported symbols.
5:25:53
jack_rabbit
Oh, minor note. Symbols that can be accessed with a single colon can *also* be accessed with a double colon. It's just best practice to use the single colon.
5:26:31
asarch
(defpackage :bar (:use :common-lisp) (:export :foo)), (defpackage :baz (:use :common-lisp) (:export :foo)) <- I don't want to use :foo from baz in :asarch
5:28:06
jack_rabbit
asarch, packages have access to other loaded packages, even without :use'ing them.
5:29:02
asarch
If I do: (defpackage :asarch (:use :common-lisp :bar :baz)), I would conflict the REPL at the time when I use (foo), right?
5:29:55
jack_rabbit
<jack_rabbit> asarch, packages have access to other loaded packages, even without :use'ing them.
5:30:29
jack_rabbit
asarch, It's not like java or python, etc. where you have to import packages to have access to them.
5:30:30
asarch
(defpackage :asarch (:use :common-lisp)) <- But any other functions in bar or in baz would not be accessible
5:36:07
jack_rabbit
asarch, When you :use a package, it just imports all that package's symbols into the target package, so they can be used as if they were part of the target package.
5:37:04
jack_rabbit
That's what beach advised against. Using explicit package prefixes makes the code clearer, since you can tell at the call site where functions, etc. reside.
5:39:46
jack_rabbit
It makes sense once you get used to it. It's just a little different than a lot of common systems.