format-setf
The Common Lisp equivalent of scanf().

A (relatively) frequently asked question on comp.lang.lisp is "What's the equivalent to scanf()?". The usual answer is "There isn't one, because it's too hard to work out what should happen". Which is fair enough.

However, one year Christophe was bored during exams, so he wrote format-setf.lisp, which may do what you want.

It should be pointed out that currently the behaviour of this program is unspecified, in more senses than just the clobbering of symbols in the "CL" package. What would be nice would be to see a specification appear for its behaviour, so that I don't have an excuse when people say that it's buggy.

Quick assessment (2023-03-24)

For example:

(setf (format nil "~F, ~D" x y) "2.2, 3")

correctly parses the string into x and y, whereas

(setf (format nil "~D, ~D" x y) "2.2, 3")

fails because we used the wrong format directive.


Text