From: B.B.
Subject: loop for i across s
Date: 
Message-ID: <DoNotSpamthegoat4-F8D09B.00452716042004@library.airnews.net>
   I can't figure out why this is broken.


[360]> (let ((s (make-sequence 'string 15)))
  (loop for i across s
        do (setf i #\a)
        finally (return s)))
"               "
[361]> 

   Help?

-- 
B.B.           --I am not a goat!       thegoat4 at airmail.net
    Fire the stupid--Vote.

From: Lars Brinkhoff
Subject: Re: loop for i across s
Date: 
Message-ID: <85zn9ce9lr.fsf@junk.nocrew.org>
"B.B." <·················@airmail.net.com.org.gov.tw.ch.ru> writes:
>    I can't figure out why this is broken.
> [360]> (let ((s (make-sequence 'string 15)))
>   (loop for i across s
>         do (setf i #\a)
>         finally (return s)))
> "               "

Perhaps you meant to write
   (setf (char s i) #\a)
?

-- 
Lars Brinkhoff,         Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting    http://www.brinkhoff.se/
From: Petter Gustad
Subject: Re: loop for i across s
Date: 
Message-ID: <m34qrkp4ab.fsf@scimul.dolphinics.no>
Lars Brinkhoff <·········@nocrew.org> writes:

> "B.B." <·················@airmail.net.com.org.gov.tw.ch.ru> writes:
> >    I can't figure out why this is broken.
> > [360]> (let ((s (make-sequence 'string 15)))
> >   (loop for i across s
> >         do (setf i #\a)
> >         finally (return s)))
> > "               "
> 
> Perhaps you meant to write
>    (setf (char s i) #\a)

No, since the i does not represent the index, but rather the value at
the index

(let ((s "abcd"))
  (loop for i across s
        collect i))
(#\a #\b #\c #\d)


Petter
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Raymond Wiker
Subject: Re: loop for i across s
Date: 
Message-ID: <86hdvkcv02.fsf@raw.grenland.fast.no>
"B.B." <·················@airmail.net.com.org.gov.tw.ch.ru> writes:

>    I can't figure out why this is broken.
>
>
> [360]> (let ((s (make-sequence 'string 15)))
>   (loop for i across s
>         do (setf i #\a)
>         finally (return s)))
> "               "
> [361]> 
>
>    Help?

        I think it's because you're extracting the characters of the
string, and overwriting the copies of the characters, instead of
changing the string.

        The following works:

(let ((s (make-sequence 'string 15)))
  (let ((l (length s)))
    (loop for i below l
        do (setf (char s i) #\a)
        finally (return s))))

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/
From: Marco Antoniotti
Subject: Re: loop for i across s
Date: 
Message-ID: <gKWfc.33$a5.7481@typhoon.nyu.edu>
B.B. wrote:

>    I can't figure out why this is broken.
> 
> 
> [360]> (let ((s (make-sequence 'string 15)))
>   (loop for i across s
>         do (setf i #\a)
>         finally (return s)))
> "               "
> [361]> 
> 
>    Help?
> 

'i' is set to each element of the string (vector), hence the vector is 
not modified.  This will work

(let ((s (make-string 15 :initial-element #\Space)))
   (loop for i from 0 below (length s)
         do (setf (char s i) #\a)
         finally (return s)))

Alternatively

(let ((s (make-string 15 :initial-element #\Space)))
   (map-into s (constantly #\a) s))

Cheers

Marco
From: Ed Symanzik
Subject: Re: loop for i across s
Date: 
Message-ID: <c63opj$2ceg$1@msunews.cl.msu.edu>
If you just wanted a string of a's:

(make-string 15 :initial-element #\a)