From: Slobodan Blazeski
Subject: Weird read-from-string behaviour
Date: 
Message-ID: <1192356377.983016.230480@i38g2000prf.googlegroups.com>
(read-from-string "abcdefg" )
ABCDEFG
7

 (read-from-string "abcdefg" :start 1 :end 2)
AB
2

(read-from-string "abcdefg" :start 4 :end 5)
ABCDE
5

Shouldn't this above return  EF instead of  ABCDE? It seems that read-
from-string is ignoring :start argument. Why?

Slobodan

From: Rainer Joswig
Subject: Re: Weird read-from-string behaviour
Date: 
Message-ID: <joswig-25EC3E.12192914102007@news-europe.giganews.com>
In article <························@i38g2000prf.googlegroups.com>,
 Slobodan Blazeski <·················@gmail.com> wrote:

> (read-from-string "abcdefg" )
> ABCDEFG
> 7
> 
>  (read-from-string "abcdefg" :start 1 :end 2)
> AB
> 2
> 
> (read-from-string "abcdefg" :start 4 :end 5)
> ABCDE
> 5
> 
> Shouldn't this above return  EF instead of  ABCDE? It seems that read-
> from-string is ignoring :start argument. Why?
> 
> Slobodan

Well, this is the unfortunate design of the parameter list
of READ-FROM-STRING, which leads to these errors.

Try:

? (read-from-string "abcdefg" nil nil :start 4 :end 5)
E
5
From: ···············@gmail.com
Subject: Re: Weird read-from-string behaviour
Date: 
Message-ID: <1192373110.748474.24960@e34g2000pro.googlegroups.com>
This is in the comp.lang.lisp FAQ

http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part3/faq-doc-1.html

[3-0] Why does (READ-FROM-STRING "foobar" :START 3) return FOOBAR
instead of BAR?

READ-FROM-STRING is one of the rare functions that takes both
&OPTIONAL and
&KEY arguments:

       READ-FROM-STRING string &OPTIONAL eof-error-p eof-value
                               &KEY :start :end :preserve-whitespace

When a function takes both types of arguments, all the optional
arguments must be specified explicitly before any of the keyword
arguments may be specified.  In the example above, :START becomes the
value of the optional EOF-ERROR-P parameter and 3 is the value of the
optional EOF-VALUE parameter.

To get the desired result, you should use
   (READ-FROM-STRING "foobar" t nil :START 3)
If you need to understand and use the optional arguments, please refer
to CLTL2 under READ-FROM-STRING, otherwise, this will behave as
desired for most purposes.



On Oct 14, 6:06 am, Slobodan Blazeski <·················@gmail.com>
wrote:
> (read-from-string "abcdefg" )
> ABCDEFG
> 7
>
>  (read-from-string "abcdefg" :start 1 :end 2)
> AB
> 2
>
> (read-from-string "abcdefg" :start 4 :end 5)
> ABCDE
> 5
>
> Shouldn't this above return  EF instead of  ABCDE? It seems that read-
> from-string is ignoring :start argument. Why?
>
> Slobodan
From: Slobodan Blazeski
Subject: Re: Weird read-from-string behaviour
Date: 
Message-ID: <1192446681.402241.50170@v23g2000prn.googlegroups.com>
Thanks for the both replies.

slobodan blazeski
On Oct 14, 8:45 am, ················@gmail.com"
<············@gmail.com> wrote:
> This is in the comp.lang.lisp FAQ
>
> http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part3/faq-doc-1.html
>
> [3-0] Why does (READ-FROM-STRING "foobar" :START 3) return FOOBAR
> instead of BAR?
>
> READ-FROM-STRING is one of the rare functions that takes both
> &OPTIONAL and
> &KEY arguments:
>
>        READ-FROM-STRING string &OPTIONAL eof-error-p eof-value
>                                &KEY :start :end :preserve-whitespace
>
> When a function takes both types of arguments, all the optional
> arguments must be specified explicitly before any of the keyword
> arguments may be specified.  In the example above, :START becomes the
> value of the optional EOF-ERROR-P parameter and 3 is the value of the
> optional EOF-VALUE parameter.
>
> To get the desired result, you should use
>    (READ-FROM-STRING "foobar" t nil :START 3)
> If you need to understand and use the optional arguments, please refer
> to CLTL2 under READ-FROM-STRING, otherwise, this will behave as
> desired for most purposes.
>
> On Oct 14, 6:06 am, Slobodan Blazeski <·················@gmail.com>
> wrote:
>
> > (read-from-string "abcdefg" )
> > ABCDEFG
> > 7
>
> >  (read-from-string "abcdefg" :start 1 :end 2)
> > AB
> > 2
>
> > (read-from-string "abcdefg" :start 4 :end 5)
> > ABCDE
> > 5
>
> > Shouldn't this above return  EF instead of  ABCDE? It seems that read-
> > from-string is ignoring :start argument. Why?
>
> > Slobodan