This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

drifter cell for class types (cells)

5 posts · 1719 views

i have a vector2d class and a position2d class which stores the position as a vector2d drifter cell called "value". the initial value should be a zero vector and then a vector2d should be added every time the translation value of a mover object is changed.

my question is, how do i define incf and decf functions for position2d.value which the drifter cell depends on?
or maybe there is some other way to define a value for initialization time and use (setf (vector-add .cache translation)) on change?
(object-pos (make-instance 'position2d
                 :value (cells:c... ((vector2d-0)) (translation2d-of object-mover))
                                      ))

Re: drifter cell for class types (cells)

You can specialize C-VALUE-INCF generic function on any pair of class values, and drifters will use them for updates. There is no DECF, since obviously INCFing by a negative value is equivalent. I haven't used drifters in practice, so I don't know for certain if this works, but there is no reason why it should not.

What's with the hanging parentheses? See this StackOverflow question for the reasons why not to leave parentheses on their own line.

Re: drifter cell for class types (cells)

24min, you were too fast this time -.-

> C-VALUE-INCF generic function

cool, thanks! :D

> What's with the hanging parentheses?

from the Stack Overflow article:
(defvar *persons*
   (list (make-person "fred")
         (make-person "jane")
         (make-person "susan)
         ))
i use this construct for aligned initarg definitions. i think it's more comfortable to kill and yank lines this way.
(make-instance 'myclass
          :slot1 1
          :slot2 2
          :slot3 3
          )

Re: drifter cell for class types (cells)

hewih wrote:i use this construct for aligned initarg definitions. i think it's more comfortable to kill and yank lines this way.
One of the primary reasons why I so much prefer using Lisp to any other language is that Emacs, especially with paredit, has s-expression motion/manipulation functions, which means one doesn't have to manipulate the code by lines. Although perhaps for this case lines may make more sense than C-Space C-M-F C-M-F C-W which I usually do... maybe I should rebind mark-sexp sometime. But this works even when the initarg spans more than one line.

Re: drifter cell for class types (cells)

i'm more like finding out how to uncomment regions, trim whitespaces and move the cursor to the last position at the moment, hahaha! :lol: