[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: SBCL complains where Lispwork does not: loop for i for j

William James

11/18/2015 9:54:00 PM

Jochen wrote:

> > This ...
> >
> > CL-USER 1 > (loop for i for j in '(a b c) collect (cons i j))
> > => ((0 . A) (1 . B) (2 . C))
> >
> > works perfectly on LispWorks, but not with SBCL
> >
> > => FOR is an unknown keyword in FOR or AS clause in LOOP.
> >
> > I found a way around it 'for i from 0' but am not sure if there is
> > another smarter way to achieve this.
>
> I think the canonical way would be
>
> (loop for i upfrom 0
> for j in '(a b c)
> collect (cons i j))

MatzLisp (Ruby):

(:a .. :f).each_with_index.map{|c,i| [i,c]}
===>[[0, :a], [1, :b], [2, :c], [3, :d], [4, :e], [5, :f]]

--
The conclusion of this analysis is that democracy is identified not with the
power of the people to pursue their perceived interests. Rather, democracy is
conceptualized as guaranteeing that majorities will not resist the expansion of
power of minorities even if that means a decline in their own power.
--- Dr. Kevin MacDonald; "The Frankfurt School of Social Research and the
Pathologization of Gentile Group Allegiances"
1 Answer

William James

5/8/2016 6:49:00 PM

0

WJ wrote:

> Jochen wrote:
>
> > > This ...
> > >
> > > CL-USER 1 > (loop for i for j in '(a b c) collect (cons i j))
> > > => ((0 . A) (1 . B) (2 . C))
> > >
> > > works perfectly on LispWorks, but not with SBCL
> > >
> > > => FOR is an unknown keyword in FOR or AS clause in LOOP.
> > >
> > > I found a way around it 'for i from 0' but am not sure if there is
> > > another smarter way to achieve this.
> >
> > I think the canonical way would be
> >
> > (loop for i upfrom 0
> > for j in '(a b c)
> > collect (cons i j))
>
> MatzLisp (Ruby):
>
> (:a .. :f).each_with_index.map{|c,i| [i,c]}
> ===>[[0, :a], [1, :b], [2, :c], [3, :d], [4, :e], [5, :f]]

OCaml:

List.mapi (fun i s -> i,s) ["alpha";"beta";"camel"];;
===>
[(0, "alpha"); (1, "beta"); (2, "camel")]

--
[T]he number of Jews killed there was 800,000,000.... [T]he Talmud makes it all
clear by informing us that the blood of the holocausted Jews ran to the sea in
a huge tidal wave that swept boulders in its path and was so deep that it
reached the nostrils of the Romans' horses.
nationalvanguard.org/2014/09/disillusioned-part-1/