r/Common_Lisp • • Mar 10 '23

R for Recursion

0 Upvotes

Have you heard about NASA’s 10 rules for developing safety-critical code?
The first rule forbids recursion and there are many reasonable arguments for that. Even if you don't write safety-critical systems, the use of recursion makes your software less reliable, because:

  • it is difficult to reason about when and what your function returns

  • function becomes vulnerable to stack overflow

But if you CL, recursion becomes a very natural and concise way to express your ideas. Let us learn from the masters! There is a famous macro called flatten described in a marvelous book "On Lisp" written by Paul Graham. Here is the code:

(defun flatten (x)
  (labels ((rec (x acc)
      (cond ((null x) acc)
            ((atom x) (cons x acc))
            (t (rec (car x) (rec (cdr x) acc))))))
    (rec x nil)))

It parses an arbitrarily deep tree of objects and returns you a flat list. Clear and concise. It is even referenced by another famous book "Let over Lambda" (D. Hoyte). From that I conclude the this macro is an example of idiomatic Lisp code. Now test it with a not-so-small tree of objects:

(let ((x (loop for i from 0 to 1000000 collect (cons i i))))
  (flatten x))

SBCL crashes with the message:

Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

This is only the half of the story. If you look carefully at the macro, it is not just recursive, but it uses a recursive core, which is not visible to a caller. This seems to be also a good Lisp style, which unfortunately forces you to mistrust the code written by others.

Yes, functional programming in unthinkable without recursion. Moreover, if you manage to make a call tail-recursive, than a decent compiler must be able to transform it in a loop without run-time overhead. And so we can enjoy brevity of the code and its performance at the same time.

What really scares me, is how actively recursive functions are used in Lisp. They are scattered nearly everywhere. Is this performance/expressiveness lottery really worth it? If yes, I have a proposal.

We have a convention, that a name of a function which modifies its argument should start with "n" prefix (nreverse, nconc, etc). This sends a clear message to its caller. Recursion is equally dangerous, so why not to use an "r" prefix for the functions where recursion is used? This would discourage a reckless programmer to use rflatten in a safety-critical code. Let's vote!


r/Common_Lisp • • Mar 22 '26

A new assembler written in common lisp

0 Upvotes

Hello. I hope I am not breaking a taboo here.

I am curently vibe-coding cl-asm (https://github.com/Phibrizo/cl-asm) a modular assembler writen in common lisp, mainly for the 6502 but extensible (and extended) to other architectures. Probably bugged but curently working (with small test files) for several architectures. Still needs a lot of tests. fell free to comment, give your advice, or just to roast me :)

This assembler is written 100% in common lisp and can be used without exiting the repl. You can use lisp code instead of assembly macros, or even directly use lisp macros if you want :)


r/Common_Lisp • • Feb 07 '21

Where can i find skilled LISP programmers to help me prepare for an exam

0 Upvotes

Hello everyone

I couldn t find anyone on Fever. I m willing to pay reasonablly good.

I need some help to make me understand some conepts and preferable now haha

Is there is anyone on this subreddit willing to do taht ?

Hopefully this thread isn t against the subreddit rules

send me private messages if you re interested


r/Common_Lisp • • Jul 05 '21

Python expressions and their counterparts in Common Lisp

Thumbnail
github.com
0 Upvotes

r/Common_Lisp • • Oct 01 '21

welp, this makes it harder

0 Upvotes

https://youtu.be/4TaH6KXhLt4

Was hoping cl-vectors was going to be real slow and it would be easy to fix. turns out cl-vectors is still way faster than clx.


r/Common_Lisp • • Jan 01 '22

Why not to overload functions in Common Lisp

Thumbnail
ashok-khanna.medium.com
1 Upvotes

r/Common_Lisp • • Apr 12 '26

Telos - Intent introspection for Common Lisp — make the WHY queryable.

0 Upvotes

Telos helps give agents more context for recovering from errors. It add another queryable dimension of intent and rationale. This is distinctly better than just the doc-strings.

With LLM-in-the-Loop, restart selection can be very powerful. The LLM can make corrections, provide missing data.

The condition system is amazing. Agents are natural users for truly dynamic decision making.

cl-mcp-server has telos specific tools

Software is tested and works AFAIK. But it is software so will most certainly have issues and will benefit from improvements. Critiques, feedback and suggestion most welcome.

A study : https://quasilabs.in/blog/2026/02/07/conditions-restarts-and-the-agent-that-chooses/

https://github.com/quasi/telos

Note: This software is written by AI agents at my direction. I own full responsibility for all the good the bad and the ugly. Anyone who does not like software written with the help of AI are free to /please/ ignore this library.

Hope someone finds this useful...


r/Common_Lisp • • Aug 10 '18

Exists a common lisp implementation written in common lisp

Thumbnail
stackoverflow.com
0 Upvotes

r/Common_Lisp • • Nov 12 '21

Visualization is good for dumb people

2 Upvotes

Been recovering some bitrotted wfc code and trying to figure out why it's not working properly. Staring at arrays of numbers just make my eyes bleed, so wrote a little something to display the tiles I was sampling from an image.

This clearly showed my sampling was off.

A little bit of fiddling and this clearly looks better. At least can visually tell the tiles are the right size and colours. Should probably add zoom now so that the code can be used in a ui to choose to collapse some pixels before starting the algorithm.

edit: using lisp to display arrays sampled from regions of an image.


r/Common_Lisp • • Dec 26 '22

Full smart contract framework for CL?

0 Upvotes

I use web3.js to interact with smart contracts at the moment.

Are there any "full" web3 libraries for CL?

I cannot find any when I search. Just want to make sure.


r/Common_Lisp • • Feb 08 '18

Failure report SBCL 1.4.4 / ASDF 3.3.1

Thumbnail report.quicklisp.org
0 Upvotes

r/Common_Lisp • • Jun 18 '20

common lisp runtime interest gauge

1 Upvotes

If there existed a magical standardized runtime for Common Lisp (think java), would you use it?

If so, what would you want to see it do?


r/Common_Lisp • • Jul 21 '20

I need help with 2 functions !

1 Upvotes

I need to write 2 functions for a school assignment. I have already written them and they both work, but my teacher is not happy with them and I have no idea how to do them otherwise.

The first one is supposed to return the position in the list of the argument it's been called with, nil if it's not in the list.

Here's what I got

(defun myposition (lettre liste)
  (cond
    ((not (member lettre liste)) (return-from myposition nil))
    ((equal (car liste) lettre) 0)
    ((+ 1 (myposition lettre (cdr liste)))) ) )

He won't allow us to use member, or return-from, and I don't know how one function can return either a number or nil...

The second function is supposed to return the n cdr of a list, cdr 0 being the list itself

Here's what I came up with

(defun niemecdr (item liste)
  (cond
    ((not liste) (return-from niemecdr nil))
    ((equal item 0) (return-from niemecdr liste))
    (t (niemecdr (- item 1) (cdr liste))) ) )

For this one he said that my function was crazy (sorry I don't know how to better translate what he actually said) and again I shouldn't use return-from or what am I going to use when we start writing complexe functions, an atomic bomb?

(Sorry about the rant, I'm kinda pissed about the whole thing)


r/Common_Lisp • • Nov 27 '18

I'm learning Common Lisp and I owe YOU $5 USD every day that I don't work on it!

Thumbnail
github.com
0 Upvotes

r/Common_Lisp • • Feb 02 '26

Programming and AI

0 Upvotes

Finally the problem our small common lisp community had of not enough man power is solved. I had to give up common lisp in an enterprise environment simply because the eco system was minuscule. I am super happy that people have started making new stuff in CL again. There will be slop. But do you think there was no slop in software ever even with Humans? On the other hand there is potential to create great software. Depends on us.

Every new technological change goes through teething trouble before it stabilises. There is no going back from AI writing code. What we need to learn is to use AI to write /good/ code - just like we want.

antirez puts it well : https://antirez.com/news/158


r/Common_Lisp • • Sep 15 '26

Programmer

0 Upvotes

I am a software engineer with prior experience with many languages and technologies, including CL and Python. I was formerly employed as a Senior Software Engineer at Lockheed-Martin. My resume can be found at the link below.

My rate is $50 per hour, payable via cashpay or cryptocurrency. I am fully remote and prepared to work for any client world-wide. I am also a US citizen and I am currently located in Bronx County, NY (a borough of New York City). In case of necessity other payment arrangements may be discussed.

My github repo currently contains only one significant Lisp project, which is still in a very early stage of development. It is a project called Julius which is intended to become a new Lisp dialect more suitable for modern applications, such as numerical analysis and the generation of neural networks and modern AI (a field with which I have considerable experience). It is implemented in Common Lisp in order to retain the well-known advantages of the Lisp language for older forms of intelligent systems, which typically involve a great deal of symbolic reasoning.

The current version of Julius is Open Source and I am open to comments and contributions here:

Julius Project: https://github.com/tgflynn/julius

Resume: https://github.com/tgflynn/latex-cv


r/Common_Lisp • • Jul 31 '24

Delete

3 Upvotes

I am clueless after reading the Hyperspec nonsense. Can somebody explain in human language why I need to setf the children when I use delete?

(defmethod remove-child ((parent-box box) (child-box box))
  (remhash (sxhash child-box) (gui-window:all-widgets (root-window child-box)))

  (setf (children parent-box)
        (delete child-box (children parent-box)
                :test (lambda (a b)
                        (eq (sxhash a)
                            (sxhash b))))))

r/Common_Lisp • • Jun 01 '25

[blog post] Common Lisp is a dumpster

Thumbnail
nondv.wtf
22 Upvotes

Hello!

I've been working on this essay for a while. I've been using Common Lisp for various personal things and experiments in the past couple of years. Those include: tinder bot, telegram bots for different purposes, stock market watcher, deployment scripts for my homelab, etc.

But it's got plenty of things that keep flabberghasting me. These are some of them :)


r/Common_Lisp • • Feb 23 '24

Need to write some java code in abcl

0 Upvotes

The scala code :


/ File companion.scala
class Companion {
	def hello() =
		println("Hello (class)")  // [1]
}
object Companion {
	def hallo() =
		println("Hallo (object)")  // [2]
	def hello() =
		println("Hello (object)")  // [3]
}

The java code which calls this scala code :


// File TestCompanion.java
public class TestCompanion {
    public static void main(String[] args) {
        new Companion().hello(); // [1]
        Companion.hallo();  // [2] (static)
        Companion$.MODULE$.hello();  // [3] (hidden static)
    }
}

Question. What is the abcl-code equivalent to this java-code, so i can call scala from abcl ?


r/Common_Lisp • • Feb 23 '24

Is an interop beween abcl & scala possible ?

0 Upvotes

Is an interop beween abcl & scala/kotlin possible ?


r/Common_Lisp • • Jul 20 '19

Common Lisp ragequit?

16 Upvotes

Hello everyone,

CL is a beautiful language. Despite this, it is not widely endorsed despite its age. Why?

As a CL newbie, please allow me to give some feedback about that.

A word about my background: I'm not a programmer but a computer enthusiast. One year ago I decided to learn Python and I wrote a basic chess engine for the sake of learning. Then I got frustrated with Python slowness and I decided to learn CL, which is way faster and still provides a dynamic developpement process. I read "Common Lisp: a gentle introduction to symbolic computation" and "Practical common Lisp". I got fascinated with the language, which allows a very different kind of programmation than Python (very few usage of allocation for example), and a wide variety of optimizations. So I started to write my engine again in a more efficient way, and here I am.

So why is the title talking about ragequit? One single word: Emacs.

Emacs is a pain in the ass, and will discourage 99% of people from sticking to CL.

I mean, let's be serious: Emacs in an ergonomical abomination. The standard keyboard shortcuts don't work. We can't even copy/paste from in a simple manner. And what about managing windows? Seriously, I didn't even found how to do it. The friction with the unfamiliar user is terrible.

So I searched on the web and yes, I found Portacle but it doesn't adress these simple problems.

So I used atom-slime for Atom, which worked well, until I started to need an efficient debugging tool (which is supposed to be one of the CL main advantages), and realised that atom-slime doesn't manage the debugger properly yet.

EDIT: atom-slime is now replaced by Slima which is more complete.

Seriously, I know you guys are aware of these problems and are not responsible for that. But still, these drawbacks hold CL back in a incredible manner. Emacs is why CL has this "old language" reputation.

At this point, I hugely regret it as I learned to love this language, but I just can't bear Emacs anymore. It's unsupportable.

And I sadly doubt that CL will have any serious future if it stays tied with Emacs, which is just a slap in the head of the good will guys like me, who just want to learn CL because it's inherently good.

Thank you for reading anyhow. Don't hesitate to comment, would love to hear others's point of view.

EDIT: After a few hours learning Emacs (Portacle for me), I can see the logic behind it and the efficiency it can procure.

As of now, I wouldn't be so reticent to use it on a regular basis, and I think it could even be handy and efficient on the long term.

I still think, however, that the lack of consideration for new users holds CL back. The point is not, indeed, that Emacs would be too complicated, but that it feels dated. New users comes in, try to copy/paste something and it don't works.

Some could argue that Emac's harshness is an useful filter; that if someone can't learn Emacs, he will not be able to learn Lisp either way. I don't think that this is pertinent. We're in 2019; there is plenty of good languages out there, and CL is now in a competitive environnement. It is not only a matter of competence, but also a matter of willingness; what Emacs does, in the first place, is redirecting new users to other languages.

This is not desirable because smaller is the user base, smaller is the incentive for competent people to learn it (starting with the professional incentive); and bigger becomes the incentive to learn something else.

I will anyhow continue CL (and Emacs) because it is fun!

Thank you all, you were helpful.


r/Common_Lisp • • Mar 18 '20

What are the things that Racket does below the base language that CL lacks?

4 Upvotes

From Why I haven't jumped ship from Common Lisp to Racket (just yet)[1]

First and foremost, Racket keeps evolving, and not just "above" the base language, but importantly below. This alone makes it vastly superior to CL (that has evolved tremendously "above" its base abstractions, but hasn't evolved "below", except for FFI purpose, in the last 20 years), which itself remains superior to most languages (that tend to not evolve much "above", and not at all "below" their base abstractions).

What are the things that Racket does below the base language that CL lacks?

How can CL improve below without contradicting the standard? I was also reading up on stop-the-world garbage collection. that is also under the hood I presume, is there a way to have concurrent GC like in Go for CL?

[1] https://fare.livejournal.com/188429.html


r/Common_Lisp • • Feb 27 '23

String is immutable

0 Upvotes

Error given : Destructive function SB-KERNEL:%SETELT called on constant data: "MYSTRING"

(load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3)))
(defun main ()
    (let ((s "MYSTRING"))
        (setf (elt s 0) #\H)
        (print s)))

r/Common_Lisp • • 11d ago

Sloppy CL interpreter experiment targeting Wasm

Thumbnail
github.com
1 Upvotes