[Openmcl-devel] (null #())
Taoufik Dachraoui
dachraoui.taoufik at gmail.com
Sun Oct 7 09:47:23 PDT 2012
I found (or (null x) (zerop (length x))) simple and considering, if I
understand correctly, (alexandria:sequence-of-length-p sequence 0) is same
as (length v) on vectors; the solution for any sequence could be
(or (null x) (and (not (consp x)) (zerop (length x))))
I added (not (consp x)) to avoid (length x) when x is a cons and not null
Thanks
Taoufik
On Sun, Oct 7, 2012 at 5:30 PM, Stas Boukarev <stassats at gmail.com> wrote:
> Raymond Wiker <rwiker at gmail.com> writes:
>
> > On Oct 7, 2012, at 16:59 , Stas Boukarev <stassats at gmail.com> wrote:
> >> Taoufik Dachraoui <dachraoui.taoufik at gmail.com> writes:
> >>
> >>> Hi
> >>>
> >>> how to check that a sequence is null without using length?
> >> (alexandria:sequence-of-length-p sequence 0)
> >
> >
> > Or just
> >
> > (defun is-null-vector (v)
> > (and (vectorp v)
> > (zerop (first (array-dimensions v)))))
>
> (first (array-dimensions v)) is exactly (length v) on vectors.
> But the question was about sequences, not just vectors. LENGTH on lists
> is O(n), that's why it's undesirable. So, that leaves either
> alexandria:sequence-of-length-p or (or (null x) (zerop (length x)))
>
> --
> With best regards, Stas.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20121007/f685885e/attachment.htm>
More information about the Openmcl-devel
mailing list