freenode/lisp - IRC Chatlog
Search
3:20:48
minion
beach, memo from pjb: quicksort optimization (branchless Lomuto partitioning): https://blog.reverberate.org/2020/05/29/hoares-rebuttal-bubble-sorts-comeback.html
4:26:13
Decs
Hey all, this week I wrote a small runtime to support the Actor Model of computation. Pastebin if you're interested: https://pastebin.com/piPY0GVX. First time I've tackled a problem like this, all comments are welcome.
4:29:53
beach
And, yes, as no-defun-allowed points out, you would typically use a standard class for a queue, not a closure.
4:30:26
no-defun-allowed
And then it might be more efficient to use a lock and condition variable per queue.
4:30:34
Decs
okay thanks beach. There may be something funky with my emacs as I can never get my loops to indent properly
4:31:13
beach
Apparently, the contribution slime-indentation is now part of the default setup. But if you have an older version, you may have to include it manually.
4:32:31
beach
There are an awful lot of c*r calls in there. That's a sign that you need to use standard classes or structs instead of lists.
4:32:37
no-defun-allowed
I would also represent each actor as an object that holds its own message queue and closure.
4:33:37
beach
At the very least, you should introduce a layer of named abstractions as "aliases" for those c*r calls.
4:34:21
Decs
The use of closures are a symptom of having just learnt of them, its my new superpower!
4:36:34
Decs
I totally agree I need to name some things, so when i come back to this code it's not incomprehensible like you say
4:37:26
no-defun-allowed
You could probably get away with using a package like safe-queue for the queue implementation too.
4:38:22
beach
So I think that sums it up: Use standard classes. Indent properly. Don't quote your CASE keys. Introduce abstractions. Use WHEN and UNLESS for single-branch conditionals.
4:40:28
no-defun-allowed
The trouble with making structures from lists is that you have to infer the shape from wherever that structure is created.
4:41:44
no-defun-allowed
I read "fond, noun: Having a strong liking, inclination, or affection", and you told us all. But to keep this productive, let's say I said fond instead.
4:42:21
no-defun-allowed
noun→adjective. God dammit, I should focus on just my homework and not #lisp and my homework.
4:48:14
Decs
Cheers yeah it's been at the back of my mind that the list destructuring (?) is messy. I'll definitely look into making every thing more explicit
4:55:10
Decs
I had read Carl Hewitt didnt consider actors having their own message queues as fundamental so I decided on a whim that I would take that approach. even though all the implementations Ive seen tack them onto the actors class. Not sure of the pros and cons of either approach.
4:56:39
no-defun-allowed
If you had an implementation where actors had their own threads, and receiving a message blocked the thread, I think it would be a requirement to use separate queues.
4:58:59
no-defun-allowed
You use message handlers to represent actors and a scheduler running on one thread, which does not require that. I have not tested this, but I would also expect that using a message queue per actor (and an appropriate means of scheduling) would improve throughput with many worker threads.
5:06:10
Decs
ahh, yes I tried to make the queue operations as fast as i could to limit blocking between worker threads, but I can see how it may be a problem with more worker threads operating on the queue potentially simultaneously
5:07:49
no-defun-allowed
(Oh, and if you're on SBCL, safe-queue will use SB-CONCURRENCY, which is likely faster as it uses compare-and-swap instead of a lock.)
5:08:31
Decs
with the multi queue approach threads will only block if trying to write to the same actors queue
5:39:05
seok
can you pass multiple values (values a b c ...) to a function which takes same number of arguments?
7:12:25
beach
(loop with min-entry = (first alist) with min-value = (cdr min-entry) for entry in (rest alist) when (< (cdr entry) min-value) do (setf min-entry entry) (setf min-value (cdr entry)) finally (return min-entry))
7:13:30
phoe
(reduce (lambda (x y) (if (< (cdr x) (cdr y)) x y)) '((a . 335) (b . 29385) (c . 839875) (d . -32) (e . 447)))
7:56:00
beach
As in: when (funcall predicate (funcall key item) (funcall key best)) (setf best item)