Newsgroups: comp.lang.lisp
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Sat, 10 Nov 2012 00:40:41 +0100
Local: Fri, Nov 9 2012 6:40 pm
Subject: Re: destructively changing the cdr of a sublist in a function
ccc31807 <carte...@gmail.com> writes:
Try:
> On Friday, November 9, 2012 11:40:06 AM UTC-5, Barry Margolin wrote: >> You're making a silly mistake, see below. > Yes, thanks, I see that.
>> The syntax of SETF is:
>> There's one other thing: you shouldn't perform destructive modification > I'm trying my hand at a mancala type game (by way of explanation). Here is what I finally came up with. I won't ask you for comments, but would appreciate it if you have any.
> -------------code--------------------
> (defun drop-pebbles-helper (new-state num-pebbles start-square factor)
> ((0 . 2) (1 . 1) (2 . 0) (3 . 0) (4 . 3) (5 . 1))
(defun display-mancala (state &optional (stream *standard-output*))
(display-mancala '((0 . 2) (1 . 1) (2 . 0) (3 . 0) (4 . 3) (5 . 1)))
If you encapsulate your lists in clos objects, then you can write a
(defclass mancala ()
(defmethod print-object ((self mancala) stream)
(make-instance 'mancala :state '((0 . 2) (1 . 1) (2 . 0) (3 . 0) (4 . 3) (5 . 1)))
-- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||