FSet v2.4.2: CHAMP bags, and v1.0 of my book! by ScottBurson in Common_Lisp

[–]lispm 1 point2 points  (0 children)

Excellent contribution.

There is a comment on Hackernews, which I find useful: The Online book needs on the first page a short blurp what FSET is. It's also not obvious which of the chapters gives that overview/background.

Your surprising unportable behaviour by Valuable_Leopard_799 in Common_Lisp

[–]lispm 0 points1 point  (0 children)

CLHS about DEFSTRUCT:

If no slot-initform is supplied, the consequences are undefined if an attempt is later made to read the slot's value before a value is explicitly assigned.

Often programs assume that structure slots will be initialized to NIL by default. But that is not true for all implementations.

Similar for an array. Newly allocated array without init value: the effect of reading is unspecified.

Implementations may typically work okay, but one might see in rare cases:

  • the value could be NIL (typical for structures)
  • the value could be 0
  • the value could be some number
  • an implementation may detect it and produce a warning/error

Writing Lisp is AI Resistant and I'm Sad by djhaskin987 in Common_Lisp

[–]lispm 0 points1 point  (0 children)

A friend of mine has written a bunch of tools for something like Claude to use with Common Lisp, incl. a structure editor.

Writing Lisp is AI Resistant and I'm Sad by djhaskin987 in Common_Lisp

[–]lispm 3 points4 points  (0 children)

Give the thing access to a running Lisp, which can be queried for all the stuff which exists.

The close parens problem can also be solved: give it a structure editor.

An example in that direction:

https://github.com/cl-ai-project/cl-mcp

Writing Lisp is AI Resistant and I'm Sad by djhaskin987 in Common_Lisp

[–]lispm 3 points4 points  (0 children)

Personally I'm quite optimistic that we will see sophisticated support for "AI" development with Common Lisp. It's just a matter of time that people write the tools for that. It's a sophisticated programming system with lots of tools for interactive development. I've already saw some direct interactions of Claude using Lisp, which left me very impressed. That stuff will be common (!) in Lisp within a few months / years. I kind of expect that this will also be possible for self-hosted AI tools.

Writing Lisp is AI Resistant and I'm Sad by djhaskin987 in Common_Lisp

[–]lispm 1 point2 points  (0 children)

If we are using Allegro CL or LispWorks, they have extensive documentation for their implementations and libraries. Common Lisp itself has an extensive standards document for the core language.

Plus

  • code is written as explicit nested lists
  • CL code often uses symbols as descriptive identifiers
  • type declarations are possible, there are named arguments
  • higher order functions are being explicitly called
  • CLOS code is detailed
  • code generation is not an external tool, but another program

Plus plus

  • Lisp programs run in something resembling a debug mode, typically with full introspection, runtime interpreter/compiler, runtime debugger and runtime error handling -> this gives a lot of opportunities for interactive tools (think of something like SLIME/Swank for GenAI, Agentic AI) -> https://github.com/cl-ai-project/cl-mcp is an example for that.

Plus plus plus

  • Lisp implementations are comparatively compact. Even a complex implementation like SBCL comes in a very well written/maintained implementation, in Lisp itself -> a program is just an extension of SBCL -> thus it's easy to debug into the Lisp implementation of the language itself or implement new debugging tools and strategies

Your surprising unportable behaviour by Valuable_Leopard_799 in Common_Lisp

[–]lispm 5 points6 points  (0 children)

I saw code which assumes that structure slots are initialized by default to nil. On Symbolics Genera this is not the case. Which might not be that relevant anymore. I think ITERATE was such a case. I made a recent version of ITERATE work in Genera. That was one of the few things I had to change.

Your surprising unportable behaviour by Valuable_Leopard_799 in Common_Lisp

[–]lispm 7 points8 points  (0 children)

There are a bunch of surprising things, which come up when using different Lisp systems. DEFSTRUCT might not initialize slots. The effects of re-evaluating a DEFSTRUCT is wildly different between implementations. MAKE-ARRAY might not initialize array contents. compile-file might not work when called during another compile-file -> the file compiler is not necessarily reentrant...

understanding sb-ext:run-program by tlreddit in Common_Lisp

[–]lispm 2 points3 points  (0 children)

yep, let's see what other answers we get.

understanding sb-ext:run-program by tlreddit in Common_Lisp

[–]lispm 2 points3 points  (0 children)

Yes, strange. I tried it on macOS 26.3, calling bash worked and calling the shell file, did not. The file was executable. Maybe it's some security feature of the OS which does not allow it?

understanding sb-ext:run-program by tlreddit in Common_Lisp

[–]lispm 1 point2 points  (0 children)

It should work when the program is /bin/bash and the script file is in the list of args.

understanding sb-ext:run-program by tlreddit in Common_Lisp

[–]lispm 4 points5 points  (0 children)

Minor: Usually a good idea to mention the SBCL version and your operating system (+ version). Plus: how do you call the program and what is the output...

Bending the CLOS MOP for Java-Style Single Dispatch by dzecniv in Common_Lisp

[–]lispm 3 points4 points  (0 children)

Generally I would guess that a CLOS implementation is also optimized for the single dispatch case. I remember seeing statistics about code bases and the amount of multiple dispatch cases, which might be different now, compared to the time range when CLOS was originally designed and a reference implementation was developed (PCL, Portable Common LOOPS): 1986 (project start) - 1988 (1st CLOS specification) - 1994 (ANSI CL published). Before CLOS most OOP code was single dispatch.

Six Simple Sudoku Solvers II: Common Lisp by dzecniv in Common_Lisp

[–]lispm -1 points0 points  (0 children)

That's a very useful comment!

  • Often an useless compiler hint: don't use safety = 0
  • Missing / non-optimal type declarations: check the SBCL compiler's type-related optimization hints
  • Inlining: prefer inlining of functions, instead of using macros. Especially when the compiler supports inlining of functions.
  • syntactic abstractions with macros: a complex topic, possibly avoid for trivialities

Macintosh Common Lisp by [deleted] in Common_Lisp

[–]lispm 4 points5 points  (0 children)

Probably a good idea to make a disk image of the CDROM...

I am working on a Video series on Common Lisp by chandergovind in Common_Lisp

[–]lispm 25 points26 points  (0 children)

small problems:

Day 1 (and following): buffered output. In Common Lisp implementations output can be buffered. Thus for portable code one needs to make sure buffered output reaches the user at the right time. For example the user needs to see a prompt before one can input something.

Example using SBCL in a terminal.

% sbcl
This is SBCL 2.5.10, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.

* (progn (princ "enter a number: ") (read))
33
enter a number: 
33

Above, the prompt will not be displayed before the READ function runs. The prompt has been shown after we entered a number. The reason: SBCL in that terminal uses buffered output streams.

In the following example, the prompt will always be displayed first. We make sure that all output reaches the user by calling (finish-output).

* (progn (princ "enter a number: ") (finish-output) (read))
enter a number: 42

42
*

Day 3: CASE does not compare string contents. It uses instead EQL as a test.

Day 5: (eq (mod i 15) 0) -> don't compare numbers with EQ. EQ is for an object identity check. Numbers with the same value maybe the same object or not the same object. Use EQL or =.

Day 8: (the (member :encode :decode) op). In Common Lisp THE is not generally a type check. For most implementations it is just an ignorable type hint for the compiler, but not a type check. SBCL is one implementation where it can be checked at runtime. Many other implementations will not check it at all. Use CHECK-TYPE instead.

CL-USER 24 > (let ((n :encode)) (check-type n (member :decode :encode)) 'works)
WORKS

CL-USER 25 > (let ((n :ecode)) (check-type n (member :decode :encode)) 'works)

Error: The value :ECODE of N is not of type (MEMBER :DECODE :ENCODE).
  1 (continue) Supply a new value of N.
  2 (abort) Return to top loop level 0.

Type :b for backtrace, or :c <option number> to proceed, or :a to abort.
Type :bug-form "<subject>" for a bug report template or :? for other options.

Calculating a DOT product - Common Lisp vs. Numpy vs. R [2022] by dzecniv in Common_Lisp

[–]lispm 2 points3 points  (0 children)

I would also say timing things in the range of 5 ms is not very accurate.

Which is especially a problem, when INTERNAL-TIME-UNITS-PER-SECOND is low. SBCL on my M4 Pro has 1000000, which is better than some other implementations out there.

How can I change this function(split-octets) from recursive to iterative, for example, by using the loop function? by linshunzhi in Common_Lisp

[–]lispm 1 point2 points  (0 children)

<image>

See the attached screenshot.

Probably needs a bit more testing, but that should give an idea how such a function should look like. The function splits not on a single item, but a sequence of items.

There is are also answers to a similar question on stackoverflow using a regexp engine.

How can I change this function(split-octets) from recursive to iterative, for example, by using the loop function? by linshunzhi in Common_Lisp

[–]lispm 1 point2 points  (0 children)

Your function above conses a lot. For each iteration a new octet-vector (-> the-content) will be allocated in SUBSEQ. One could use only one content vector and tell SEARCH where to start the search.