[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Why sbcl don't throw a type-error when the command some is applied to a non proper sequence? Is not conforming to the CLHS?

TwirlwT

12/24/2015 11:19:00 AM

CL-USER> (let (a)
(declare (optimize (safety 3)))
(setq a (cons 4 8))
(some #'evenp a))
=> T

(defun cycle(l)
(let ((l1 (copy-list l)))
(nconc l1 l1)))

(let ((a (cycle (list 4 8))))
(declare (optimize (safety 3)))
(every #'evenp a))

=>
This runs forever and doesn't signal a type-error as required by a conforming implementation, as state in my local copy of the hyperspec at file:///usr/share/doc/hyperspec/Body/f_everyc.htm
14 Answers

TwirlwT

12/24/2015 11:45:00 AM

0

El jueves, 24 de diciembre de 2015, 12:19:13 (UTC+1), TwirlwT escribió:
> CL-USER> (let (a)
> (declare (optimize (safety 3)))
> (setq a (cons 4 8))
> (some #'evenp a))
> => T
>
> (defun cycle(l)
> (let ((l1 (copy-list l)))
> (nconc l1 l1)))
>
> (let ((a (cycle (list 4 8))))
> (declare (optimize (safety 3)))
> (every #'evenp a))
>
> =>
> This runs forever and doesn't signal a type-error as required by a conforming implementation, as state in my local copy of the hyperspec at file:///usr/share/doc/hyperspec/Body/f_everyc.htm

The above behavior was with sbcl:
> (lisp-implementation-type) => "SBCL"
> (lisp-implementation-version) => 1.2.14.debian.


In gcl, the code with some signals a type-error (as expected), but the code
with every runs forever.

> (lisp-implementation-version)

"GCL 2.6.12"

In my personal opinion testing for non-proper sequences is expensive and I prefer to have more speed available. Perhaps a strict-mode creating an upper safety level (for example (safety 4)).

Pascal J. Bourguignon

12/24/2015 7:01:00 PM

0

TwirlwT <danieltorridoverde@gmail.com> writes:

> CL-USER> (let (a)
> (declare (optimize (safety 3)))
> (setq a (cons 4 8))
> (some #'evenp a))
> => T

It's still NON-CONFORMING.

You CAN behead people, and rape girls, but it's still ILLEGAL in
civilized countries.


> (defun cycle(l)
> (let ((l1 (copy-list l)))
> (nconc l1 l1)))
>
> (let ((a (cycle (list 4 8))))
> (declare (optimize (safety 3)))
> (every #'evenp a))
>
> =>
> This runs forever and doesn't signal a type-error as required by a
> conforming implementation, as state in my local copy of the hyperspec
> at file:///usr/share/doc/hyperspec/Body/f_everyc.htm

And even if your implemented returned true or NIL, or signaled an error,
it would still be non-conforming.


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Pascal J. Bourguignon

12/24/2015 7:06:00 PM

0

TwirlwT <danieltorridoverde@gmail.com> writes:

> In my personal opinion testing for non-proper sequences is expensive
> and I prefer to have more speed available. Perhaps a strict-mode
> creating an upper safety level (for example (safety 4)).

Actually, testing for dotted lists is 0 cost, just use ENDP instead of
NULL, and testing for circular lists only costs in temporary space 1
more reference, and O(n) accesses, which are free while under the cache
size.

Granted, for lists much bigger than caches, it will use 2 cache lines
instead of 1. So calling CDR twice shouldn't represent a dramatic slow
down. I would argue that an implementation could check for
non-proper-lists while processing lists sequencially without noticeable
downside.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Norbert_Paul

12/27/2015 1:51:00 PM

0

Pascal J. Bourguignon wrote:
> TwirlwT<danieltorridoverde@gmail.com> writes:
>
>> CL-USER> (let (a)
>> (declare (optimize (safety 3)))
>> (setq a (cons 4 8))
>> (some #'evenp a))
>> => T
>
> It's still NON-CONFORMING.
>
> You CAN behead people, and rape girls, but it's still ILLEGAL in
> civilized countries.
>
>
>> (defun cycle(l)
>> (let ((l1 (copy-list l)))
>> (nconc l1 l1)))
>>
>> (let ((a (cycle (list 4 8))))
>> (declare (optimize (safety 3)))
>> (every #'evenp a))
>>
>> =>
>> This runs forever and doesn't signal a type-error as required by a
>> conforming implementation, as state in my local copy of the hyperspec
>> at file:///usr/share/doc/hyperspec/Body/f_everyc.htm
>
> And even if your implemented returned true or NIL, or signaled an error,
> it would still be non-conforming.

Just to please my curiosity: Why is it non-conforming?

Norbert

Pascal J. Bourguignon

12/27/2015 5:08:00 PM

0

Norbert_Paul <norbertpauls_spambin@yahoo.com> writes:

> Pascal J. Bourguignon wrote:
>> TwirlwT<danieltorridoverde@gmail.com> writes:
>>
>>> CL-USER> (let (a)
>>> (declare (optimize (safety 3)))
>>> (setq a (cons 4 8))
>>> (some #'evenp a))
>>> => T
>>
>> It's still NON-CONFORMING.
>>
>> You CAN behead people, and rape girls, but it's still ILLEGAL in
>> civilized countries.
>>
>>
>>> (defun cycle(l)
>>> (let ((l1 (copy-list l)))
>>> (nconc l1 l1)))
>>>
>>> (let ((a (cycle (list 4 8))))
>>> (declare (optimize (safety 3)))
>>> (every #'evenp a))
>>>
>>> =>
>>> This runs forever and doesn't signal a type-error as required by a
>>> conforming implementation, as state in my local copy of the hyperspec
>>> at file:///usr/share/doc/hyperspec/Body/f_everyc.htm
>>
>> And even if your implemented returned true or NIL, or signaled an
>> error,
>> it would still be non-conforming.
>
> Just to please my curiosity: Why is it non-conforming?

http://www.lispworks.com/documentation/HyperSpec/Body...

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Norbert_Paul

12/27/2015 7:08:00 PM

0

Pascal J. Bourguignon wrote:
> Norbert_Paul<norbertpauls_spambin@yahoo.com> writes:
>
>> Pascal J. Bourguignon wrote:
>>> TwirlwT<danieltorridoverde@gmail.com> writes:
>>>
>>>> CL-USER> (let (a)
>>>> (declare (optimize (safety 3)))
>>>> (setq a (cons 4 8))
>>>> (some #'evenp a))
>>>> => T
>>>
>>> It's still NON-CONFORMING.
>>>
>>> You CAN behead people, and rape girls, but it's still ILLEGAL in
>>> civilized countries.
>>>
>>>
>>>> (defun cycle(l)
>>>> (let ((l1 (copy-list l)))
>>>> (nconc l1 l1)))
>>>>
>>>> (let ((a (cycle (list 4 8))))
>>>> (declare (optimize (safety 3)))
>>>> (every #'evenp a))
>>>>
>>>> =>
>>>> This runs forever and doesn't signal a type-error as required by a
>>>> conforming implementation, as state in my local copy of the hyperspec
>>>> at file:///usr/share/doc/hyperspec/Body/f_everyc.htm
>>>
>>> And even if your implemented returned true or NIL, or signaled an
>>> error,
>>> it would still be non-conforming.
>>
>> Just to please my curiosity: Why is it non-conforming?
>
> http://www.lispworks.com/documentation/HyperSpec/Body...

OK, but which of those rules is then violated by the above code?

Tom Russ

12/27/2015 7:58:00 PM

0

On Sunday, December 27, 2015 at 11:08:33 AM UTC-8, Norbert_Paul wrote:
> Pascal J. Bourguignon wrote:
> > Norbert_Paul<norbertpauls_spambin@yahoo.com> writes:
> >
> >> Just to please my curiosity: Why is it non-conforming?
> >
> > http://www.lispworks.com/documentation/HyperSpec/Body...
>
> OK, but which of those rules is then violated by the above code?

It is applying a function that the spec defines as applicable only to proper sequences and applies
it to a non-proper sequence (list). The spec for EVERY, etc. says
"Should signal type-error if its first argument is neither a symbol nor a function
or if any subsequent argument is not a proper sequence."

So it is a type error, and any code that does this is non-conforming.

Also, since the standard says "Should signal" instead of "Shall signal", implementations are not required
to signal an error if they get a dotted list or a circular list.

Barry Margolin

12/27/2015 8:08:00 PM

0

In article <9abdf8a0-649b-43ef-ba6e-4fb844f24f4e@googlegroups.com>,
Tom Russ <taruss2000@gmail.com> wrote:

> Also, since the standard says "Should signal" instead of "Shall signal",
> implementations are not required
> to signal an error if they get a dotted list or a circular list.

The description of "should signal" says that implementations are
required to signal in safe code.

And the examples have (safety 3), so they're required to signal.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Pascal J. Bourguignon

12/27/2015 8:20:00 PM

0

Norbert_Paul <norbertpauls_spambin@yahoo.com> writes:

> OK, but which of those rules is then violated by the above code?

The rule that EVERY takes a sequence, not a circular list.

If you pass a dotted list or a circular list to a function that takes a
proper list or a sequence, then you go to unspecified or implementation
dependant behavior, and your code is not conforming.

To make it conforming, you would have to write:

(defun cycle(l)
(let ((l1 (copy-list l)))
(nconc l1 l1)))

#-implementation-that-accepts-circular-list-for-EVERY
(defun myevery (pred object)
(every pred (com.informatimago.common-lisp.cesarum.list:list-elements object)))

(let ((a (cycle (list 4 8))))
(declare (optimize (safety 3)))
(#+implementation-that-accepts-circular-list-for-EVERY every
#-implementation-that-accepts-circular-list-for-EVERY my-every
(function evenp) a))


MYEVERY could even be more complex, if you also had to deal with
vectors and multiple lists, etc, and wanted to avoid copying the lists
(which LIST-ELEMENTS does), and wanted to avoid calling PRED multiple
times on the same element (EVERY shall stop calling the predicate as
soon as the result is determined).

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Barry Margolin

12/27/2015 9:56:00 PM

0

In article <8760zjfxug.fsf@kuiper.lan.informatimago.com>,
"Pascal J. Bourguignon" <pjb@informatimago.com> wrote:

> The rule that EVERY takes a sequence, not a circular list.

I thought the question in this thread is whether the *implementation* is
conforming when it doesn't signal an error. It's clear that the code is
non-conforming, and that's why an error was supposed to be signalled.

Since the spec says that an error is signalled in safe code,
implementations that don't do so are non-conforming.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***