Given +foo+ and +bar+ (2 constants, value not really important here),
I'd like to make an unsigned-byte 8 sequence containing these two
values. The brute force way:
(let ((blob (make-array 2 :element-type '(unsigned-byte 8))))
(setf (aref blob 0) +foo+)
(setf (aref blob 1) +bar+)
blob))
But surely I ought to be able to use :initial-contents to populate the
array. I just haven't been able to find the right incantation that
makes everyone happy.
Any help appreciated.
On Dec 5, 12:04 pm, ····@stablecross.com (Bob Felts) wrote:
> Given +foo+ and +bar+ (2 constants, value not really important here),
> I'd like to make an unsigned-byte 8 sequence containing these two
> values. The brute force way:
>
> (let ((blob (make-array 2 :element-type '(unsigned-byte 8))))
> (setf (aref blob 0) +foo+)
> (setf (aref blob 1) +bar+)
> blob))
>
> But surely I ought to be able to use :initial-contents to populate the
> array. I just haven't been able to find the right incantation that
> makes everyone happy.
>
> Any help appreciated.
Not sure how you are specifying the initial-contents, but this worked
for me:
(make-array 2 :element-type '(unsigned-byte 8) :initial-contents (list
+foo+ +bar+))
or
(make-array 2 :element-type '(unsigned-byte 8) :initial-contents
(vector +foo+ +bar+))
HTH,
Tom
Thomas M. Hermann <··········@gmail.com> wrote:
> On Dec 5, 12:04 pm, ····@stablecross.com (Bob Felts) wrote:
> > Given +foo+ and +bar+ (2 constants, value not really important here),
> > I'd like to make an unsigned-byte 8 sequence containing these two
> > values. The brute force way:
> >
> > (let ((blob (make-array 2 :element-type '(unsigned-byte 8))))
> > (setf (aref blob 0) +foo+)
> > (setf (aref blob 1) +bar+)
> > blob))
> >
> > But surely I ought to be able to use :initial-contents to populate the
> > array. I just haven't been able to find the right incantation that
> > makes everyone happy.
> >
> > Any help appreciated.
>
> Not sure how you are specifying the initial-contents, but this worked
> for me:
>
> (make-array 2 :element-type '(unsigned-byte 8) :initial-contents (list
> +foo+ +bar+))
>
> or
>
> (make-array 2 :element-type '(unsigned-byte 8) :initial-contents
> (vector +foo+ +bar+))
>
I could have sworn I tried that. Thanks for the help.
Bob Felts wrote on 12/05/2008 01:04 PM:
> Given +foo+ and +bar+ (2 constants, value not really important here),
> I'd like to make an unsigned-byte 8 sequence containing these two
> values. The brute force way:
>
> (let ((blob (make-array 2 :element-type '(unsigned-byte 8))))
> (setf (aref blob 0) +foo+)
> (setf (aref blob 1) +bar+)
> blob))
>
> But surely I ought to be able to use :initial-contents to populate the
> array. I just haven't been able to find the right incantation that
> makes everyone happy.
What about:
(let ((blob (make-array 2 :element-type '(unsigned-byte 8)
:initial-contents (list +foo+ +bar+))))
blob)
?
Alberto