Hacker News new | ask | show | jobs
by amno 689 days ago
I am with you, I think setf is making code repetitive and more verbose in many cases, however in this particular case, if you see

    (var *some-object* value)
somewhere far away from the class definition, say in another file, can you tell immediately what that code does? Can you understand it directly by looking at the code? Do you define something? Do you set something or do you just read something like a property list (something like rassoc)?

    (setf (var *some-object*) value)
With setf it is immediately clear from the code what is going on. I don't know if that is the best example, just thinking of all the arguments for and against setf :). Personally, I find it makes code more verbose in many situations.
1 comments

Since I was talking about accessors / generic functions, I don't get the point of this example:

    (var *some-object* value)
because we also use SETF with accessors:

    (setf (var *some-object*) value)
Quick example:

    (defclass person () 
      ((name :accessor name)))

    (make-instance 'person)

    (setf (name *) "me")