Lisp: SETF macro C++: std::ios_base::setf sets the formatting flags to specified settings. Its return value is the previous format flags.
Questions tagged [setf]
30 questions
17
votes
2 answers
defining setf-expanders in Common Lisp
Here's the thing: I don't "get" setf-expanders and would like to learn how they work.
I need to learn how they work because I've got a problem which seems like a typical example for why you should learn setf-expanders, the problem is as…

Johan
- 605
- 5
- 16
9
votes
2 answers
How does using the SETF function to extend SETF work?
In Practical Common Lisp chapter 17. Object Reorientation: Classes section Accessor Functions, I was finding it difficult understanding the way SETF is being extended.
The functions:
(defun (setf customer-name) (name account)
(setf (slot-value…

Bleeding Fingers
- 6,993
- 7
- 46
- 74
6
votes
1 answer
SETFable vs place (CLHS) vs location (Norvig)
Is a setfable the same as a place in CLHS and a location in Norvig's PAIP?
I'm trying to figure out what exactly a place is in Common Lisp but to me the HyperSpec's explanation
place n. 1. a form which is suitable for use as a generalized…

Frank
- 433
- 3
- 10
6
votes
3 answers
What happens when I use a plain setf statement in LISP?
I know that when you want to make a dynamic/global binding in Lisp, you use either defparameter or defvar. I also know that you can make lexical bindings, well, almost everywhere, using defun argument lists or let statements.
What I'm wondering is…

Gearov
- 87
- 6
5
votes
1 answer
How to write a multf function in common lisp
I'm looking for a way to modify a property value in a property list by multiplying it with a given factor similar to using incf for adding to a value.
With incf I could say:
(let ((seq '(:x 10 :y 3)))
(incf (getf seq :y) 3)
seq)
-> (:x 10 :y…

Orm Finnendahl
- 198
- 6
4
votes
3 answers
Turn off setf in c++?
I am using setf in for displaying decimal places in outputs.
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
However, when I put the above code before an output, other outputs are affected too. Is there any way I can use setf…

bffaf02
- 43
- 3
3
votes
1 answer
What are the typical use-cases of (defun (setf …)) defsetf and define-setf-expander
When developing with Common Lisp, we have three possibilities to define new setf-forms:
We can define a function whose name is a list of two symbols, the first one being setf, e.g. (defun (setf some-observable) (…)).
We can use the short form of…

Michaël Le Barbier
- 6,103
- 5
- 28
- 57
3
votes
2 answers
Sidestepping errors by defining vars with SETF
Crew,
I'm one of those types that insists on defining my variables with SETF. I've upgraded to a new machine (and a new version of SBCL) and it's not letting me get away with doing that (naturally, I get the appropriate "==> undefined variable..."…

Todd Pierce
- 161
- 7
3
votes
2 answers
How do setf works under the hood?
Currently learning common lisp, following Peter Seibel's Practical Common Lisp (i'm at chapter 11, about collections), i have difficulties to understand how setf works behind the hood.
Considering this expression :
(setf a 10)
I completely…

aluriak
- 5,559
- 2
- 26
- 39
3
votes
2 answers
define-modify-macro with operator argument
In Section 12.4 of On Lisp, Paul Graham writes, "Unfortunately, we can't define a correct _f with define-modify-macro, because the operator to be applied to the generalized variable is given as an argument."
But what's wrong with something like…

user3414663
- 531
- 3
- 11
3
votes
1 answer
Setf (?) causing cycles in tree
I'm implementing an evolutionary algorithm in Common Lisp (CLISP) and I have a problem.
I have a tree-like class:
(defclass node ()
((item :initarg :item :initform nil :accessor item)
(children :initarg :children :initform nil :accessor…

tearvisus
- 2,013
- 2
- 15
- 32
2
votes
2 answers
Common lisp: Remove a pair in an alist via setq and assoc
I find the code in an old common lisp book, and try it in lispworks and clozure cl. But both of them cannot run the code. This code is used to remove the pair: (author1 . john).
(setf q '((author1 . john) (author2 . tony) (author3 . fred)))
(setf…

Tyrus
- 23
- 3
2
votes
7 answers
setf in Clojure
I know I can do the following in Common Lisp:
CL-USER> (let ((my-list nil))
(dotimes (i 5)
(setf my-list (cons i my-list)))
my-list)
(4 3 2 1 0)
How do I do this in Clojure? In particular, how do I do this without having a…

Paul Reiners
- 8,576
- 33
- 117
- 202
2
votes
2 answers
How to implement recursion when defining a setf function?
From the book "ANSI Common Lisp", p. 100 ch 6.1 :
Suppose that a marble is a structure with a single field called color.
The function UNIFORM-COLOR takes a list of marbles and returns
their color, if they all have the same color, or nil if they…

Jérôme Radix
- 10,285
- 4
- 34
- 40
2
votes
1 answer
Setf function names
Reading this question got me thinking about what constitutes a valid car of an expression. Obviously, symbols and lambdas can be "called" using the usual syntax. According to the hyperspec,
function name n. 1. (in an environment) A symbol or a list…

Silvio Mayolo
- 62,821
- 6
- 74
- 116