Re: scantokens

"Daniel H. Luecking" <[email protected]>
Newsgroups gmane.comp.tex.metapost
Message-ID <MWHPR04MB0526D6ABD5A0493BDEEDE5B5B91F0@MWHPR04MB0526.namprd04.prod.outlook.com>
Walt:


After expansion,

  n[i] := scantokens aa;

becomes

  n[i] := 12 34 45 1 0  234;

which is invalid.


You should arrange to either (1) split off the numbers in

aa one at a time, or (2) create mydata with a separate line

for each number and read it one line at a time.


Cheers,

Daniel H. Luecking [[email protected]]
Department of Mathematical Sciences
1 University of Arkansas
Fayetteville, AR, USA 72701-1201


________________________________
From: metapost <[email protected]> on behalf of Walt Burkhard <[email protected]>
Sent: Friday, April 21, 2017 6:13 PM
To: Metapost List
Subject: [metapost] scantokens

Hello Fellow MetaPosters,

I am using the scantokens command and have observed some rather weird standard output remarks. ---

Here is my program ---

string aa ;
numeric n[] , i , j , len ;
numeric wide ;
%%  mydata contains one sequence of numbers " 12 34 45 1 0  234"

vardef mydigits ( expr nn ) =
  numeric w ;
  if (nn > 99) and (nn < 1000) :
    w := 3 ;
    w
  elseif (nn > 9) and (nn < 100) :
    w := 2 ;
    w
  else :
    w := 1 ;
    w
  fi
enddef ;

aa := readfrom ( "mydata" ) ;
message ("aa "&aa ) ;

for i = 0 upto 5 :
  len := length aa ;
  spaces := 0 ;
  for j = 0 upto len :
    if substring (j,j+1) of aa = " " :  spaces := spaces+1 ; else : fi exitif true ; fi ;
  endfor ;
  aa := substring (spaces,len) of aa ;
  n[i] := scantokens aa ;
  wide :=  mydigits ( n[i] ) ;
  len := length aa ;
  aa := substring (wide,len) of aa ;
endfor ;

for i = 0 upto 5 :
  message ( "n["&decimal i&"] "&decimal n[i] ) ;
endfor ;

end


AND here is the mydata file ---

 12 34 45 1 0  234

The scantokens commands seem to want to indicate that there is more to read than just the next number!

Here is a portion of the output I obtain ---

This is MetaPost, version 1.9991 (TeX Live 2016) (kpathsea version 6.2.2)
(/usr/local/texlive/2016/texmf-dist/metapost/base/mpost.mp<https://urldefense.proofpoint.com/v2/url?u=http-3A__mpost.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=qWEXXzhF1oqlzQC88L7WnGB_k10FjyBQUf-ed2VmV4E&e=>
(/usr/local/texlive/2016/texmf-dist/metapost/base/plain.mp<https://urldefense.proofpoint.com/v2/url?u=http-3A__plain.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=bzeG1FO7B6JSDFzqFBYQxs6AvZwpxA97bwS3Y5zQlk4&e=>
Preloading the plain mem file, version 1.005) ) (./mytest.mp<https://urldefense.proofpoint.com/v2/url?u=http-3A__mytest.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=-O3lzwAypZSOmpyVVf1gSe5NMlTV6xkuFZdrBrN7-yY&e=>
aa  12 34 45 1 0  234
! Extra tokens will be flushed.
<to be read again>
                   34
<scantokens> 12 34
                   45 1 0  234
<to be read again>
                   ;
<for(0)> ...s,len)of.aa;n[(EXPR0)]:=scantokens.aa;
                                                  wide:=mydigits(n[(EXPR0)])...
l.34 endfor
            ;

MetaPost interrupts the processing at this point, but if an "r" is entered from the keyboard, MetaPost continues
with much more similar output and then finally ---

n[0] 12
n[1] 34
n[2] 45
n[3] 1
n[4] 0
n[5] 234 )

Is there a way to avoid these extra standard output remarks?


Many thanks in advance.

Walt
ps    The zipped file jkljkl.zip contains both mytest.mp<https://urldefense.proofpoint.com/v2/url?u=http-3A__mytest.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=-O3lzwAypZSOmpyVVf1gSe5NMlTV6xkuFZdrBrN7-yY&e=> and mydata.

--
http://tug.org/metapost/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.