Questions tagged [setf]

Lisp: SETF macro C++: std::ios_base::setf sets the formatting flags to specified settings. Its return value is the previous format flags.

30 questions
2
votes
2 answers

Creating a shadow array of an array with switched rows and columns

I'm trying to find out a way to create a copy of an array with switched rows and columns. I want to do this by setting pointers from the shadow array to the original array so that item[2 1] points to item[1 2]. Using pointers will have the effect…
hbl
  • 23
  • 3
1
vote
1 answer

setw() - adjustfield (left, right or internal)

I am going though the string functions doing tests to learn them (I am a newbie programmer) Anyway, I am currently looking at setw() but I seam to not understand it... I think I understand the basic use and the use of setfil here is my test…
aJynks
  • 677
  • 2
  • 14
  • 27
1
vote
2 answers

Non destructive modify hash table

Is it possible to non-destructively add new key-value pairs to a Common Lisp (SBCL) hash table? The standard way to add new elements to a hash table is to call: (setf (gethash key *hash-table*) value) but the call to setf modifies *hash-table*…
myselfesteem
  • 733
  • 1
  • 6
  • 23
1
vote
3 answers

How to execute a function on setf place

I have a list which contains some symbols and values. The goal is to setf the class slot with the accessor, whose symbol is provided by the list : (defclass my-class () ((attr :accessor attr))) (let ((to-call '(attr "some-value")) (obj…
Fnifni
  • 319
  • 1
  • 10
1
vote
1 answer

Why aren't generic functions the same as accessor functions lisp

From the things I have read I understand that Accessor functions in CLOS allows for the programmer to get and set variables and it generates a generic function of the name that was give in to the accessor to which you need to define different…
jakHunter
  • 305
  • 3
  • 13
1
vote
2 answers

Nondestructive setf?

Common Lisp seems to go to great lengths to provide both nondestructive functions (like subst & remove) and destructive functions and modify macros (like delete & rotatef) for general use. Presumably this is to effectively support both functional…
davypough
  • 1,847
  • 11
  • 21
1
vote
1 answer

SETF neither terminates nor reports an error

I'm a Common Lisp beginner and came across this piece of code: (let ((foo (list 42))) (setf (rest foo) foo)) The REPL seem to just loop forever when trying to execute it.
hayordi
  • 119
  • 1
  • 8
1
vote
2 answers

Prevent the zero before the decimal from being displayed in C++

In C++, I'm using the following statements to display output: // example float x = 0.66004; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << x; My output looks like 0.66 How can I prevent the zero before the decimal…
Elliott
  • 360
  • 1
  • 4
  • 15
0
votes
1 answer

What's setf and is it a valid function in Dr.Racket?

I have an assignment where I have to define an alias to an expression, in one of the guides we are told to use either setf or lists of lists to define them. To be more specific we need to assign to the alias ADD/SUCC/PRED/etc their lambda calculus…
0
votes
1 answer

Dynamically defining setf expanders

I'm trying to define a macro that'll take a struct's name, a key, and the name of a hash table in the struct and define functions to access and modify the value under the key in the hash. (defmacro make-hash-accessor (struct-name key hash) (let…
0
votes
1 answer

Evaluation of setf forms

This question is about the Common Lisp setf macro, and how it evaluates its argument forms (and subforms)--namely, only once if they happen to appear more than once. (It is also partly follow-up to an example given in the comments at Using…
davypough
  • 1,847
  • 11
  • 21
0
votes
1 answer

LET and SETF in commonLISP

From what my teacher told me, I should use let to declare local variables and setf to declare global variables. I'm tried running the following code: (let (state-list (problem-initial-state problem)) (print state-list)) and I get NIL. However,…
Rui Loureiro
  • 119
  • 9
0
votes
1 answer

how to set.precision on multiple variables in a single cout

I have this in main: Product newProduct; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); newProduct.display(); in Product.cpp I have: cout << "$" << basePrice << " - " << name << " - " << cout.precision(1) << weight << "…
Dylan L.
  • 1,243
  • 2
  • 16
  • 35
0
votes
1 answer

print X number after the decimal point using the cout

I have this code: double a = 7.456789; cout.unsetf(ios::floatfield); cout.precision(5); cout << a; and also this one: double a = 798456.6; cout.unsetf(ios::floatfield); cout.precision(5); cout << a; the result of the first code is: 7.4568 Which…
John Oldman
  • 89
  • 2
  • 8
-6
votes
1 answer

Lisp: Find the setf way of doing the equivalent of fset

Find the setf way of doing the equivalent of fset in lisp.
1
2