freenode/lisp - IRC Chatlog
Search
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)
13:49:30
Xach
https://github.com/quicklisp/quicklisp-client/issues/198 is a real head-scratcher for moe
13:55:33
MichaelRaskin
https://support.sectigo.com/articles/Knowledge/Sectigo-AddTrust-External-CA-Root-Expiring-May-30-2020 is the link to the upstream post
13:57:33
MichaelRaskin
Or paranoidally check everything provided in the chain even if it is not actually necessary to establish trust
13:57:36
Xach
ah, ok. hmm. i don't think my operating systems have updates for certs pending, though.
14:24:09
phoe
and for conses, you want stronger checks than just typechecking - you usually want destructuring of some sort
14:24:23
Bike
a form can be anything, so there's nothing to check. the rest of the syntax is usually covered by the lambda list
14:26:24
theseb
e.g. I made a for loop macro that works like this...(for i (list 1 2 3) ....) ......Seems like it may avoid issues to check if 1st for macro arg is a symbol and 2nd macro arg evals to a list
14:32:47
theseb
Oh one last thing.....is it easy to switch between CL and Clojure....I'm hoping that Clojure becoming fashionable is a good thing for the CL and Lisp community in general
14:32:57
aeth
theseb: you can check that the first is a symbol, but you can't check the second at macro time, at best you can insert a CHECK-TYPE in your expansion
14:45:09
pjb
theseb: it really depends on the complexity of your function (macros are functions), and whether you use the values immediately, or later or deeper in the code. If you use the value immediately, then a type error will be soon detected and reported, in a way that should be understandable to the programmer.
14:45:54
pjb
theseb: on the other hand, if the values are used later or deeper in the code, the relationship between the bad value and the call (or macrocall) can be less obvious. Then it may be helpful to the programmer to check the types and report the error earlier.
14:46:48
pjb
theseb: but it's rarely done. One objection is that the programmer checking the types often is too restrictive. Lisp is a generic programming language: you don't write function processing specific types, but functions processing ANY type that it can.
14:47:43
pjb
theseb: as for the ease of switching, 1- there's a clojure implementation written in CL, 2- just try to convert 10kLOC of Clojure to CL, and tell us! (better write directly in CL).
14:48:37
pjb
theseb: also for the types if you don't check it, then the type restrictions may depend on the implementation of the function. Which can be considered good or bad…
14:55:29
aeth
theseb: this is off-topic, but Clojure looks past fashionable, not "becoming fashionable", to me. That's the risk of relying on "fashion" in the first place.
14:57:20
aeth
pjb: You want to check the type early so you can fail early. Sure, a for loop macro would probably fail fairly early (but the message won't be as clear to the user) without a list (but it should be a sequence) as the input, but most things could fail very deep
14:58:01
aeth
IME it's fairly common in a large program to get a random NIL pop up when it could've been generated somewhere very far from where it shows.
15:02:21
theseb
aeth, pjb: i see both sides....dynamic typing is a wonderful thing that leads to cleaner code but may also lead to hard to find bugs.
15:03:17
aeth
pjb: duplicated code is efficiency, at the cost of space, at least. That's sort of the point of C++ templates or https://github.com/markcox80/specialization-store/
15:03:52
aeth
theseb: it appears to have peaked 5-6 years ago in multiple (obviously all unreliable in their own way) measures, e.g. Google Trends.
15:04:41
pjb
aeth: it's wrong. the generated binaries are often identical, since most type have the same size.
15:04:49
theseb
aeth: i would think ClojureScript will rocket to the moon since apparently anything in the browser becomes super popular
15:05:21
aeth
theseb: 5-10 years ago, everyone was trying to compile things to JS (including dozens of Lisps, mostly Schemes, but two CLs)
15:05:34
aeth
theseb: These days, it seems to have consolidated on TypeScript. Maybe WASM will be another chance for Lisp in the browser.
15:09:53
aeth
pjb: Quite a few CL APIs are for a specific type or for the union of a specific type and NIL (i.e. (or null foo) which I use a DEFTYPE to write as (maybe foo)).
15:10:49
p_l
currently V8, and thus Chrome, can't handle WASM that isn't representable as straight JS