From: Surendra Singhi
Subject: read-from-string - confusion
Date: 
Message-ID: <cmr4p9$bvo$1@news.asu.edu>
Hi,
   I am not able to understand why "Read-from-string" doesn't prints 3 
in the first example whereas it does in the second. Can anyone please 
explain it to me?

CG-USER(8): (read-from-string "1 3 5" :start 2)
1
2
CG-USER(9): (read-from-string "1 3 5" t nil :start 2)
3
4

Thanks,

Surendra Singhi

From: Marco Antoniotti
Subject: Re: read-from-string - confusion
Date: 
Message-ID: <PP8kd.12$E26.20088@typhoon.nyu.edu>
Surendra Singhi wrote:
> Hi,
>   I am not able to understand why "Read-from-string" doesn't prints 3 in 
> the first example whereas it does in the second. Can anyone please 
> explain it to me?
> 
> CG-USER(8): (read-from-string "1 3 5" :start 2)
> 1
> 2
> CG-USER(9): (read-from-string "1 3 5" t nil :start 2)
> 3
> 4
> 

It the first case the optional EOF-ERROR-P argument gets bound to :START 
and the optional EOF-VALUE gets bound to 2.  The keyword argument START 
is bound to the default (i.e. 0.)  In the second case you are respecting 
the CL calling conventions and you get what you espect.  The rule is 
that keyword arguments are "more optional" than optional arguments.  As 
Celine Dion would sing: that's the way it is. :)

Cheers
--
Marco
From: Pascal Bourguignon
Subject: Re: read-from-string - confusion
Date: 
Message-ID: <87ekj2ltid.fsf@naiad.informatimago.com>
Surendra Singhi <·········@netscape.net> writes:

> Hi,
>    I am not able to understand why "Read-from-string" doesn't prints 3
> in the first example whereas it does in the second. Can anyone please
> explain it to me?
> 
> CG-USER(8): (read-from-string "1 3 5" :start 2)
> 1
> 2
> CG-USER(9): (read-from-string "1 3 5" t nil :start 2)
> 3
> 4

READ-FROM-STRING takes optional arguments in addition to
keywords. Therefore in the first case, :start is taken as the first
optional argument, 2 as the second optional argument and there remains
no argument for the keywords.

There's only 4 functions in COMMON-LISP that take both optional and
keyword arguments.  If you want to use any of them with keywords, you
must give the optional arguments too. 

Didn't you realize that keywords arguments are optional too? You
cannot give only a second optional argument without giving the first
optional argument. Therefore youc annot give the keyword arguments
without giving the non-keyword optional arguments.

-- 
__Pascal Bourguignon__
From: Björn Lindberg
Subject: Re: read-from-string - confusion
Date: 
Message-ID: <hcsr7n2akvb.fsf@my.nada.kth.se>
Surendra Singhi <·········@netscape.net> writes:

> Hi,
>    I am not able to understand why "Read-from-string" doesn't prints 3
> in the first example whereas it does in the second. Can anyone please
> explain it to me?
> 
> CG-USER(8): (read-from-string "1 3 5" :start 2)
> 1
> 2
> CG-USER(9): (read-from-string "1 3 5" t nil :start 2)
> 3
> 4

This is the syntax of READ-FROM-STRING:

read-from-string string &optional eof-error-p eof-value &key start end
  preserve-whitespace

In your second try, the symbol :START and the number 2 will be
consumed by the optional arguments eof-error-p and eof-value. To be
able to use the keyword arguments you (unfortunately) need to specify
values for the optional arguments too.


Bj�rn
From: Jakub Travnik
Subject: Re: read-from-string - confusion
Date: 
Message-ID: <pan.2004.11.12.20.59.17.403994@sh.cvut.cz.no.sp.am>
On Tue, 09 Nov 2004 12:11:38 -0700, Surendra Singhi wrote:

> Hi,
>    I am not able to understand why "Read-from-string" doesn't prints 3
> in the first example whereas it does in the second. Can anyone please
> explain it to me?
> 
> CG-USER(8): (read-from-string "1 3 5" :start 2) 1
> 2
> CG-USER(9): (read-from-string "1 3 5" t nil :start 2) 3
> 4

see http://www.cliki.net/Infrequently%20Asked%20Questions

;-))