From: Mark Carter
Subject: newbie: initialising structures
Date: 
Message-ID: <d3c9c04.0310210611.161a9be2@posting.google.com>
I would like to initialise a structure, where some of the slots depend
on the other slots.

So what I have so far is:

(defstruct blog-entry
  fname
   (date (ddmmmyy (subseq :fname 1 7))))

where ddmmmyy is some function you don't need to worry about for the
purposes of this argument.

The problem is that when I do
(make-blog-entry :fname "m031021-01.txt")

I get the message

*** - :FNAME is not a sequence.

I've tried various combinations of things, all to no avail. I suppose
you could argue that I could write a function which fills in the
dependent values - but I think it would be safer to initialise them at
instantiation.

Is what I am trying to do undoable, or just plain evil? Should I be
using objects?

From: Barry Margolin
Subject: Re: newbie: initialising structures
Date: 
Message-ID: <Rjblb.121$lK3.9@news.level3.com>
In article <···························@posting.google.com>,
Mark Carter <············@ukmail.com> wrote:
>I would like to initialise a structure, where some of the slots depend
>on the other slots.
>
>So what I have so far is:
>
>(defstruct blog-entry
>  fname
>   (date (ddmmmyy (subseq :fname 1 7))))
>
>where ddmmmyy is some function you don't need to worry about for the
>purposes of this argument.
>
>The problem is that when I do
>(make-blog-entry :fname "m031021-01.txt")
>
>I get the message
>
>*** - :FNAME is not a sequence.

If it actually worked as you expected, it should be FNAME, not :FNAME.  The
latter is a keyword, which is always treated as a literal, not a variable.

>I've tried various combinations of things, all to no avail. I suppose
>you could argue that I could write a function which fills in the
>dependent values - but I think it would be safer to initialise them at
>instantiation.
>
>Is what I am trying to do undoable, or just plain evil? Should I be
>using objects?

You can do it with a BOA constructor:

(defstruct (blog-entry
             (:constructor
               (make-blog-entry (:key fname
                                      (date (ddmmmyy (subseq fname 1 7)))))))
  fname
  date)

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: james anderson
Subject: Re: newbie: initialising structures
Date: 
Message-ID: <3F954FE2.3DB7CFB7@setf.de>
Barry Margolin wrote:
> 
> ...
> 
> You can do it with a BOA constructor:
> 
> (defstruct (blog-entry
>              (:constructor
>                (make-blog-entry (:key fname
>                                       (date (ddmmmyy (subseq fname 1 7)))))))
>   fname
>   date)
> 

?

(defstruct (blog-entry
            (:constructor
             make-blog-entry (&key fname
                                   (date (ddmmmyy (subseq fname 1 7))))))
  date
  fname)
From: ·············@comcast.net
Subject: Re: newbie: initialising structures
Date: 
Message-ID: <k76ywq0j.fsf@comcast.net>
············@ukmail.com (Mark Carter) writes:

> I would like to initialise a structure, where some of the slots depend
> on the other slots.
>
> So what I have so far is:
>
> (defstruct blog-entry
>   fname
>    (date (ddmmmyy (subseq :fname 1 7))))
>
> where ddmmmyy is some function you don't need to worry about for the
> purposes of this argument.
>
> The problem is that when I do
> (make-blog-entry :fname "m031021-01.txt")
>
> I get the message
>
> *** - :FNAME is not a sequence.
>
> I've tried various combinations of things, all to no avail. I suppose
> you could argue that I could write a function which fills in the
> dependent values - but I think it would be safer to initialise them at
> instantiation.
>
> Is what I am trying to do undoable, or just plain evil? Should I be
> using objects?

I'd use object myself.

The trick is to use &AUX parameters in the constructor:

(defstruct (blog-entry
             (:constructor make-blog-entry 
                          (fname &aux (date (ddmmyy (subseq fname 1 7))))))
  fname
  date)