freenode/#lisp - IRC Chatlog
Search
20:27:54
Bike_
you could use a function that returns multiple values, or a macro replacing map, or any number of things
20:28:14
Bike_
which is why i asked what they're doing more specifically so i could maybe pick which direction seemed best
20:30:23
__rumbler31
I was confused about the context of the discussion at hand, so "at the time I was speaking about what I thought was a more general discussion"
20:52:36
pjb
fafff: you can write (map 'list (lambda (x y) (+ x y)) (k1)) on the condition of wrapping it into a normal (operator argument) form.
20:53:23
pjb
then you write the with-k1 macro, to analyse the sexp (map 'list (lambda (x y) (+ x y)) (k1)) and replace it with (map 'list (lambda (x y) (+ x y)) l1 l2)
20:54:42
pjb
fafff: now, if you have a list of list, for example returned by a function f1, you can write (apply (function map) 'list (function +) (f1))
21:05:47
pjb
But it may be a little violent. You may want to use a code walker to interpret (k1) correctly: (with-k1 (list (k1) (labels ((k1 () 'foo)) (k1)) (k1))) only the first and last (k1) must be substituted, the (k1) in the middle refers to the function k1 defined by labels.
21:47:27
stylewarning
"you may want to use a code walker" ;; people always suggest this, but is there actually a usable code walker out therE?
21:57:29
attila_lendvai
hu.dwim.walker is ours, and it was used in non-trivial applications (uses contextl for fine grained customability)
22:05:26
Shinmera
You can say (:pointer type), but it's equivalent to :pointer as it doesn't do anything with it.
22:05:44
pjb
stylewarning: AFAIK, the only implementation that has an implementation specific special operator is sbcl. This is the only #+ you need in a code walker.
22:07:53
pjb
Ah, there's also: (ccl:nfunction) and in clisp, cl:function is used with an extension (a second parameter).
22:08:13
pjb
But as I said, it's no problem if the code walker provides its own set of standard CL macros.
22:10:40
pjb
Implementation specific special operators (without a corresponding macro) would be particularly problematic if used in implementation specific macros (in extension packages).
22:57:22
emaczen
Shinmera: I'm having trouble arefing a foreign pointer/array the type of the array is an opaque type just defined like: struct name;
23:04:22
axg`
maybe you can define it as an alias to *void? types aren't "allocated" when defined beyond as data within cffi/the c compiler
23:07:52
emaczen
the C code initializes the pointer like: type **name; and then passes it in the function call via func(&name)
23:11:19
Bicyclidine
you have no addressof in lisp. if you want to pass a pointer you have to allocate a pointer
23:11:44
Bicyclidine
cffi doesn't really care about the type beyond knowing that it's a pointer, though
0:07:53
pjb
Shinmera: I wouldn't be so categoric: pointers can have different sizes. eg. in MS-DOS. But also because you may have pointers to different type of data requiring more or less bits.
3:38:45
jasom
pjb: Bike, faff appears to be gone now, but what about this, which doesn't appear to have been suggested: (apply map 'list (lambda (x y) (+ x y)) (k1))
3:48:31
emaczen
https://pastebin.com/PKJz7FLH -- I am having trouble converting this C code to lisp CFFI code
3:49:26
emaczen
I've written a short fully working program that uses CFFI and an external C library without any problems before, but the code was of a different style and didn't pass pointers to be modified like this code does
3:57:06
|3b|
https://github.com/3b/3b-libusb1/blob/master/bindings.lisp is how i would have done it ~2.5 years ago :)
3:58:07
axg
in the C++ code, you are passing the address of your ctx pointer to init. in the lisp version, it looks like you are passing null
3:58:53
|3b|
(though possibly for older version of libusb, not sure how much/if it has changed since then)
4:06:29
|3b|
you might need to read the pointer from that pointer after calling init to get something you can pass to other functions
4:07:31
pjb
jasom: I proposed: (apply (function map) 'list (function +) (f1)) <-- F1, an operator returning a list of lists. The point of k1 is that it is not possible for a macro to return multiple forms. A macro can only return one form. This form could compute a list of list, so (apply (function map) 'list (function +) (k1)) would be possible. But there would be no point in using a macro, since a function would work as well.
4:10:13
emaczen
All I changed was adding (cffi:mem-ref context :pointer) right after (libusb-init context)
4:13:37
emaczen
Okay now, it isn't giving me an unhandled memory error BUT when I (cffi:mem-ref devices :pointer 5) it is the null pointer
4:15:34
|3b|
ACTION can't explain it in IRc better than https://github.com/3b/3b-libusb1/blob/master/wrappers.lisp#L15 :p
4:17:47
jasom
emaczen: yes; the lisp code you would would roughly correspond to the c code: context = malloc(sizeof(void **)); libusb_init(context); libusb_get_device_list(*context);
4:18:30
|3b|
thanks, that's what i was failing to find words for :) been too long since i used C directly
4:18:33
jasom
because you need to explicitly allocate in lisp anything you are going to pass to C (rather than implicitly allocate on the stack like your C code)
4:19:48
emaczen
Now my problem is that libusb-get-device-list returns 6 (so I have 6 usb devices) which means I should be able to (cffi:mem-ref devices :pointer 5)
4:25:05
|3b|
and you probably want mem-aref there, where the offset is in pointers rather than bytes
4:29:13
emaczen
What should I be expecting in the print statements? I have no idea what are reasonable values for the number of configurations, device class, vendor id, or product id
4:36:14
beach
So again, we are on freenode (dedicated to free software) in the #lisp channel (dedicated to Common Lisp), but we are talking about using other languages on commercial operating systems. Go figure.
4:39:08
|3b|
beach: at least the foreign library in question doesn't require the commercial operating systems :)
4:49:12
|3b|
ACTION generally considers falling cffi:foreign-alloc directly to be "something wrong" without good reason, but shouldn't affect output of that
4:51:55
|3b|
assuming those are correct, looks reasonable, but i'd probably try to verify the offsets if possible (print results of offsetof from the c code for example)
4:52:15
|3b|
works if you know your ABI well enough to get the alignment etc right when counting bytes :)
4:52:49
|3b|
ACTION would just put all the fields in and let cffi figure it out for normal libraries
4:55:58
emaczen
and then I'm calling (print-dev (cffi:mem-aref devices :pointer 2)) or another index
5:04:43
|3b|
ACTION thinks padding might not matter for that struct, since it has uint8 in multiples of 2 between the uint16, but multiplying offsets by 8 probably isn't good :)
5:05:09
|3b|
(at least in my version of it, which presumably matched the C version well enough for my code to run at some point)
5:09:19
emaczen
|3b|: Right now, I'm just trying to get started with programming with USB devices from CL
5:12:03
|3b|
might see if my lib still works... not very complete but at least might bet you a little bit further to start out
5:16:25
emaczen
|3b|: Thanks for the help, the hardest part is getting started... I should be able to figure out a lot from here with the pointers given
5:22:13
sigjuice
would it be possible to do something like this to make a custom sbcl binary? (defsystem "mysbcl/exe" :build-operation program-op :build-pathname "mysbcl" :entry-point "launch-sbcl-repl????" :depends-on (...))
5:36:34
pillton
sigjuice: https://github.com/markcox80/lisp-executable/blob/master/lisp-executable-example.asd#L39
5:42:14
sigjuice
|3b| yes, sort of. and is it something I can use as an entrypoint in the asdf:defsystem I mentioned above.
5:47:12
pillton
sigjuice: Lisp-executable won't be of any use if you want that. I didn't read what you said properly.
5:58:12
pillton
sigjuice: No worries. Sorry for not reading your original question correctly. Thanks to |3b|.