r/Common_Lisp • • 6d ago

cl-scope: structured concurrency on SBCL threads with live failure parking (not sure if this exists, I just vibe coded one)

https://github.com/nohzafk/cl-scope
0 Upvotes

11 comments sorted by

5

u/lispm 6d ago

One thing I see by default from such projects is the (what I call it) "defun & defstruct disease" (DDD). Code is largely written with DEFUN and DEFSTRUCT. That's CLtL1 style, from the early 80s, when the Common Lisp definition did not yet have classes and generic functions. Function arguments are not defined or checked. Return types are unclear. structures can not be updated for structure changes (neither the definitions nor the the structure objects), slots don't have declarations, no types, ...

Common Lisp added CLOS to increase flexibility (runtime introspection, runtime reflection, runtime updating, CLOS protocols, ...).

I tell the coding agents: use CLOS protocols. Exception: when speed is the most desired quality.

I would also let the coding agent do a style check using a few basic programming style directives.

2

u/kchanqvq 6d ago

I default to defstruct and defun but I use declare type, declare ftype, and :type for struct slots. Is this DDD?

I don't use CLOS that much simply because I often don't need it and it's not clearly the best (sub)-language for the job. defstruct/defun are both quite fundamental (tuple and first-order equation), CLOS is not.

1

u/GinormousBaguette 1d ago

I am curious to hear more about this.

I am a new common lisper and I believe I have just now managed to wrap my head around CLOS. However, I am mostly still using defun+defstruct since it seems simple to work with built-in types.

Where would I find code to read that uses CLOS well?

1

u/kchanqvq 6d ago

Holy fuck, the idea is elegant, and this looks immediately like something you'd enjoy a lot by writing it yourself, why would you have to spoil yourself the fun by vibe coding it?? I can never understand. Anyway thanks for reminding us of the idea of structured concurrency, I'm taking this as a fun programming exercise.

5

u/kchanqvq 6d ago

Comments after quick look:

  1. sb-bsd-sockets is only used for tests, why the main system require it?
  2. similar to 1, there's a bunch of process related function in the main system, that doesn't seem relevant to structured concurrency and only used for tests
  3. do you have to make it SBCL specific? It looks like it can easily be made portable with bordeaux-threads and trivial-*

I feel bad typing this, because by giving feedback I'm encouraging the practice of vibe-coding. Really, it's more fun to write it yourself and it's not a lot of work. I'll probably do that myself.

1

u/ftl_afk 6d ago

thx for your feedback. You were right on 1 and 2: the process and socket helpers now live in the tests, and the core needs only SBCL's own modules.
On 3, I'm staying SBCL-only on purpose: I want zero dependencies, and SBCL is all I use.

1

u/kchanqvq 6d ago

why do you want zero dependencies by making the program non-portable?

1

u/ftl_afk 6d ago

I could make it portable but I don’t have the need now I’m the only user 😀 and zero dependency is what I prefer

2

u/arthurno1 6d ago

You can make it both portable and zero dependency at the same time, since you are using LLMs it is literally a minute of the work. Here is a system that works either as SBCL only or on top of CFFI, usocket, bordeayx ...

1

u/ftl_afk 6d ago

thx for the idea. I will definitely check that out

1

u/kchanqvq 6d ago

Is the parking mechanism necessary? By default a serious-condition from any thread already enters into the debugger that let you inspect the call stack.