drifter cell for class types (cells)

Discussion of Common Lisp
Post Reply
hewih
Posts: 30
Joined: Tue Jan 19, 2010 9:36 am

drifter cell for class types (cells)

Post by hewih » Sun Feb 07, 2010 2:50 pm

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?

Code: Select all

(object-pos (make-instance 'position2d
                 :value (cells:c... ((vector2d-0)) (translation2d-of object-mover))
                                      ))

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: drifter cell for class types (cells)

Post by ramarren » Sun Feb 07, 2010 3:14 pm

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.

hewih
Posts: 30
Joined: Tue Jan 19, 2010 9:36 am

Re: drifter cell for class types (cells)

Post by hewih » Sun Feb 07, 2010 3:28 pm

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:

Code: Select all

(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.

Code: Select all

(make-instance 'myclass
          :slot1 1
          :slot2 2
          :slot3 3
          )

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: drifter cell for class types (cells)

Post by ramarren » Sun Feb 07, 2010 3:37 pm

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.

hewih
Posts: 30
Joined: Tue Jan 19, 2010 9:36 am

Re: drifter cell for class types (cells)

Post by hewih » Sun Feb 07, 2010 3:41 pm

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:

Post Reply