gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] (novice) looking for example to use somevar=argv[1] ??


From: Francois Pussault
Subject: Re: [gforth] (novice) looking for example to use somevar=argv[1] ??
Date: Sun, 18 Jun 2017 08:58:51 +0200 (CEST)

Hi guys,

thanks again.
now I understand better

There are tow ways to do so .
call startup stack as numbers without any controls or call args as args and use 
them ; as you did in 
> : getvarnumbers
>     arg  2dup s>number?  if  drop  ararg ! ." I got a variable!  " ararg @ .
>                    else 2drop type
>                    then cr
> ;


I can make a little useless test :  like
address@hidden:~$ grep --color=always .  ~/Documents/DEV/forth/ascii2/ascii2.fs 
variable col
variable beta
variable betb
: ?CR 
        1 = IF CR 10 col ! cr  
        ELSE col @ 1 -  col ! 
        THEN 
;
: ASCII 
        DO col @ ?cr I . I EMIT ."  -  " 
        LOOP CR 
;
: MAIN
        beta !  beta @ 1 + beta !       \       arg from stack
        betb !                          \       arg from stack
        11 col !                        \       format on 10 columns
        beta @ betb @  ASCII            \       example 65 90
        CR
;
MAIN
cr
bye
address@hidden:~$ gforth -e '65 90' ~/Documents/DEV/forth/ascii2/ascii2.fs 
65 A -  66 B -  67 C -  68 D -  69 E -  70 F -  71 G -  72 H -  73 I -  74 J -  

75 K -  76 L -  77 M -  78 N -  79 O -  80 P -  81 Q -  82 R -  83 S -  84 T -  

85 U -  86 V -  87 W -  88 X -  89 Y -  90 Z -  


address@hidden:~$ 






> ----------------------------------------
> From: carl hansen <address@hidden>
> Sent: Sun Jun 18 03:02:22 CEST 2017
> To: Francois Pussault <address@hidden>
> Subject: Re: [gforth] (novice) looking for example to use somevar=argv[1] ??
> 
> 
> On Sat, Jun 17, 2017 at 1:47 PM, Francois Pussault
> <address@hidden> wrote:
> > Hello
> >
> > I don't understand the official doc page
> 
> I often can't understand it either.
> 
>  
> https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/OS-command-line-arguments.html
> 
> It says version 7.0, it might or might not be the latest version.
> 
> 
> > so I cannot use args.
> >
> > gforth  foo.fs  5 10
> > using a code like :
> >
> > 1 arg type CR
> >
> > display it  ok but as a text so I cannot affect that numbers to  variables
> >
> >
> >
> >
> >
> > Cordialement
> 
> likewise
> 
> > Francois Pussault
> > 10 chemin de négo saoumos
> > apt 202 - bat 2
> > 31300 Toulouse
> > +33 6 17 230 820
> > address@hidden
> >
> 
> Joel Rees is on track,  s>number? is the key for you. Here is
> something I got to work:
> 
> \ usage:  gforth argtest.fs  -e "34333" -e bye
> \ this file name is argtest.fs
> variable  ararg
> : getvarnumbers
>     arg  2dup s>number?  if  drop  ararg ! ." I got a variable!  " ararg @ .
>                    else 2drop type
>                    then cr
>                    ;
> 
> 0 dup .  getvarnumbers
> 1 dup .  getvarnumbers
> 2 dup .  getvarnumbers
> 3 dup .  getvarnumbers
> 4 dup .  getvarnumbers
> 
> ararg @ dup * . ." See? It works! " cr
> 
> \ try it like this:
> 
>   gforth argtest.fs  -e "34333" -e bye


Cordialement
Francois Pussault
10 chemin de négo saoumos
apt 202 - bat 2
31300 Toulouse
+33 6 17 230 820 
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]