[metapost] a better question

luigi scarso luigi.scarso at gmail.com
Fri Jan 6 12:18:36 CET 2017


On Thu, Jan 5, 2017 at 10:37 PM, Walt Burkhard <burkhard at cs.ucsd.edu> wrote:
> Hello
>
> I have a short metapost program attached the uses the reads from and
> scan token commands.   I do not understand why the program works
> in the way it does.     There are two files:   the file named stringTest
> contains one line  2.56  7.23   The file named test.mp is shown below.
>
> numeric n ;   string jkjk ;
>
> jkjk := readsfrom ( "stringTest" ) ;  message ( jkjk ) ;    % shows 2.56
> 7.23
>
> n := scantoken ( jkjk ) ;       % this parses/reads  2.56  and sets n to be
> 2.56
>                                           % evidently.
> message ( "n = "&decimal n ) ;        % shows n = 2.56
>
> n := scantoken ( jkjk ) ;       % still sets n to be 2.56
>
> I have attached both files here.  Any suggestions on how I should be reading
> the
> second numeric value from the string would be appreciated.   The User's
> guide
> says that the scantoken command processes tokens sequentially. (page 17)
>
> Many thanks in advance.
>
> Walt Burkhard
>
> --
> http://tug.org/metapost/

It seems ok to me, your program is not correct.

# mpost test.mp
This is MetaPost, version 1.9991 (TeX Live 2017/dev) (kpathsea version
6.2.3/dev)

(/texlive/2016/texmf-dist/metapost/base/mpost.mp
(/texlive/2016/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./test.mp
2.56  7.23
! Extra tokens will be flushed.
<to be read again>
                   7.23
<scantokens> 2.56  7.23

<to be read again>
                   ;
l.7 n := scantokens ( jkjk ) ;

?


-- 
luigi


More information about the metapost mailing list