freenode/#lisp - IRC Chatlog
Search
22:16:06
dxtr
Does it make sense to run call-next-method at the beginning of a method? Or should I rather use :before?
22:24:24
therik
when I (ql:quickload :usocket), why doesn't it pull the server.lisp file too? I have to do separate (ql:quickload :usocket-server) for that
22:50:17
fiddlerwoaroof
The main reasons to use :AROUND are either you want to change the return value of a primary method (and don't want to make people remember to call #'CALL-NEXT-METHOD) or you want to prevent the primary methods (and :BEFORE/:AFTER methods) from running
22:50:53
fiddlerwoaroof
Or, you're doing something interesting, like trying to make the implementations of your function run in a different thread
23:10:04
casouri
Hi, I'm tring to inplement a simple irc backend. I think I would have two streams: one connects to emacs and one connects to irc server. And the program and send/recieve messages from/to them. I've thought of some structure of the program but they all seems complicated.
23:12:06
casouri
For one that I can think of, I would have two special variable bound to streams and have lock on them, and loops through 1) send to emacs, 2) recieve from emacs, 3) send to irc, 4) recieve from irc
23:13:36
fiddlerwoaroof
If you have a recent enough version of slime/swank (I'm not sure if it's in quicklisp), you can use swank-buffer-streams to get a stream that outputs to an emacs buffer
23:15:49
therik
Xach: where's that written? I just randomly typed :usocket-server out of desperation and it downloaded it
23:15:56
casouri
Thanks, swank feels a bit of an overkill to me. A tcp socket should work fine for messeges
23:19:46
casouri
Is there any way to do non-blocking read on normal streams? I searched around and didn't found anything that mentions it.
23:27:30
fiddlerwoaroof
something like (loop when (cl:listen s) thereis (sl:read-char s) do (sleep 0.1))
23:29:24
casouri
verisimilitude: Thanks. Would it be ok if I instead spawn four threads and connects them to some CSP channels?
23:32:11
casouri
Because it seems a non-blocking READ-LINE is more difficult to implement that that. I need to create a buffer and read char to buffer and only return t when I read a newline.
0:23:03
Josh_2
currently using safe-queue I'd like to have sq:make-queue instead of safe-queue:make-queue for example
0:27:33
Josh_2
That is true :) however I got a conflic with clx and usocket so I just went with using the package designators at the start (I think that's what it is)
0:36:37
Josh_2
Is there an advantage to do say (defmacro pop-queue () `(sq:dequeue *commands-queue*)) over (defun pop-queue () (sq:dequeue *commands-queue*))? I've seen it done with accessors before
1:25:26
aeth
Josh_2: If you have a macro and an equivalent function, always go with the function. If you want sort of macro-like behavior then (declaim (inline function-name)) and you get that. Note that that inline includes the macro's *disadvantage* of not updating the callers when you recompile it. It will give you macro-like performance characteristics while permitting higher order functions and removing a bunch of potential bugs, though.
1:27:00
aeth
e.g. (defmacro 2+ (number) `(+ 2 ,number)) vs. (defun 2+ (number) (+ 2 number)) vs. (declaim (inline 2+)) (defun 2+ (number) (+ 2 number)) and for this particular case the 3rd option is probably what you want.
1:29:53
aeth
Forgetting , is such a common bug because the author will probably name their variables the same the whole way so it will take a third party using it to spot the missing , so that's one good reason to never use macros when a function will do.
1:30:25
aeth
e.g. the 2+ macro author might name their number 'number and then write `(+ 2 number) and you'll spot it when you call your number 'n and have to write a pull request
1:32:03
aeth
These seem to be incredibly common in exactly the sort of macro-as-inline-function trivial macros, too. Perhaps because the author isn't paying too much attention to something so trivial.
1:42:29
Josh_2
(bt:make-thread ..) is the way to make a thread that should run in the background, or am I missing something... *thonk*
2:05:38
aeth
Josh_2: (defun hello (n) (format t "Hello, ~D.~%" n)) (defun make-hello (n) (bt:make-thread (lambda () (sleep 10) (hello n)))) (dotimes (i 10) (make-hello i) (sleep 1))
2:06:42
aeth
Josh_2: Interestingly, the #'make-hello is actually *mandatory*, or else it reads the *current* value of i (9 for the first thread and 10 for the remaining 9) at the time of printing instead of printing 0 to 9.
2:07:43
aeth
Also don't forget to put it in its own function or be very aware of the variables it's capturing
2:08:51
aeth
It's a clsoure. It will have access to all of the outer variables, although if it's just (lambda () (receive-data)) I guess it won't matter. I think in that case (zero arguments) you might just be able to say #'receive-data
4:43:24
emaczen
I have a lisp function whose argument gets passed to a particular cffi:foreign-funcall which expects a struct
4:43:49
emaczen
The "struct" I pass to the lisp function gets automatically translated into a lisp list
4:45:30
emaczen
How do I stop this automatic translation, or how can I force the list to be converted back to a struct?
5:43:12
LdBeth
emaczen: then just use the ctype pointer, see https://common-lisp.net/project/cffi/manual/cffi-manual.html#Foreign-Structure-Types
8:13:28
Nilby
Grue: Probably because it wants you to use #'cddr, maybe to prevent against 'something as a typo.
8:17:22
beach
Grue`: I think it means that it is going to call FDEFINITION, perhaps in each iteration.
8:33:55
Grue`
I actually avoid using #' in my code for various reasons, so this warning was annoying
8:40:08
Grue`
' always uses top level function definition, so for example if I'm calling a function in a macro expansion I'm immune to it being redefined in flet
8:42:41
Grue`
yeah, standard functions get ' for consistency. basically I only use #' for lexical scope functions
8:50:43
Grue`
there's literally no difference in (disassemble (lambda (y) (funcall 'cddr y))) whether I uuse #' or '. So the compiler probably realizes that just means (cddr y)
8:59:26
jackdaniel
it might be that optimization of "locked" funcitons is in independent module and happens much later