From: RG on
In article <87k4nviqiv.fsf(a)ma-patru.mathematik.uni-karlsruhe.de>,
Nicolas Neuss <lastname(a)kit.edu> wrote:

> RG <rNOSPAMon(a)flownet.com> writes:
>
> > In article <87r5i4jacm.fsf(a)ma-patru.mathematik.uni-karlsruhe.de>,
> > Nicolas Neuss <lastname(a)kit.edu> wrote:
> >
> >> RG <rNOSPAMon(a)flownet.com> writes:
> >>
> >> > The real heart of the system is the ITERATOR generic function, which
> >> > returns a closure that yields successive values of the iteration on
> >> > each call, and terminates by returning the privileged value +iterend+.
> >> > (It is not clear that this is really the Right Thing. The Right Thing
> >> > is probably to call THROW or raise a condition. The current
> >> > implementation should be considered more of a proof-of-concept than a
> >> > final design.)
> >>
> >> OK, I've looked at your code now. At some time I have thought myself
> >> about basing my interface on iterators, but somehow I did not come up
> >> with anything good. Probably it is time to reevaluate this again more
> >> carefully.
> >>
> >> IIUC, the iterator approach is more basic than the generic "FOR-EACH",
> >
> > Not sure what you mean by "the generic FOR-EACH". Can you be more
> > specific?
>
> (defmethod for-each (func (vec vector))
> (dotimes (i (length vec))
> (funcall func (aref vec i) i)))
>
> You can easily define this for other collections and base other
> functionality on it like MAP, REDUCE, etc. Also a parallel version
> splitting the work to several threads is straightforward.

OK, that's what I thought. I wouldn't call rg-iterators "more basic",
just different, though not radically so. The fundamental idea is the
same in both cases: have a single generic function that relates objects
to the code that iterates over them. The main difference is that
FOR-EACH creates that relationship directly, whereas rg-iterators
creates that relationship indirectly via a first-class iterator object
that acts as an intermediary between the generic function (ITERATOR) and
the iteration construct (FOR ... IN ...)

It is trivial to implement FOR-EACH in terms of FOR ... IN:

(defun for-each (fn thing)
(for element in thing do (funcall fn element)))

Going the other way is harder only because FOR ... IN leverages all the
LOOP goodies. But if you constrain yourself to FOR ... IN ... DO or FOR
.... IN ... COLLECT then it's trivial again:

(defmacro for (var in thing keyword &rest body)
(ecase keyword
(do (for-each (lambda (x) ,@body) ,thing))
(collect (with-collector collect
(for-each (lambda (x) (collect (progn ,@body)))
,thing)))))

modulo gensyms and multiple evaluation. WITH-COLLECTOR is a simple
macro whose code is also in rg-utils.lisp.

There are other minor differences as well, like the fact that
rg-iterators have an implicit multiple-value-call in the protocol. That
way you can do, e.g.:

(for key in dictionary ...)

or

(for (key value) in dictionary ...)

with the same iterator.

rg
From: Pascal Costanza on
On 12/08/2010 19:33, RG wrote:
> In article<8ci3lqFo28U1(a)mid.individual.net>,
> Pascal Costanza<pc(a)p-cos.net> wrote:
>
>> On 12/08/2010 03:19, RG wrote:
>>> In article
>>> <f1786719-65bc-44c4-bc2f-ba2105e89df8(a)f6g2000yqa.googlegroups.com>,
>>> Alessio Stalla<alessiostalla(a)gmail.com> wrote:
>>>
>>>> On 11 Ago, 23:05, RG<rNOSPA...(a)flownet.com> wrote:
>>>>> In article<877hjwandt....(a)kuiper.lan.informatimago.com>,
>>>>> p...(a)informatimago.com (Pascal J. Bourguignon) wrote:
>>>>>
>>>>>> RG<rNOSPA...(a)flownet.com> writes:
>>>>>
>>>>>>>> I would be interested in
>>>>>>>> trying it, especially if it comes under a reasonably liberal license
>>>>>>>> like BSD or LLGPL.
>>>>>
>>>>>>> I released it to the public domain last year.
>>>>>
>>>>>> Which means that you remains the only one entitled with the right to
>>>>>> make a copy of it, and your heirs until 70 years after your death.
>>>>>
>>>>> I don't know where you got that idea, but you are absolutely wrong.
>>>>> Releasing the work to the public domain means I have forfeited all my
>>>>> intellectual property rights and anyone can do anything they want with
>>>>> it, including use it in commercial software without any constraints
>>>>> whatsoever.
>>>>>
>>>>> http://en.wikipedia.org/wiki/Public_domain
>>>>>
>>>>>> Could you please try the GPL?
>>>>>
>>>>> Actually, I can't. The GPL requires that the work be copyrighted. Once
>>>>> a work enters the public domain then by definition it is no longer (and
>>>>> can no longer be) copyrighted.
>>>>
>>>> AFAIK, not all legislations have the concept of public domain.
>>>
>>> I am quite certain you are quite mistaken.
>>>
>>>> In some countries, you cannot give up your copyright on your work.
>>>
>>> Which countries are those exactly? What country do you live in?
>>
>> In Germany, you cannot give up your copyright.
>
> So if I have a copyrighted work I can't sell the copyright to someone
> else? Thank God I don't live in Germany.

You can sell the duplication rights to somebody else, but not the
creator's rights. You can only sell the duplication rights for a limited
amount of time, because otherwise this would amount to being the same as
selling your creator's right, which according to German law is not
possible. This distinction is made to protect creators.

>> (It actually makes a
>> finer distinction between creator's rights and copyright, and you cannot
>> give up creator's rights - simply because you _are_ the creator of your
>> work, giving that fact up would be like denying reality... ;)
>
> Well, now, you've just contradicted yourself. Is it my copyright I
> can't give up, or merely my "creator's rights" (whatever those might be)?

Merely the creator's rights.

> What are "creator's rights" anyway? I've never heard of such a concept
> before.

Yes, it's hard to translate. German law just makes a finer distinction here.

> Under what circumstances do they apply? I am a U.S. citizen
> living in the U.S. Do I have "creator's rights" under German law? Will
> the German government prosecute you on my behalf for violating my
> creator's rights by making a copy of rg-utils.lisp despite the fact that
> I have expressly given you (along with everyone else on the planet)
> permission to do so?

I have no idea. The other way around, though, is certainly a problem.

There is some, but not a lot of information, at
http://en.wikipedia.org/wiki/German_Copyright_Law


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/