4.4 Using the formatio Fragment

A program using the formatio fragment will have the following structure:

INCLUDE '~beta/basiclib/formatio
--- program: descriptor ---
(# ...
   r: @real;
do ...
   'real value: %e' -> putformat(# do r->e #);
   ..
#)

4.4.1 Illustrating putFormat

Program 3: putformatDemo.bet

ORIGIN '~beta/basiclib/formatio';
--- program: descriptor ---
(#
do 'string=%s, integer=%i, real=%f\n\n'
     -> putFormat(# do 'abc'->s; -30->i; 3.14->f #);
   
   '(1234567){12345678}[123456789]\n' -> putFormat;
   '(%7i){%8i}[%9i]\n\n' -> putFormat(# do 27->i; 30->i; -45->i #);
   
   '"%%s,%%.5s,%%s,%%2.3s#" = %s,%.5s,%s,%2.3s#\n\n'
     -> putFormat(# do '27'->s; 'Hello world'->s; '-45'->s; none->s #);

   '  123456789   1234567890123456       12345678\n' -> putFormat;
   'x=%9.3f,y=%16.e,z=%.8f\n\n'
     -> putFormat(# do 27.5->f; 30.5->e; -45.5->f #);

   '  1234567890   1234567890   12345678\n' -> putFormat;
   'x=%*.*f,y=%*.2e,z=%8.*f\n\n'
     -> putFormat(# do 10->width; 3->precision; 27.5->f; 30.5->e; -45.5->f #);

#)

4.4.2 Illustrating getFormat

Program 4: getformatDemo.bet

ORIGIN '~beta/basiclib/formatio';
--- program: descriptor ---
(# i1, i2, i3, i4, i5: @integer;
   s1, s2: ^text;
   r1, r2, r3: @real;
   chr: @char;
   t, fmt: ^text;
do '123,%456, 789 JorgenLKnudsen 1.2,2+2=43.45, 67.89 abc, 101, 0x101, 0101, 101xxx'->t[];
   0->t.pos;
   
   'input:\t"%s"\n\n' -> putFormat(# do t[]->s #); newline;
   
   '%i,%%%i, %i' -> fmt[] -> t.getFormat(# do i->i1; i->i2; i->i3 #);
   'format:\t%s\nread:\t%i, %i, %i\n\n'
     -> putFormat(# do fmt[]->s; i1->i; i2->i; i3->i #);
   
   '%6s%c%s' -> fmt[] -> t.getFormat(# do s->s1[]; c->chr; s->s2[] #);
   'format:\t"%s"\nread:\t"%s", "%c", "%s"\n\n'
     -> putFormat(# do fmt[]->s; s1[]->s; chr->c; s2[]->s #);
   
   '%f,2+2=4%e, %f' -> fmt[] -> t.getFormat(# do f->r1; e->r2; f->r3 #);
   'format:\t"%s"\nread:\t%f, %f, %f\n\n'
     -> putFormat(# do fmt[]->s; r1->f; r2->f; r3->f #);
      
   '%x, %o, %i, %i, %i%s' -> fmt[] 
     -> t.getFormat(# do x->i1; o->i2; i->i3; i->i4; i->i5; s->s1[] #);
   'format:\t"%s"\nread:\t%i, %i, %i, %i, %i, "%s"\n'
     -> putFormat(# do fmt[]->s; i1->i; i2->i; i3->i; i4->i; i5->i; s1[]->s #);
   
   '123,%456, 124 %JorgenLKnudsen 1.2,2+2=43.45, 67.89 abc, 111, 0x111, 0111, 111xxx'->t[];
   0->t.pos;
   '\n\ninput:\t"%s"\n\n' -> putFormat(# do t[]->s #); newline;
   
   '%i,%%%i, %i %6s%c%s%f' -> fmt[] -> t.getFormat(# do i->i1; i; i->i2; s; c; s; f->r1; #);
   'format:\t%s\nread:\t%i, %i, %f\n\n'
     -> putFormat(# do fmt[]->s; i1->i; i2->i; r1->f; #);
   
#)


Basic Libraries - Reference Manual
© 1990-2002 Mjølner Informatics
[Modified: Monday October 23rd 2000 at 11:49]