handmade.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
handmade.social is for all handmade artisans to create accounts for their Etsy and other handmade business shops.

Server stats:

37
active users

#lisp

1 post1 participant0 posts today

is this the best way to destructively add an item to the end of a list in #lisp ?
---

(defun ntack (l x)
(setf (cdr (last l)) (cons x nil))
l
)

---

I feel like (cons x nil) is a bit messy.

Just x doesn't work.

Replied in thread

@Kazinator @rzeta0 No fancy inference. #Lisp knows exactly what type each datum is. Is s is a number, return that number. If sequence of length 1, then (first s) returns its only element; if of length 3, it's considered to be an infix operation, so it's reordered into (elt₂ elt₁ elt₃) and evaluated.

`cond` returns the value of the last sexpr of the first clause whose first sexpr evaluates to `t`.

Yesterday I had it first time in my life when the person I told about #guix #lisp and all the hacky stuff I'm into came to me after few years saying he realized that's really cool stuff and whats to know more.

Damn. At least one person. I've almost lost any faith in 'cool-tech evangelism'

Continued thread

but the if I swap the two cond conditions, it works...

------

(defun arith-eval (s)

(cond

( (numberp s) s)
( (equal (length s) 1) (first s))

( (equal (length s) 3) (eval (list (second s) (arith-eval (first s)) (arith-eval (third s)) )))
( t nil)

)

)

---

I can't see how ( (equal (length s) 1) (first s)) would preclude anything later?

---

2 / 2 #lisp

#lisp - unreachable code warning ..

I don't understand why this results in a warning:

-------

(defun arith-eval (s)

(cond

( (equal (length s) 1) (first s))
( (numberp s) s)

( (equal (length s) 3) (eval (list (second s) (arith-eval (first s)) (arith-eval (third s)) )))
( t nil)

)

)

---

1 / 2

I’m an amateur lisper, mostly #Guile and #EmacsLisp, but if someone wants to team up for this #GameJam, I’d be interested!

I also do some basic art, game design, sound, and music. I wouldn’t want to be the sole programmer for this jam but could definitely contribute there and would love to learn more #Lisp.

https://toot.cat/@dthompson/114166799349052427

Toot.Catdave (@dthompson@toot.cat)The Spring Lisp Game Jam is happening once again! Join us for 10 days of consing up little games starting on May 9th! https://itch.io/jam/spring-lisp-game-jam-2025 #lisp #gamejam #lispgamejam
Replied to Alexander Burger

Continuing this thread, the post-scarcity software environment can't yet do iteration, so I'm using a recursive algorithm for factorial:

(set! fact
(lambda (n)
"Compute the factorial of `n`, expected to be a natural number."
(cond ((= n 1) 1)
(t (* n (fact (- n 1)))))))

Let's look at the stack vs iterative performance of different #Lisp family languages...

Here's a gist

gist.github.com/simon-brooke/f

GistComparison of recursive vs iterative performance in various Lisp family languagesComparison of recursive vs iterative performance in various Lisp family languages - recursive-iterative-performance.md
Replied to Alexander Burger

@Regenaxer @borkdude @vindarel Thanks! Right, so my comparable in-REPL times for iterative factorial 1000 are

#PicoLisp: (bench (apply * (range 1 1000)))
0.000 sec
#Clojure: user=> (time (apply *' (range 1 1000)))
"Elapsed time: 2.428199 msecs"
#SBCL: CL-USER[1]: (time (apply #'* (alexandria:iota 1000 :step 1)))
Evaluation took:
0.000 seconds of real time
0.000015 seconds of total run time (0.000000 user, 0.000015 system)
100.00% CPU
45,990 processor cycles
0 bytes consed

Continued thread

However, having bignums in vector space would cause a churn of non-standard-sized objects in vector space, which would mean much more frequent garbage collection, which has to be mark-and-sweep because unequal-sized objects, otherwise you get heap fragmentation.

So maybe I just have to put more work into debugging my cons-space bignums.

Bother, bother.

There are no perfect solutions.

#Lisp

/ continued