Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- From: Pascal Bourguignon <spam@xxxxxxxxxxxxxxxx>
- Date: Tue, 24 Jan 2006 20:51:23 +0100
"Coby Beck" <cbeck@xxxxxxxxxxxxx> writes:
> "Pascal Bourguignon" <spam@xxxxxxxxxxxxxxxx> wrote in message
> news:87zmll4l5w.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> Peter Seibel <peter@xxxxxxxxxxxxxxx> writes:
>>
>>> Pascal Bourguignon <spam@xxxxxxxxxxxxxxxx> writes:
>>>
>>>> (defun find-indices (list pred)
>>>> (loop
>>>> :for index :from 1 ; (I can't see why you start from 1
>>>> :for element :in list ; the first index is 0 (try nth)).
>>>> :when (funcall pred element) :collect index))
>>>>
>>>> (Use of keywords instead of symbols is to prevent name colision when
>>>> you use after a package that exports a symbol by the same name).
>>>
>>> What bad consequence of such "name collisions" are you worried about?
>>
>> Name collisions can have catastrophic consequences when they occur in
>> non-interactive executions. And anyways, I'm lazy, I don't like to
>> answer silly questions about what symbols I want by the restart code...
>>
>>
>>> I can see maybe wanting to use keywords to make them stand out to the
>>> human eye, but for exactly the same reason you can use keywords you
>>> can use any symbol, from any package, with the right SYMBOL-NAME.
>>> Which I'm sure you know. So I wonder why you're trying to scare the
>>> newbies with this vague threat of bad things possibly happening in the
>>> future that can't actually happen. Or am I totally missing something?
>>
>> Well, it actually happened to me.
>
> Please share. I can't think of what could possibly go wrong either. And
> given how unidiomatic it is, it is worth knowing if there actually is some
> danger.
I already explained it.
(defpackage :p1
(:use :cl) (:export :for))
(in-package :p1)
(defmacro for ((var init limit increment) &body body)
`(do ((,var ,init ,increment))
((not ,limit))
,@body))
(in-package :cl-user)
(loop for i from 1 to 10 collect i)
(use-package :p1)
#<PACKAGE P1>
[398]> #<PACKAGE P1>
P1[399]> FOR
P1[400]> #<PACKAGE COMMON-LISP-USER>
[401]> (1 2 3 4 5 6 7 8 9 10)
[402]>
*** - (USE-PACKAGE (#<PACKAGE P1>) #<PACKAGE COMMON-LISP-USER>): 1 name
conflicts remain
Which symbol with name "FOR" should be accessible in
#<PACKAGE COMMON-LISP-USER>
?
The following restarts are available:
P1 :R1 #<PACKAGE P1>
COMMON-LISP-USER :R2 #<PACKAGE COMMON-LISP-USER>
ABORT :R3 ABORT
Break 1 [403]>
--
__Pascal Bourguignon__ http://www.informatimago.com/
"A TRUE Klingon warrior does not comment his code!"
.
- Follow-Ups:
- References:
- YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- From: John Connors
- Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- From: Pascal Bourguignon
- Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- From: Peter Seibel
- Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- From: Pascal Bourguignon
- Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- From: Coby Beck
- YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- Prev by Date: Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- Next by Date: Re: Lisp is Sin
- Previous by thread: Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- Next by thread: Re: YANQ - When to map, when to iterate, when to recurse? And why CLOS?
- Index(es):