Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #36085 > unrolled thread

Reducing C,

Started byjosv@planet.nl
First post2015-01-28 04:07 -0800
Last post2015-02-04 12:54 +0000
Articles 20 on this page of 75 — 16 participants

Back to article view | Back to comp.lang.forth


Contents

  Reducing C, josv@planet.nl - 2015-01-28 04:07 -0800
    Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-01-28 05:02 -0800
    Re: Reducing C, Howerd <howerdo@yahoo.co.uk> - 2015-01-28 07:42 -0800
      Re: Reducing C, josv@planet.nl - 2015-01-28 08:17 -0800
    Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-01-29 03:37 +1100
    Re: Reducing C, visualforth@rocketmail.com - 2015-01-28 12:53 -0800
    Re: Reducing C, humptydumpty <ouatubi@gmail.com> - 2015-01-28 14:03 -0800
    Re: Reducing C, humptydumpty <ouatubi@gmail.com> - 2015-01-28 20:39 -0800
      Re: Reducing C, humptydumpty <ouatubi@gmail.com> - 2015-01-28 20:51 -0800
        Re: Reducing C, josv@planet.nl - 2015-01-29 06:28 -0800
    Re: Reducing C, hughaguilar96@gmail.com - 2015-01-29 21:18 -0800
      Re: Reducing C, josv@planet.nl - 2015-01-30 05:38 -0800
        Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-01-30 15:11 +0000
          Re: Reducing C, josv@planet.nl - 2015-01-30 08:34 -0800
        Re: Reducing C, hughaguilar96@gmail.com - 2015-01-31 20:26 -0800
          Re: Reducing C, josv@planet.nl - 2015-02-01 11:16 -0800
            Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-02 11:03 +1100
              Re: Reducing C, "Elizabeth D. Rather" <erather@forth.com> - 2015-02-01 14:13 -1000
                Re: Reducing C, hughaguilar96@gmail.com - 2015-02-01 17:22 -0800
                Re: Reducing C, hughaguilar96@gmail.com - 2015-02-01 17:36 -0800
                  Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-02 11:40 +0000
                    Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-02 05:24 -0800
                      Netiquette was: Re: Reducing C, albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-02 13:40 +0000
                      Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-02 15:08 +0000
                        Politeness, was Re: Reducing C, "Rod Pemberton" <buzz@notnotnontnooatno.cmm> - 2015-02-02 19:30 -0500
                          Re: Politeness, was Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-03 01:57 +0100
                          Re: Politeness, was Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-03 11:59 +0000
                        Re: Reducing C, josv@planet.nl - 2015-02-03 02:31 -0800
                          Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-03 12:06 +0000
                            Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-03 19:47 +0000
                              Re: Reducing C, josv@planet.nl - 2015-02-03 14:06 -0800
                                Re: Reducing C, hughaguilar96@gmail.com - 2015-02-03 21:19 -0800
                                  Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 12:10 +0000
                                    Re: Reducing C, hughaguilar96@gmail.com - 2015-02-04 18:22 -0800
                                      Re: Reducing C, hughaguilar96@gmail.com - 2015-02-04 19:04 -0800
                                        Re: Reducing C, stephen@mpeforth.com (Stephen Pelc) - 2015-02-05 11:33 +0000
                                          Re: Reducing C, hughaguilar96@gmail.com - 2015-02-05 19:39 -0800
                                            Re: Reducing C, stephen@mpeforth.com (Stephen Pelc) - 2015-02-06 11:50 +0000
                                              Re: Reducing C, hughaguilar96@gmail.com - 2015-02-06 11:28 -0800
                                        Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-05 04:37 -0800
                                          Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-06 21:47 +1100
                                          Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-13 09:45 +1100
                                            Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-13 05:24 -0800
                                              Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-15 13:53 +1100
                                                Re: Reducing C, Mark Wills <markwills1970@gmail.com> - 2015-02-16 01:07 -0800
                                                  Re: Reducing C, anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-16 15:02 +0000
                                                  Re: Reducing C, "HAA" <someone@microsoft.com> - 2015-02-19 14:22 +1100
                                        Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-05 13:18 +0000
                                        Re: Reducing C, josv@planet.nl - 2015-02-05 07:02 -0800
                                          Re: Reducing C, josv@planet.nl - 2015-02-05 07:14 -0800
                                      Re: Reducing C, josv@planet.nl - 2015-02-07 07:12 -0800
                                  Re: Reducing C, josv@planet.nl - 2015-02-04 07:12 -0800
                                    Re: Reducing C, november.nihal@gmail.com - 2015-02-04 09:38 -0800
                                    Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 21:08 +0000
                                      Re: Reducing C, josv@planet.nl - 2015-02-05 06:45 -0800
                                        Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-06 13:21 +0000
                                  Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-05 17:36 +0100
                                    Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-05 17:06 +0000
                                      Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-05 18:17 +0100
                                      Re: Reducing C, "Elizabeth D. Rather" <erather@forth.com> - 2015-02-05 10:40 -1000
                                        Re: Reducing C, hughaguilar96@gmail.com - 2015-02-05 20:25 -0800
                                          Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-06 11:39 +0000
                                          Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-06 12:48 +0100
                                            Re: Reducing C, hughaguilar96@gmail.com - 2015-02-06 17:28 -0800
                                              Re: Reducing C, awegel@arcor.de (Alexander Wegel) - 2015-02-07 12:38 +0100
                                          Re: Reducing C, albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-06 14:40 +0000
                                            Re: Reducing C, hughaguilar96@gmail.com - 2015-02-06 18:33 -0800
                                      Re: Reducing C, anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-06 13:49 +0000
                                        Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-06 14:15 +0000
                              Re: Reducing C, hughaguilar96@gmail.com - 2015-02-03 21:23 -0800
                                Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 12:41 +0000
                              Re: Reducing C, "WJ" <w_a_x_man@yahoo.com> - 2015-02-04 18:19 +0000
                                Re: Reducing C, "WJ" <w_a_x_man@yahoo.com> - 2015-02-04 20:54 +0000
                  Re: Reducing C, "WJ" <w_a_x_man@yahoo.com> - 2015-02-04 09:41 +0000
                    Re: Reducing C, "Alex McDonald" <blog@rivadpm.com> - 2015-02-04 12:54 +0000

Page 1 of 4  [1] 2 3 4  Next page →


#36085 — Reducing C,

Fromjosv@planet.nl
Date2015-01-28 04:07 -0800
SubjectReducing C,
Message-ID<1a6def09-04e6-44d6-ac2e-bc3b3280c8d8@googlegroups.com>
\ Resently I needed some code to allot a number of bytes like:
create &test1
    8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
    9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,

\ All those C, looked quite boring and the number of allocated bytes was also missing.
\ The following byte$: solved my problem in Win32Forth.

: byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr-lcount )
   create  here dup , \ map: #bytes...
   begin bl nextword
         if count number?
            if   d>s true
            else drop
           then
         else false
         then
   while c,
   repeat here over - cell- swap !
   ;

debug byte$:

byte$: &test2
    8  0 13  3 10  2  7
    9  5 12  4  1  6 10 ;

.s &test2 lcount dump
\s
Is there a better way to define byte$: ?
Jos

[toc] | [next] | [standalone]


#36087

FromMark Wills <markwills1970@gmail.com>
Date2015-01-28 05:02 -0800
Message-ID<e98acef9-a0bd-4eb9-8871-e98d481f04f4@googlegroups.com>
In reply to#36085
On Wednesday, 28 January 2015 12:07:24 UTC, jo...@planet.nl  wrote:
> \ Resently I needed some code to allot a number of bytes like:
> create &test1
>     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
>     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
> 
> \ All those C, looked quite boring and the number of allocated bytes was also missing.
> \ The following byte$: solved my problem in Win32Forth.
> 
> : byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr-lcount )
>    create  here dup , \ map: #bytes...
>    begin bl nextword
>          if count number?
>             if   d>s true
>             else drop
>            then
>          else false
>          then
>    while c,
>    repeat here over - cell- swap !
>    ;
> 
> debug byte$:
> 
> byte$: &test2
>     8  0 13  3 10  2  7
>     9  5 12  4  1  6 10 ;
> 
> .s &test2 lcount dump
> \s
> Is there a better way to define byte$: ?
> Jos

I have DATA[ and ]DATA (though its for cells, not bytes:

DATA[ 1 2 3 4 5 6 7 8 9 10 ]DATA

Results in addr count being pushed to the stack.

[toc] | [prev] | [next] | [standalone]


#36088

FromHowerd <howerdo@yahoo.co.uk>
Date2015-01-28 07:42 -0800
Message-ID<22b252ca-f66c-432d-91ad-c27483b4eee4@googlegroups.com>
In reply to#36085
Hi Jos,

I use this :
\ Add n bytes to the structure, using the n hex ASCII words following, then ignore the rest of the line

\ This allows captured packet data to be copied and pasted...
: nc, ( -- )  base @ >r  hex 
   ( n -- ) 0 do   bl word  count number  c,  loop 
   r> base ! 
   postpone \ 
;  

create MyString 6 nc, 11 22 33 44 55 66 

Not quite the same, but simple...

Best regards,
Howerd

[toc] | [prev] | [next] | [standalone]


#36090

Fromjosv@planet.nl
Date2015-01-28 08:17 -0800
Message-ID<265d45ce-e93d-4ca8-b671-8e808e1fde83@googlegroups.com>
In reply to#36088
28 januari 2015 16:42:57 UTC+1 Howerd wrote:
> Hi Jos,
> 
> I use this :
> \ Add n bytes to the structure, using the n hex ASCII words following, then ignore the rest of the line
> 
> \ This allows captured packet data to be copied and pasted...
> : nc, ( -- )  base @ >r  hex 
>    ( n -- ) 0 do   bl word  count number  c,  loop 
>    r> base ! 
>    postpone \ 
> ;  
> 
> create MyString 6 nc, 11 22 33 44 55 66 
> 
> Not quite the same, but simple...
> 
> Best regards,
> Howerd

Hi Howerd,

Thanks for the code.
For Win32Forth I had to change the code as follows:

: nc, ( -- )  base @ >r  hex
   ( n -- ) 0 do   bl word  number d>s c,  loop
   r> base !
   postpone \
;

Indeed a bit different.
Not multiline and misses the number of allocated bytes.
And I must count the number of bytes for my PC.
Something Forth should do for me.

Jos

[toc] | [prev] | [next] | [standalone]


#36091

From"HAA" <someone@microsoft.com>
Date2015-01-29 03:37 +1100
Message-ID<mab377$vc4$1@speranza.aioe.org>
In reply to#36085
josv@planet.nl wrote:
> \ Resently I needed some code to allot a number of bytes like:
> create &test1
>     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
>     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
>
> \ All those C, looked quite boring and the number of allocated bytes was also missing.
> [...]

    here
    8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
    9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
    here over - 2constant &test1

Simplicity is never boring.


[toc] | [prev] | [next] | [standalone]


#36093

Fromvisualforth@rocketmail.com
Date2015-01-28 12:53 -0800
Message-ID<885f4741-7724-4e52-92e5-def824f9c3c5@googlegroups.com>
In reply to#36085
On Wednesday, January 28, 2015 at 7:07:24 AM UTC-5, jo...@planet.nl wrote:
> \ Resently I needed some code to allot a number of bytes like:
> create &test1
>     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
>     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
> 
> \ All those C, looked quite boring and the number of allocated bytes was also missing.
> \ The following byte$: solved my problem in Win32Forth.
> 
> : byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr-lcount )
>    create  here dup , \ map: #bytes...
>    begin bl nextword
>          if count number?
>             if   d>s true
>             else drop
>            then
>          else false
>          then
>    while c,
>    repeat here over - cell- swap !
>    ;
> 
> debug byte$:
> 
> byte$: &test2
>     8  0 13  3 10  2  7
>     9  5 12  4  1  6 10 ;
> 
> .s &test2 lcount dump
> \s
> Is there a better way to define byte$: ?
> Jos

Thanks, Jos, great idea! I could have used it several times.
Next time I need it I will try it.

I guess this scheme may be used to define a bunch of variables, too?

Dirk.

[toc] | [prev] | [next] | [standalone]


#36094

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-01-28 14:03 -0800
Message-ID<b306a212-c346-4403-85d0-0fba7224f893@googlegroups.com>
In reply to#36085
On Wednesday, January 28, 2015 at 2:07:24 PM UTC+2, jo...@planet.nl wrote:
> \ Resently I needed some code to allot a number of bytes like:
> create &test1
>     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
>     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
> 
> \ All those C, looked quite boring and the number of allocated bytes was also missing.
> \ The following byte$: solved my problem in Win32Forth.
> 
> : byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr-lcount )
>    create  here dup , \ map: #bytes...
>    begin bl nextword
>          if count number?
>             if   d>s true
>             else drop
>            then
>          else false
>          then
>    while c,
>    repeat here over - cell- swap !
>    ;
> 
> debug byte$:
> 
> byte$: &test2
>     8  0 13  3 10  2  7
>     9  5 12  4  1  6 10 ;
> 
> .s &test2 lcount dump
> \s
> Is there a better way to define byte$: ?
> Jos

Hi!

For that kind of work I would use '::' something like (excerpt from command-line):

bash-4.2$ gforth loader.fs
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
  ok
here s" " s" C," PAD 80 ::   
8  0 13  3 10  2  7          
9  5 12  4  1  6 10          
;; here over - 2constant test  ok
test dump                    
B71F9250: 08 00 0D 03  0A 02 07 09 - 05 0C 04 01  06 0A        ..............
 ok
s" crack" s" " PAD 80 :: left right move>| |<move << :: ;; 
: left  
  rot umin ;
: right  
  rot tuck - dup 0 <= 
  IF     + 
  ELSE   rot + swap 
  THEN ;
: move>|  
  over >r right over >r move 2r> over - ;
H( cas us cad ud -- ca u  ;move right, return buffer rest )

: |<move  
  2dup 
  DO     left dup >r move r> 2r> rot /string ;
H( cas us cad ud -- ca u  ;move left,  return buffer rest )

: <<  
  BEGIN  parse-name dup 
         IF     tuck BUFFER<< 80 left move BUFFER<< swap EXIT 
         ELSE   2drop source-id 0= 
                IF     cr 
                THEN 
                refill drop 
         THEN 
  AGAIN ;
H( -- ca u  ; multiline parse-name. )

: ::  
  2dup blank 2dup 
  DO     move>| |<move 1 /string 1- 
         BEGIN  << 2dup s\" ;;" compare 
                IF     2over patch 2r@ evaluate 
                REPEAT 
                2r> 2drop 2drop 2drop ;
H( capre upre capost upost cabuf ubuf 'data0' .. 'dataN' ';;' --  ;For each DATAi from input-stream evaluate buffer 'PRECODE DATAi POSTCODE'.  User *must* ensure that buffer is large enough. )
 ok
bye 
bash-4.2$ 

Read 'H( ... )' as a comment for above definition.
'BUFFER<<' is just a buffer of 80 chars.
In '::' code 'DO' just means '2>R'.

'loader.fs' loads a little modified 'lfw.fs' posted here in clf.

Have a nice day,
humptydumpty

[toc] | [prev] | [next] | [standalone]


#36108

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-01-28 20:39 -0800
Message-ID<bd56ebd3-897e-4a04-8a92-64c69f4583ad@googlegroups.com>
In reply to#36085
On Wednesday, January 28, 2015 at 2:07:24 PM UTC+2, jo...@planet.nl wrote:
> \ Resently I needed some code to allot a number of bytes like:
> create &test1
>     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
>     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
> 
> \ All those C, looked quite boring and the number of allocated bytes was also missing.
> \ The following byte$: solved my problem in Win32Forth.
> 
> : byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr-lcount )
>    create  here dup , \ map: #bytes...
>    begin bl nextword
>          if count number?
>             if   d>s true
>             else drop
>            then
>          else false
>          then
>    while c,
>    repeat here over - cell- swap !
>    ;
> 
> debug byte$:
> 
> byte$: &test2
>     8  0 13  3 10  2  7
>     9  5 12  4  1  6 10 ;
> 
> .s &test2 lcount dump
> \s
> Is there a better way to define byte$: ?
> Jos

Hi!

Maybe I would use '::' from 'lfw.fs' for this kind of work

H( ... ) is a comment for above definition.
'BUFFER<<' is an address to a buffer of 80 chars. 
in '|move' '<<' '::' a 'DO' without 'LOOP' translates to '2>R'.

here s" " s" C," PAD 80 ::   
8  0 13  3 10  2  7           
9  5 12  4  1  6 10           
;; here over - 2constant test  ok
test dump 
B71F4250: 08 00 0D 03  0A 02 07 09 - 05 0C 04 01  06 0A        ..............
 ok
s" crack" s" " PAD 80 :: left right dump move>| |<move << :: ;; 
: left  
  rot umin ;
: right  
  rot tuck - dup 0 <= 
  IF     + 
  ELSE   rot + swap 
  THEN ;
: dump  
  cr useraddr <56>  @ >r hex 0 
  ?DO    i' i - 16 min /dump ! dup 8 u.r .\" : " dup .line cr 16 + 16 
  +LOOP
  drop r> useraddr <56>  ! ;
: move>|  
  over >r right over >r move 2r> over - ;
H( cas us cad ud -- ca u  ;move right, return buffer rest )

: |<move  
  2dup 
  DO     left dup >r move r> 2r> rot /string ;
H( cas us cad ud -- ca u  ;move left,  return buffer rest )

: <<  
  BEGIN  parse-name dup 
         IF     BUFFER<< 80 left 2dup 
                DO     move 2r> EXIT 
                ELSE   2drop source-id 0= 
                       IF     cr 
                       THEN 
                       refill drop 
                THEN 
         AGAIN ;
H( -- ca u  ; multiline parse-name. )

: ::  
  2dup blank 2dup 
  DO     move>| |<move 1 /string 1- 
         BEGIN  << 2dup s\" ;;" compare 
                IF     2over patch 2r@ evaluate 
                REPEAT 
                2r> 2drop 2drop 2drop ;
H( capre upre capost upost cabuf ubuf 'data0' .. 'dataN' ';;' --  ;For each DATAi from input-stream evaluate buffer 'PRECODE DATAi POSTCODE'.  User *must* ensure that buffer is large enough. )
 ok


Have a nice day,
humptydumpty
P.S. I deleted previous post because definition of '<<' was bad. 

[toc] | [prev] | [next] | [standalone]


#36109

Fromhumptydumpty <ouatubi@gmail.com>
Date2015-01-28 20:51 -0800
Message-ID<14c15ed3-1a70-4f1a-8fdc-6b349e74bbb4@googlegroups.com>
In reply to#36108
On Thursday, January 29, 2015 at 6:39:37 AM UTC+2, humptydumpty wrote:
> On Wednesday, January 28, 2015 at 2:07:24 PM UTC+2, jo...@planet.nl wrote:
> > \ Resently I needed some code to allot a number of bytes like:
> > create &test1
> >     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
> >     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
> > 
> > \ All those C, looked quite boring and the number of allocated bytes was also missing.
> > \ The following byte$: solved my problem in Win32Forth.
> > 
> > : byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr-lcount )
> >    create  here dup , \ map: #bytes...
> >    begin bl nextword
> >          if count number?
> >             if   d>s true
> >             else drop
> >            then
> >          else false
> >          then
> >    while c,
> >    repeat here over - cell- swap !
> >    ;
> > 
> > debug byte$:
> > 
> > byte$: &test2
> >     8  0 13  3 10  2  7
> >     9  5 12  4  1  6 10 ;
> > 
> > .s &test2 lcount dump
> > \s
> > Is there a better way to define byte$: ?
> > Jos
> 
> Hi!
> 
> Maybe I would use '::' from 'lfw.fs' for this kind of work
> 
> H( ... ) is a comment for above definition.
> 'BUFFER<<' is an address to a buffer of 80 chars. 
> in '|move' '<<' '::' a 'DO' without 'LOOP' translates to '2>R'.
> 
> here s" " s" C," PAD 80 ::   
> 8  0 13  3 10  2  7           
> 9  5 12  4  1  6 10           
> ;; here over - 2constant test  ok
> test dump 
> B71F4250: 08 00 0D 03  0A 02 07 09 - 05 0C 04 01  06 0A        ..............
>  ok
> s" crack" s" " PAD 80 :: left right dump move>| |<move << :: ;; 
> : left  
>   rot umin ;
> : right  
>   rot tuck - dup 0 <= 
>   IF     + 
>   ELSE   rot + swap 
>   THEN ;
> : dump  
>   cr useraddr <56>  @ >r hex 0 
>   ?DO    i' i - 16 min /dump ! dup 8 u.r .\" : " dup .line cr 16 + 16 
>   +LOOP
>   drop r> useraddr <56>  ! ;
> : move>|  
>   over >r right over >r move 2r> over - ;
> H( cas us cad ud -- ca u  ;move right, return buffer rest )
> 
> : |<move  
>   2dup 
>   DO     left dup >r move r> 2r> rot /string ;
> H( cas us cad ud -- ca u  ;move left,  return buffer rest )
> 
> : <<  
>   BEGIN  parse-name dup 
>          IF     BUFFER<< 80 left 2dup 
>                 DO     move 2r> EXIT 
>                 ELSE   2drop source-id 0= 
>                        IF     cr 
>                        THEN 
>                        refill drop 
>                 THEN 
>          AGAIN ;
> H( -- ca u  ; multiline parse-name. )
> 
> : ::  
>   2dup blank 2dup 
>   DO     move>| |<move 1 /string 1- 
>          BEGIN  << 2dup s\" ;;" compare 
>                 IF     2over patch 2r@ evaluate 
>                 REPEAT 
>                 2r> 2drop 2drop 2drop ;
> H( capre upre capost upost cabuf ubuf 'data0' .. 'dataN' ';;' --  ;For each DATAi from input-stream evaluate buffer 'PRECODE DATAi POSTCODE'.  User *must* ensure that buffer is large enough. )
>  ok
> 
> 
> Have a nice day,
> humptydumpty
> P.S. I deleted previous post because definition of '<<' was bad.

I had a typo: wroted 'dump' instead of 'patch' in previous post.

crack patch                                                    
: patch  
  2dup blank left move ; ok

[toc] | [prev] | [next] | [standalone]


#36113

Fromjosv@planet.nl
Date2015-01-29 06:28 -0800
Message-ID<b72d4727-d6e0-4171-9ade-28b2ac116a89@googlegroups.com>
In reply to#36109
29 january 2015 05:51:09 UTC+1 humptydumpty wrote:
> crack patch                                                    
> : patch  
>   2dup blank left move ; ok

\ Hi Humptydumpty,
\ Nice insight of the possibility's of Gorth.
\ Both you and HAA seem to suggest to return the adress and number
\ of used items in one go.
\ So I changed the code as follows:

: byte$:              \ compiletime: ( ...; - ) runtime: ( - Adr #bytes )
   create  here dup , \ map: #bytes...
   begin bl nextword
         if count number?
            if   d>s true
            else drop
           then
         else false
         then
   while c,
   repeat here over - cell- swap !
   does> lcount
   ;

\ For Dirk:

: int$:               \ compiletime: ( ...; - ) runtime: ( - Adr #ints )
   create  here dup , \ map: #ints...
   begin bl nextword
         if count number?
            if   d>s true
            else drop
           then
         else false
         then
   while ,
   repeat here over - cell- cell /  swap !
   does> lcount
   ;

byte$: &test2
    8  0 13  3 10  2  7
    9  5 12  4  1  6 10 ;

int$: &test3
    8  0 13  3 10  2  7
    9  5 12  4  1  6 10 ;

 &test2       dump cr
 &test3 cells dump cr
\s
Jos

[toc] | [prev] | [next] | [standalone]


#36133

Fromhughaguilar96@gmail.com
Date2015-01-29 21:18 -0800
Message-ID<73ab7b08-43e0-4d72-a35f-18841d84d9aa@googlegroups.com>
In reply to#36085
On Wednesday, January 28, 2015 at 5:07:24 AM UTC-7, jo...@planet.nl wrote:
> \ Resently I needed some code to allot a number of bytes like:
> create &test1
>     8 C,  0 C, 13 C, 3 C, 10 C, 2 C, 7 C,
>     9 C,  5 C, 12 C, 4 C,  1 C, 6 C, 10 C,
> 
> \ All those C, looked quite boring and the number of allocated bytes was also missing.

In the novice package (http://www.forth.org/novice.html) I have these:

: non-zeros ( 0 numbers... -- 0 numbers... count )
    0                                           \ -- count
    0 >r  begin  over while  swap >r  1+ repeat nip
    0 swap  begin  r>  ?dup while  swap  repeat ;
    
: reverse-stack ( 0 numbers... -- 0 numbers... )          
    non-zeros 0 ?do  I roll  loop ;

: dup-stack ( 0 numbers... -- 0 numbers... 0 numbers... ) 
    non-zeros 
    dup 1+  0  do  >r  r@ pick  r>  loop drop ;

: non-zeros, ( 0 numbers... -- )
    reverse-stack  
    begin  ?dup while  ,  repeat ;

These won't work for you, because I am assuming 0 to be the sentinel, and you want it to be a valid number. You want the range [0,255] to be valid, so -1 would be a good sentinel for you. It should be trivial for you to rewrite this to do what you want --- I'll leave it to you, so you can get whatever syntax you want --- I can do it for you though, if you get stuck.

Notice how my functions are short and simple --- your functions you posted were rather lengthy, and they involved nested conditionals --- try to go with short and simple as much as possible! :-)

I don't like to use DEPTH because you have to store it in a global variable --- this can be done though, and it is the only solution if you want every cell to be valid and hence can't have a sentinel that is defined as being invalid.

[toc] | [prev] | [next] | [standalone]


#36147

Fromjosv@planet.nl
Date2015-01-30 05:38 -0800
Message-ID<acd3039d-8f7f-4066-8351-a2bb42186f80@googlegroups.com>
In reply to#36133
On 30 January 2015 06:18:42 UTC+1 hughag...@gmail.com wrote:
[ ... ]
> Notice how my functions are short and simple --- your functions you posted 
> were rather lengthy, and they involved nested conditionals --- try to go 
> with short and simple as much as possible! :-)
> 
> I don't like to use DEPTH because you have to store it in a global variable 
> --- this can be done though, and it is the only solution if you want every 
> cell to be valid and hence can't have a sentinel that is defined as 
> being invalid.

\ Hi Hugh,
\ Your remark to simplify my functions is quite helpful.
\ But I do not like the use of sentinels.
\ Thanks to you the new code is:

: nextnumber? ( - d f )
   bl nextword
      if    count number?
      else  0 0 false
      then ;

sys-warning-off

: byte$:        \ compiletime: ( ...; - ) runtime: ( - Adr #bytes )
   create >mark \ map: #bytes...
      begin  nextnumber?
      while  d>s c,
      repeat
   2drop <mark over - cell- swap !
   does>  lcount ;

: int$:         \ compiletime: ( ...; - ) runtime: ( - Adr #ints )
   create >mark \ map: #ints...
      begin  nextnumber?
      while  d>s ,
      repeat
   2drop <mark over - cell- cell / swap !
   does>  lcount ;

sys-warning-on

byte$: &test2
    8  0 13  3 10  2  7
    9  5 12  4  1  6 10 ;

int$: &test3
    8  0 13  3 10  2  7
    9  5 12  4  1  6 10 ;

 &test2       dump cr
 &test3 cells dump cr
\s
Jos

[toc] | [prev] | [next] | [standalone]


#36150

From"Alex McDonald" <blog@rivadpm.com>
Date2015-01-30 15:11 +0000
Message-ID<mag6t5$bcr$1@dont-email.me>
In reply to#36147
on 30/01/2015 13:38:21,  wrote:
> On 30 January 2015 06:18:42 UTC+1 hughag...@gmail.com wrote:
> [ ... ]
>> Notice how my functions are short and simple --- your functions you posted
>> were rather lengthy, and they involved nested conditionals --- try to go
>> with short and simple as much as possible! :-)
>>
>> I don't like to use DEPTH because you have to store it in a global variable
>> --- this can be done though, and it is the only solution if you want every
>> cell to be valid and hence can't have a sentinel that is defined as
>> being invalid.
> 
> \ Hi Hugh,
> \ Your remark to simplify my functions is quite helpful.
> \ But I do not like the use of sentinels.
> \ Thanks to you the new code is:
> 
>: nextnumber? ( - d f )
> bl nextword

I thought nextword had the signature ( -- addr len ) ?? Like this;

: nextword     ( -- addr len )  \ get next word in input stream
    begin parse-name dup 0=
    while 
      drop refill dup 0= if exit then
      2drop
    repeat ;

NEXTWORD just looks like an alias for WORD otherwise.

> if    count number?

There's no COUNT possible if the signature is ( -- addr len ) from
NEXTWORD, and if it's ( -- cstring ) like WORD then surely there's a DUP
missing before the IF?

> else  0 0 false

Hmm, that looks wrong.

> then ;
> 
> sys-warning-off
> 
>: byte$:        \ compiletime: ( ...; - ) runtime: ( - Adr #bytes )
> create >mark \ map: #bytes...
> begin  nextnumber?
> while  d>s c,
> repeat
> 2drop <mark over - cell- swap !
> does>  lcount ;
> 
>: int$:         \ compiletime: ( ...; - ) runtime: ( - Adr #ints )
> create >mark \ map: #ints...
> begin  nextnumber?
> while  d>s ,
> repeat
> 2drop <mark over - cell- cell / swap !
> does>  lcount ;
> 
> sys-warning-on
> 
> byte$: &test2
> 8  0 13  3 10  2  7
> 9  5 12  4  1  6 10 ;
> 
> int$: &test3
> 8  0 13  3 10  2  7
> 9  5 12  4  1  6 10 ;
> 
> &test2       dump cr
> &test3 cells dump cr
> \s
> Jos
> 

[toc] | [prev] | [next] | [standalone]


#36160

Fromjosv@planet.nl
Date2015-01-30 08:34 -0800
Message-ID<ec36f608-cbb2-4406-811e-ab842fcaa7df@googlegroups.com>
In reply to#36150
On 30 januari 2015 16:11:03 UTC+1 Alex McDonald wrote:
>> [ ... ]

Hi Alex,
Thank you for analyzing my code.

> I thought nextword had the signature ( -- addr len ) ??
No, in Win32Forth it is:  ( char -- adr flag )

> else  0 0 false
Indeed that is where you are right.
The new code for nextnumber? is:

: nextnumber? ( - d f )
   bl nextword
      if    count number?
      else   0 false
      then ;
Jos

[toc] | [prev] | [next] | [standalone]


#36189

Fromhughaguilar96@gmail.com
Date2015-01-31 20:26 -0800
Message-ID<ba5dce78-ce8c-40c2-8d29-ca8008d6ec7f@googlegroups.com>
In reply to#36147
On Friday, January 30, 2015 at 6:38:20 AM UTC-7, jo...@planet.nl wrote:
> On 30 January 2015 06:18:42 UTC+1 hughag...@gmail.com wrote:
> [ ... ]
> > Notice how my functions are short and simple --- your functions you posted 
> > were rather lengthy, and they involved nested conditionals --- try to go 
> > with short and simple as much as possible! :-)
> > 
> > I don't like to use DEPTH because you have to store it in a global variable 
> > --- this can be done though, and it is the only solution if you want every 
> > cell to be valid and hence can't have a sentinel that is defined as 
> > being invalid.
> 
> \ Hi Hugh,
> \ Your remark to simplify my functions is quite helpful.
> \ But I do not like the use of sentinels.
> \ Thanks to you the new code is:
> 
> : nextnumber? ( - d f )
>    bl nextword
>       if    count number?
>       else  0 0 false
>       then ;
> 
> sys-warning-off
> 
> : byte$:        \ compiletime: ( ...; - ) runtime: ( - Adr #bytes )
>    create >mark \ map: #bytes...
>       begin  nextnumber?
>       while  d>s c,
>       repeat
>    2drop <mark over - cell- swap !
>    does>  lcount ;
> 
> : int$:         \ compiletime: ( ...; - ) runtime: ( - Adr #ints )
>    create >mark \ map: #ints...
>       begin  nextnumber?
>       while  d>s ,
>       repeat
>    2drop <mark over - cell- cell / swap !
>    does>  lcount ;
> 
> sys-warning-on
> 
> byte$: &test2
>     8  0 13  3 10  2  7
>     9  5 12  4  1  6 10 ;
> 
> int$: &test3
>     8  0 13  3 10  2  7
>     9  5 12  4  1  6 10 ;
> 
>  &test2       dump cr
>  &test3 cells dump cr
> \s
> Jos

I skimmed over your code, so I have an idea of what you are doing, but haven't really analyzed it. You are using code I don't recognize, such as NEXTWORD and NUMBER?, so that is a stumbling block to me. I can make some comments though.

I don't like the idea of parsing a string out of the input stream and figuring out that it is a number with NUMBER? as you are doing in your NEXTNUMBER? word. This goes against Forth philosophy, which is to use the Forth outer-interpreter rather than write an interpreter of your own. Writing your own interpreter with NUMBER? means that you can only have raw numbers. You can't have arithmetic expressions, you can't have constants, etc. --- all of which would be handled just fine by the Forth outer-interpreter. The Forth outer-interpreter is very powerful compared to anything that you can write yourself --- put it to use!

If you don't want to use a sentinel, you can still use the outer-interpreter as I suggest. Have a word DATA[ that stores the value of DEPTH in a global variable. Execute this before your data. After your data, execute a word ]DATA that first calculates how many data there are (current DEPTH minus the stored original DEPTH value). The ]DATA word can reverse the order of the data on the parameter stack (similar to my REVERSE-STACK) and can then comma the data into the dictionary.

In regard to style, it is not necessary to put every part of every control-structure on a different line --- this isn't Python! --- I generally don't have multi-line functions, because I put a lot of code on each line (my rule is that each line should do one conceptual activity). This is your code:

> : nextnumber? ( - d f )
>    bl nextword
>       if    count number?
>       else  0 0 false
>       then ;

This is how I would format the same thing:

: nextnumber? ( -- d flag )
    bl nextword if  count number?  else  0. false  then ;

Keep at it --- it takes a while to get the hang of Forth...

[toc] | [prev] | [next] | [standalone]


#36207

Fromjosv@planet.nl
Date2015-02-01 11:16 -0800
Message-ID<df59384b-b316-442e-b01c-4af69779b874@googlegroups.com>
In reply to#36189
On sunday 1 february 2015 05:26:15 UTC+1 hughag...@gmail.com wrote:

Thank you for looking at my code.

From the point of flexibility you are certainly right.
But I do not need that much. I just would like to store a few 
raw numbers and attach a name to it, with the least possible overhead in the form of repeated code and nothing more.
Even typing data[ ]data is considered too much.

Jos.

> I skimmed over your code, so I have an idea of what you are doing, but haven't really analyzed it. You are using code I don't recognize, such as NEXTWORD and NUMBER?, so that is a stumbling block to me. I can make some comments though.
> 
> I don't like the idea of parsing a string out of the input stream and figuring out that it is a number with NUMBER? as you are doing in your NEXTNUMBER? word. This goes against Forth philosophy, which is to use the Forth outer-interpreter rather than write an interpreter of your own. Writing your own interpreter with NUMBER? means that you can only have raw numbers. You can't have arithmetic expressions, you can't have constants, etc. --- all of which would be handled just fine by the Forth outer-interpreter. The Forth outer-interpreter is very powerful compared to anything that you can write yourself --- put it to use!
> 
> If you don't want to use a sentinel, you can still use the outer-interpreter as I suggest. Have a word DATA[ that stores the value of DEPTH in a global variable. Execute this before your data. After your data, execute a word ]DATA that first calculates how many data there are (current DEPTH minus the stored original DEPTH value). The ]DATA word can reverse the order of the data on the parameter stack (similar to my REVERSE-STACK) and can then comma the data into the dictionary.
> 
> In regard to style, it is not necessary to put every part of every control-structure on a different line --- this isn't Python! --- I generally don't have multi-line functions, because I put a lot of code on each line (my rule is that each line should do one conceptual activity). This is your code:
> 
> > : nextnumber? ( - d f )
> >    bl nextword
> >       if    count number?
> >       else  0 0 false
> >       then ;
> 
> This is how I would format the same thing:
> 
> : nextnumber? ( -- d flag )
>     bl nextword if  count number?  else  0. false  then ;
> 
> Keep at it --- it takes a while to get the hang of Forth...

[toc] | [prev] | [next] | [standalone]


#36209

From"HAA" <someone@microsoft.com>
Date2015-02-02 11:03 +1100
Message-ID<mameqt$pal$1@speranza.aioe.org>
In reply to#36207
josv@planet.nl wrote:
> On sunday 1 february 2015 05:26:15 UTC+1 hughag...@gmail.com wrote:
>
> Thank you for looking at my code.
>
> From the point of flexibility you are certainly right.
> But I do not need that much. I just would like to store a few
> raw numbers and attach a name to it, with the least possible overhead in the form of
> repeated code and nothing more.
> Even typing data[ ]data is considered too much.
>
> Jos.

Storing a few raw numbers is most easily achieved by typing C,



[toc] | [prev] | [next] | [standalone]


#36210

From"Elizabeth D. Rather" <erather@forth.com>
Date2015-02-01 14:13 -1000
Message-ID<5pGdnRQigfSwXFPJnZ2dnUU7-XednZ2d@supernews.com>
In reply to#36209
On 2/1/15 2:03 PM, HAA wrote:
> josv@planet.nl wrote:
>> On sunday 1 february 2015 05:26:15 UTC+1 hughag...@gmail.com wrote:
>>
>> Thank you for looking at my code.
>>
>>  From the point of flexibility you are certainly right.
>> But I do not need that much. I just would like to store a few
>> raw numbers and attach a name to it, with the least possible overhead in the form of
>> repeated code and nothing more.
>> Even typing data[ ]data is considered too much.
>>
>> Jos.
>
> Storing a few raw numbers is most easily achieved by typing C,

Yes, the OP noted that, but thought it was "boring" and was looking for 
syntactic sugar. IMO none of the offered solutions contribute much 
except more code.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

[toc] | [prev] | [next] | [standalone]


#36212

Fromhughaguilar96@gmail.com
Date2015-02-01 17:22 -0800
Message-ID<62e1bb40-26cb-4476-9199-77624a0f3b78@googlegroups.com>
In reply to#36210
On Sunday, February 1, 2015 at 5:13:34 PM UTC-7, Elizabeth D. Rather wrote:
> On 2/1/15 2:03 PM, HAA wrote:
> > Storing a few raw numbers is most easily achieved by typing C,
> 
> Yes, the OP noted that, but thought it was "boring" and was looking for 
> syntactic sugar. IMO none of the offered solutions contribute much 
> except more code.

You have never posted any code on comp.lang.forth except for example code copied directly out of "Starting Forth" (and you get that wrong most of the time, because you try to do it from memory) --- the reason why you are opposed to "more code" is because you can't write it.

This is actually a trivial problem. I was going to let the OP solve it himself as an exercise, but since he hasn't and you have spoken out against the writing of code, I have decided to go ahead with it. This took about 5 minutes:


variable original-depth

: string[ ( -- )              
    depth original-depth ! ;

: numbers-count ( -- count )  
    depth original-depth @ - ;
        
: reverse-numbers ( numbers... count -- numbers... )    
    numbers-count 0 ?do  I roll  loop ;
    
: good-char? ( n -- flag )    
    256 u< ;
    
: ]string ( numbers... -- )   
    reverse-numbers
    numbers-count  dup c,
    0 ?do  
        dup good-char? 0= abort" *** ]STRING given a bad char ***
        c,  loop ;


The following is a test of the code under VFX:

1 2 3  ok-3 
.s 
DATA STACK
     top
              3 0000:0003
              2 0000:0002
              1 0000:0001
 ok-3 
create hey  ok-3 
string[ char H char E char Y char ! ]string  ok-3 
hey count type HEY! ok-3 
.s 
DATA STACK
     top
              3 0000:0003
              2 0000:0002
              1 0000:0001
 ok-3 

[toc] | [prev] | [next] | [standalone]


#36213

Fromhughaguilar96@gmail.com
Date2015-02-01 17:36 -0800
Message-ID<8f3a931d-9697-411b-8e8e-4d6d8f08005a@googlegroups.com>
In reply to#36210
On Sunday, February 1, 2015 at 5:13:34 PM UTC-7, Elizabeth D. Rather wrote:
> On 2/1/15 2:03 PM, HAA wrote:
> > Storing a few raw numbers is most easily achieved by typing C,
> 
> Yes, the OP noted that, but thought it was "boring" and was looking for 
> syntactic sugar. IMO none of the offered solutions contribute much 
> except more code.

You have never posted any code on comp.lang.forth except for code examples copied directly out of "Starting Forth" (and you get those wrong most of the time, because you try to do it from memory) --- the reason why you are opposed to "more code" is because you can't write it.

This is a trivial coding challenge --- I was going to let the OP do it himself, but since you have spoken out against the writing of Forth code, I will write it myself:

variable original-depth

: string[ ( -- )       
    depth original-depth ! ;

: numbers-count ( -- count ) 
    depth original-depth @ - ;
        
: reverse-numbers ( numbers... count -- numbers... ) 
    0 ?do  I roll  loop ;
    
: good-char? ( n -- flag )    
    256 u< ;
    
: ]string ( numbers... -- )     
    numbers-count >r
    r@ reverse-numbers  
    r@ c,
    r> 0 ?do
        dup good-char? 0= abort" *** ]STRING given a bad char ***
        c,  loop ;

        
This is a test of the code under VFX:

create hey  ok
string[ char H char E char Y char ! ]string  ok
hey count type HEY! ok

[toc] | [prev] | [next] | [standalone]


Page 1 of 4  [1] 2 3 4  Next page →

Back to top | Article view | comp.lang.forth


csiph-web