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


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

lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar?

Started bythe_gavino_himself <visphatesjava@gmail.com>
First post2015-01-22 19:34 -0800
Last post2015-02-11 09:19 +0000
Articles 20 on this page of 40 — 19 participants

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


Contents

  lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? the_gavino_himself <visphatesjava@gmail.com> - 2015-01-22 19:34 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? foxaudioresearch@gmail.com - 2015-01-22 20:08 -0800
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Mark Wills <markwills1970@gmail.com> - 2015-01-23 02:00 -0800
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-01-23 14:07 +0100
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "WJ" <w_a_x_man@yahoo.com> - 2015-01-24 01:43 +0000
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? beeflo <beeflobill@gmail.com> - 2015-01-29 08:22 -0800
          Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Elizabeth D. Rather" <erather@forth.com> - 2015-01-29 11:35 -1000
            Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-30 16:20 +0000
              Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Bernd Paysan <bernd.paysan@gmx.de> - 2015-01-30 21:48 +0100
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? the_gavino_himself <visphatesjava@gmail.com> - 2015-01-23 13:09 -0800
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? empty-buffers <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com> - 2015-01-29 00:38 +0000
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-01-29 02:49 +0100
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Elizabeth D. Rather" <erather@forth.com> - 2015-01-28 16:34 -1000
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? the_gavino_himself <visphatesjava@gmail.com> - 2015-01-29 16:04 -0800
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2015-01-30 08:46 +0000
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? skydda.barnen@gmail.com - 2015-01-30 02:39 -0800
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Alex McDonald" <blog@rivadpm.com> - 2015-01-30 11:32 +0000
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-01-30 04:08 -0800
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-01-30 08:38 -0800
          Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-01-30 22:01 +0100
            Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-01-30 22:16 -0800
              Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-02-01 00:23 +0100
                Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 00:35 -0800
                  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Coos Haak <chforth@hccnet.nl> - 2015-02-01 14:20 +0100
                    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 07:42 -0800
                  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-01 17:24 +0000
                    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 09:58 -0800
                      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-02-02 00:46 +0000
                  Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? "Elizabeth D. Rather" <erather@forth.com> - 2015-02-01 08:59 -1000
                    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 12:06 -0800
                    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? hughaguilar96@gmail.com - 2015-02-08 18:43 -0800
                      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? Ron Aaron <rambamist@gmail.com> - 2015-02-09 08:36 +0200
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-01-30 16:27 +0000
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 01:24 -0800
          Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-02-01 16:13 +0000
            Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? lehs <skydda.barnen@gmail.com> - 2015-02-01 10:54 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar? hughaguilar96@gmail.com - 2015-02-08 18:07 -0800
    Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar? "WJ" <w_a_x_man@yahoo.com> - 2015-02-09 08:55 +0000
      Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar? Doug Hoffman <glidedog@gmail.com> - 2015-02-09 08:00 -0500
        Re: lisp can sum a list of numbers with 2 parens and a +, can forth useloop to make something similar? Unknown <dog@gmail.com> - 2015-02-11 09:19 +0000

Page 1 of 2  [1] 2  Next page →


#35964 — lisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar?

Fromthe_gavino_himself <visphatesjava@gmail.com>
Date2015-01-22 19:34 -0800
Subjectlisp can sum a list of numbers with 2 parens and a +, can forth use loop to make something similar?
Message-ID<6c04408e-ec35-4a54-b066-e25ee55f4f07@googlegroups.com>
can forth do something similar with loop and the return stack?

(+ 3 4 5 6 7 8)

seems nicer than

3 4 5 6 7 8 + + + + + .

it seems loop and the stack could be made to do something like lisp does 

[toc] | [next] | [standalone]


#35966

Fromfoxaudioresearch@gmail.com
Date2015-01-22 20:08 -0800
Message-ID<8e65f095-cefd-4610-bac8-71546cfbca1b@googlegroups.com>
In reply to#35964
On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
> can forth do something similar with loop and the return stack?
> 
> (+ 3 4 5 6 7 8)
> 
> seems nicer than
> 
> 3 4 5 6 7 8 + + + + + .
> 
> it seems loop and the stack could be made to do something like lisp does

Forth is a meta language.  This not really equivalent to LISP, but is how one might do it with Forth if something similar looking was prerequisite.

: (   ; \ sugar for the example, could be used to store the stack position.

: +)    depth 1 ?do + loop ;  


( 3 4 5 6 7 8 +) .s                                                              
33 <-Top  ok


Time to try one yourself 

BF


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


#35968

FromMark Wills <markwills1970@gmail.com>
Date2015-01-23 02:00 -0800
Message-ID<74eb8b57-b72f-4f19-a7c3-9d3c7da55cf9@googlegroups.com>
In reply to#35966
On Friday, 23 January 2015 04:08:36 UTC, foxaudio...@gmail.com  wrote:
> On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
> > can forth do something similar with loop and the return stack?
> > 
> > (+ 3 4 5 6 7 8)
> > 
> > seems nicer than
> > 
> > 3 4 5 6 7 8 + + + + + .
> > 
> > it seems loop and the stack could be made to do something like lisp does
> 
> Forth is a meta language.  This not really equivalent to LISP, but is how one might do it with Forth if something similar looking was prerequisite.
> 
> : (   ; \ sugar for the example, could be used to store the stack position.
> 
> : +)    depth 1 ?do + loop ;  
> 
> 
> ( 3 4 5 6 7 8 +) .s                                                              
> 33 <-Top  ok
> 
> 
> Time to try one yourself 
> 
> BF

Nice example, BF. Hat's off!

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


#35970

FromCoos Haak <chforth@hccnet.nl>
Date2015-01-23 14:07 +0100
Message-ID<1a5abav67afzt.1f2xjs78eejaj.dlg@40tude.net>
In reply to#35966
Op Thu, 22 Jan 2015 20:08:35 -0800 (PST) schreef
foxaudioresearch@gmail.com:

> On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
>> can forth do something similar with loop and the return stack?
>> 
>> (+ 3 4 5 6 7 8)
>> 
>> seems nicer than
>> 
>> 3 4 5 6 7 8 + + + + + .
>> 
>> it seems loop and the stack could be made to do something like lisp does
> 
> Forth is a meta language.  This not really equivalent to LISP, but is how one might do it with Forth if something similar looking was prerequisite.
> 
>: (   ; \ sugar for the example, could be used to store the stack position.
> 
>: +)    depth 1 ?do + loop ;  
> 
> 
> ( 3 4 5 6 7 8 +) .s                                                              
> 33 <-Top  ok
> 
> 
> Time to try one yourself 
> 
> BF

This allows nesting in Gforth:
: (
        depth 1+ r> 2>r
    ;

: cond
        depth j >
    ;

: done
        2r> rdrop 2>r
    ;

: +)
        begin   cond
        while   +
        repeat
        done
    ;

: *)
        begin   cond
        while   *
        repeat
        done
    ;

( 1 2 3 4 5 6 7 8 9 10 +) .
( 1 2 3 4 5 6 7 8 9 10 *) .
( ( 6 ( 3 3 +) *) ( ( 4 4 +) 8 *) +) .
-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

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


#35984

From"WJ" <w_a_x_man@yahoo.com>
Date2015-01-24 01:43 +0000
Message-ID<m9utc9$atl$1@dont-email.me>
In reply to#35970
Coos Haak wrote:

> Op Thu, 22 Jan 2015 20:08:35 -0800 (PST) schreef
> foxaudioresearch@gmail.com:
> 
> > On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
> >> can forth do something similar with loop and the return stack?
> >> 
> >> (+ 3 4 5 6 7 8)
> >> 
> >> seems nicer than
> >> 
> >> 3 4 5 6 7 8 + + + + + .
> >> 
> >> it seems loop and the stack could be made to do something like lisp does
> > 
> > Forth is a meta language.  This not really equivalent to LISP, but is how one might do it with Forth if something similar looking was prerequisite.
> > 
> > : (   ; \ sugar for the example, could be used to store the stack position.
> > 
> > : +)    depth 1 ?do + loop ;  
> > 
> > 
> > ( 3 4 5 6 7 8 +) .s                                                              
> > 33 <-Top  ok
> > 
> > 
> > Time to try one yourself 
> > 
> > BF
> 
> This allows nesting in Gforth:
> : (
>         depth 1+ r> 2>r
>     ;
> 
> : cond
>         depth j >
>     ;
> 
> : done
>         2r> rdrop 2>r
>     ;
> 
> : +)
>         begin   cond
>         while   +
>         repeat
>         done
>     ;
> 
> : *)
>         begin   cond
>         while   *
>         repeat
>         done
>     ;
> 
> ( 1 2 3 4 5 6 7 8 9 10 +) .
> ( 1 2 3 4 5 6 7 8 9 10 *) .
> ( ( 6 ( 3 3 +) *) ( ( 4 4 +) 8 *) +) .

But in Scheme and Lisp, + can be used to add up a list
of numbers that already exists:

Gauche Scheme:

(use srfi-27)
(define random-numbers (map (^_ (random-integer 1000)) (iota 999000)))
(apply + random-numbers)
 ===>
499025204

(length random-numbers)
 ===>
999000


Another way:

(fold + 0 random-numbers)
 ===>
499025204

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


#36118

Frombeeflo <beeflobill@gmail.com>
Date2015-01-29 08:22 -0800
Message-ID<eed1799e-07c2-4808-83d7-bf40f8219e52@googlegroups.com>
In reply to#35970
On Friday, January 23, 2015 at 6:24:02 AM UTC-7, Coos Haak wrote:
> Op Thu, 22 Jan 2015 20:08:35 -0800 (PST) schreef
> 
> > On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
> >> can forth do something similar with loop and the return stack?
> >> 
> >> (+ 3 4 5 6 7 8)
> >> 
> >> seems nicer than
> >> 
> >> 3 4 5 6 7 8 + + + + + .
> >> 
> >> it seems loop and the stack could be made to do something like lisp does
> > 
> > Forth is a meta language.  This not really equivalent to LISP, but is how one might do it with Forth if something similar looking was prerequisite.
> > 
> >: (   ; \ sugar for the example, could be used to store the stack position.
> > 
> >: +)    depth 1 ?do + loop ;  
> > 
> > 
> > ( 3 4 5 6 7 8 +) .s                                                              
> > 33 <-Top  ok
> > 
> > 
> > Time to try one yourself 
> > 
> > BF
> 
> This allows nesting in Gforth:
> : (
>         depth 1+ r> 2>r
>     ;
> 
> : cond
>         depth j >
>     ;
> 
> : done
>         2r> rdrop 2>r
>     ;
> 
> : +)
>         begin   cond
>         while   +
>         repeat
>         done
>     ;
> 
> : *)
>         begin   cond
>         while   *
>         repeat
>         done
>     ;
> 
> ( 1 2 3 4 5 6 7 8 9 10 +) .
> ( 1 2 3 4 5 6 7 8 9 10 *) .
> ( ( 6 ( 3 3 +) *) ( ( 4 4 +) 8 *) +) .
> -- 
> Coos
> 
> CHForth, 16 bit DOS applications
> http://home.hccnet.nl/j.j.haak/forth.html

I hope you don't mind, but I asked a question about this code on stackoverflow.com.

The link is: http://stackoverflow.com/questions/28219321/how-do-2r-and-2r-work

I asked it there because I think the question is a good fit for stack overflow.

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


#36125

From"Elizabeth D. Rather" <erather@forth.com>
Date2015-01-29 11:35 -1000
Message-ID<vPmdnZIJB8Y6OlfJnZ2dnUU7-L-dnZ2d@supernews.com>
In reply to#36118
On 1/29/15 6:22 AM, beeflo wrote:
...
>
> I hope you don't mind, but I asked a question about this code on stackoverflow.com.
>
> The link is: http://stackoverflow.com/questions/28219321/how-do-2r-and-2r-work
>
> I asked it there because I think the question is a good fit for stack overflow.

You asked what 2>R and 2R> do. I see there's an answer, but to handle it 
briefly here, 2>R pops 2 items off the data stack and pushes them onto 
the Return Stack, and 2R> pops them off the Return Stack and pushes them 
on to the data stack.

The post quote gforth docs as saying:

2>r       d – R:d        core-ext       “two-to-r”
2r>       R:d – d        core-ext       “two-r-from”

I would criticize this stack description because when you use 'd' you 
imply that the two cells are part of a double integer, whereas they are 
really just two possibly unrelated cells. I think that description is 
part of what's confusing beeflo, and I would encourage the gforth 
maintainers to fix the description.

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]


#36158

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-01-30 16:20 +0000
Message-ID<2015Jan30.172022@mips.complang.tuwien.ac.at>
In reply to#36125
"Elizabeth D. Rather" <erather@forth.com> writes:
>The post quote gforth docs as saying:
>
>2>r       d – R:d        core-ext       “two-to-r”
>2r>       R:d – d        core-ext       “two-r-from”
>
>I would criticize this stack description because when you use 'd' you 
>imply that the two cells are part of a double integer, whereas they are 
>really just two possibly unrelated cells. I think that description is 
>part of what's confusing beeflo, and I would encourage the gforth 
>maintainers to fix the description.

Interestingly, I had earlier defined

2>r    ( w1 w2 -- R:w1 R:w2 )  core-ext        two_to_r
2r>    ( R:w1 R:w2 -- w1 w2 )  core-ext        two_r_from

and Bernd changed this in 2003 to 

2>r	( d -- R:d )	core-ext	two_to_r
2r>	( R:d -- d )	core-ext	two_r_from

with the puzzling comment

|Fixed reverse ordering

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2014: http://www.euroforth.org/ef14/

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


#36172

FromBernd Paysan <bernd.paysan@gmx.de>
Date2015-01-30 21:48 +0100
Message-ID<magqlc$448$1@dont-email.me>
In reply to#36158
Anton Ertl wrote:

> "Elizabeth D. Rather" <erather@forth.com> writes:
>>The post quote gforth docs as saying:
>>
>>2>r       d � R:d        core-ext       �two-to-r�
>>2r>       R:d � d        core-ext       �two-r-from�
>>
>>I would criticize this stack description because when you use 'd' you
>>imply that the two cells are part of a double integer, whereas they are
>>really just two possibly unrelated cells. I think that description is
>>part of what's confusing beeflo, and I would encourage the gforth
>>maintainers to fix the description.
> 
> Interestingly, I had earlier defined
> 
> 2>r    ( w1 w2 -- R:w1 R:w2 )  core-ext        two_to_r
> 2r>    ( R:w1 R:w2 -- w1 w2 )  core-ext        two_r_from
> 
> and Bernd changed this in 2003 to
> 
> 2>r	( d -- R:d )	core-ext	two_to_r
> 2r>	( R:d -- d )	core-ext	two_r_from
> 
> with the puzzling comment
> 
> |Fixed reverse ordering

Not sure, but the context of that complete patchset was mostly C foreign 
funciton interface, and maybe that reverse ordering referred to the C 
foreign function interface.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/
net2o ID: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ*

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


#35980

Fromthe_gavino_himself <visphatesjava@gmail.com>
Date2015-01-23 13:09 -0800
Message-ID<e9b2c5e7-2fb8-4987-91cb-657a8907dcb1@googlegroups.com>
In reply to#35966
On Thursday, January 22, 2015 at 11:08:36 PM UTC-5, foxaudio...@gmail.com wrote:
> On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
> > can forth do something similar with loop and the return stack?
> > 
> > (+ 3 4 5 6 7 8)
> > 
> > seems nicer than
> > 
> > 3 4 5 6 7 8 + + + + + .
> > 
> > it seems loop and the stack could be made to do something like lisp does
> 
> Forth is a meta language.  This not really equivalent to LISP, but is how one might do it with Forth if something similar looking was prerequisite.
> 
> : (   ; \ sugar for the example, could be used to store the stack position.
> 
> : +)    depth 1 ?do + loop ;  
> 
> 
> ( 3 4 5 6 7 8 +) .s                                                              
> 33 <-Top  ok
> 
> 
> Time to try one yourself 
> 
> BF

So one I know more forth this will seem trivial?

Its the variable number of inputs that kinda caught me.


Could this be even simpler like bunch of numbers, some word, ---> produces total?

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


#36098

Fromempty-buffers <empty.buffersYOU-DONT-WANT-THIS@gmail.NEITHER-THIS.com>
Date2015-01-29 00:38 +0000
Message-ID<slrnmcj081.d1n.empty.buffersYOU-DONT-WANT-THIS@Ferrycy.localdomain>
In reply to#35966
In comp.lang.forth, foxaudioresearch@gmail.com wrote:

> Forth is a meta language.  This not really equivalent to LISP, but is how
> one might do it with Forth if something similar looking was prerequisite.
>
>: (   ; \ sugar for the example, could be used to store the stack position.
>
>: +)    depth 1 ?do + loop ;
>
>
> ( 3 4 5 6 7 8 +) .s
> 33 <-Top  ok

But I've got a feeling, I see possible problem here: the numbers from the
row have to be put onto stack first. What if the stack is "shallow" - and the
row is long? Using C, and , is a bit cumbersome - but on the other hand: it
frees the stack immediately on the rule: "number-gone-number-gone-...".

I wonder is it possible to implement something like the above "stack-safe"
way? Yes, actually normally there's no fear - but I read somewhere, that for
example Chuck Moore quite often used in his work stacks say 16 cells deep
(or even smaller).
-- 
"Yes, this is the bad end you've come to, and two and two is - as it always
was..." - began Trurl, but just then the machine made a faint, barely audible
croaking noise and said, for the last time: "SEVEN".

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


#36103

FromCoos Haak <chforth@hccnet.nl>
Date2015-01-29 02:49 +0100
Message-ID<5cu6pdyox6l8$.10vzr4awl0x12.dlg@40tude.net>
In reply to#36098
Op Thu, 29 Jan 2015 00:38:21 +0000 (UTC) schreef empty-buffers:

> In comp.lang.forth, foxaudioresearch@gmail.com wrote:
> 
>> Forth is a meta language.  This not really equivalent to LISP, but is how
>> one might do it with Forth if something similar looking was prerequisite.
>>
>>: (   ; \ sugar for the example, could be used to store the stack position.
>>
>>: +)    depth 1 ?do + loop ;
>>
>>
>> ( 3 4 5 6 7 8 +) .s
>> 33 <-Top  ok
> 
> But I've got a feeling, I see possible problem here: the numbers from the
> row have to be put onto stack first. What if the stack is "shallow" - and the
> row is long? Using C, and , is a bit cumbersome - but on the other hand: it
> frees the stack immediately on the rule: "number-gone-number-gone-...".
> 
> I wonder is it possible to implement something like the above "stack-safe"
> way? Yes, actually normally there's no fear - but I read somewhere, that for
> example Chuck Moore quite often used in his work stacks say 16 cells deep
> (or even smaller).

I would not worry, big systems like Gforth have around 16 K stacks so there
is no problem. Even my 16 bit DOS based Forth can have more than 1 K cells
deep stacks. Catch/throw and nested including use lots of stack space.

It could be a problem with embedded CPUs if one would stash bytes this way
as an alternative for assembly code. In that case, use a decent cross Forth
compiler that should have a built-in (Forth) assembler. 
-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

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


#36105

From"Elizabeth D. Rather" <erather@forth.com>
Date2015-01-28 16:34 -1000
Message-ID<BJGdndE3uJPdAVTJnZ2dnUU7-K2dnZ2d@supernews.com>
In reply to#36098
On 1/28/15 2:38 PM, empty-buffers wrote:
> In comp.lang.forth, foxaudioresearch@gmail.com wrote:
>
>> Forth is a meta language.  This not really equivalent to LISP, but is how
>> one might do it with Forth if something similar looking was prerequisite.
>>
>> : (   ; \ sugar for the example, could be used to store the stack position.
>>
>> : +)    depth 1 ?do + loop ;
>>
>>
>> ( 3 4 5 6 7 8 +) .s
>> 33 <-Top  ok
>
> But I've got a feeling, I see possible problem here: the numbers from the
> row have to be put onto stack first. What if the stack is "shallow" - and the
> row is long? Using C, and , is a bit cumbersome - but on the other hand: it
> frees the stack immediately on the rule: "number-gone-number-gone-...".
>
> I wonder is it possible to implement something like the above "stack-safe"
> way? Yes, actually normally there's no fear - but I read somewhere, that for
> example Chuck Moore quite often used in his work stacks say 16 cells deep
> (or even smaller).
>

This is an example of the need to consider possible use in your design. 
You should know, when writing such a word, what kind of platforms it's 
going to be used on and what size (in general) strings you're going to 
use it on.

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]


#36129

Fromthe_gavino_himself <visphatesjava@gmail.com>
Date2015-01-29 16:04 -0800
Message-ID<0e5a55bf-576b-47d4-86c7-50d53bf66ad8@googlegroups.com>
In reply to#35964
On Thursday, January 22, 2015 at 10:34:36 PM UTC-5, the_gavino_himself wrote:
> can forth do something similar with loop and the return stack?
> 
> (+ 3 4 5 6 7 8)
> 
> seems nicer than
> 
> 3 4 5 6 7 8 + + + + + .
> 
> it seems loop and the stack could be made to do something like lisp does

So in the simplest sense using gforth:

: +m depth 1 ?do + loop  .  ; 
ok
4 55 67 +m 126  ok


Wow forth kicks ass.

How does forth handle complexity once things grow?
I remember reading Charles Moore saying complexity can be moved into data.
Lispers say most complex c programs require a half assed lisp to be implemented inside the program.
Also, I read Jeff Fox (rip) saying that networked forth with forth-linda allowed easy multi node clusters to attack problems.
Does forth get used that way still?
His essay said something like a remote execution was as easy as loop or something.
Ultratechnology is an inspiring site.

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


#36140

FromPaul E Bennett <Paul_E.Bennett@topmail.co.uk>
Date2015-01-30 08:46 +0000
Message-ID<cj0umvFca12U1@mid.individual.net>
In reply to#36129
the_gavino_himself wrote:

> Wow forth kicks ass.
> 
> How does forth handle complexity once things grow?
> I remember reading Charles Moore saying complexity can be moved into data.
> Lispers say most complex c programs require a half assed lisp to be
> implemented inside the program. Also, I read Jeff Fox (rip) saying that
> networked forth with forth-linda allowed easy multi node clusters to
> attack problems. Does forth get used that way still? His essay said
> something like a remote execution was as easy as loop or something.
> Ultratechnology is an inspiring site.

Part of the way Fprth handles the complexity is that during design you are 
able to identify the components you need to resolve a particular solution. 
You can design what looks like something more complex but it remains an 
entity simple enough to describe, consider and test.

For example, take the humble carburettor. It has a body, some small shafts, 
a needle, a butterfly valve, some nuts springs and screws. Each of the 
individual items are part of the make up, some components even consist of 
other components fixed together. Yet, you can refer to the whole as a 
carburettor and, because people know what that is, you can speak of it in 
its part in the workings of an engine.

This is taking the Component Oriented view of a system. The nice thing about 
components is that they are self-complete, fully describable items with 
definite interfaces and a thoroughly testable as an entity. Forth is a very 
nice Componented Oriented Development Environment (see my EuroForth 2014 
paper on the topic for more material).

-- 
********************************************************************
Paul E. Bennett IEng MIET.....<email://Paul_E.Bennett@topmail.co.uk>
Forth based HIDECS Consultancy.............<http://www.hidecs.co.uk>
Mob: +44 (0)7811-639972
Tel: +44 (0)1235-510979
Going Forth Safely ..... EBA. www.electric-boat-association.org.uk..
********************************************************************

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


#36142

Fromskydda.barnen@gmail.com
Date2015-01-30 02:39 -0800
Message-ID<9f92684b-cc26-4019-bece-e905a2d78b59@googlegroups.com>
In reply to#35964
Den fredag 23 januari 2015 kl. 04:34:36 UTC+1 skrev the_gavino_himself:
> can forth do something similar with loop and the return stack?
> 
> (+ 3 4 5 6 7 8)
> 
> seems nicer than
> 
> 3 4 5 6 7 8 + + + + + .
> 
> it seems loop and the stack could be made to do something like lisp does

VARIABLE SSP
: { DEPTH SSP ! ;
: } DEPTH SSP @ - ' SSP ! 1 DO SSP @ EXECUTE LOOP ;

{ 1 2 3 4 5 } * gives 120
{ 1 2 3 4 5 } + gives 15

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


#36143

From"Alex McDonald" <blog@rivadpm.com>
Date2015-01-30 11:32 +0000
Message-ID<mafq2v$e04$1@dont-email.me>
In reply to#36142
on 30/01/2015 10:39:47, skydda wrote:

> 
> VARIABLE SSP
>: { DEPTH SSP ! ;
>: } DEPTH SSP @ - ' SSP ! 1 DO SSP @ EXECUTE LOOP ;
> 
> { 1 2 3 4 5 } * gives 120
> { 1 2 3 4 5 } + gives 15
> 

Except it won't compile code that works when executed.

: X { 2 3 4 } * ;

throws an error. At run time, the ' tick is trying to parse for a token
to derive its xt. Making } IMMEDIATE doesn't help, since the DO EXECUTE
LOOP is taking place at the wrong time.

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


#36144

Fromlehs <skydda.barnen@gmail.com>
Date2015-01-30 04:08 -0800
Message-ID<cf51e292-e03a-41df-a68a-c742adb05479@googlegroups.com>
In reply to#36143
Den fredag 30 januari 2015 kl. 12:32:18 UTC+1 skrev Alex McDonald:
> on 30/01/2015 10:39:47, skydda wrote:
> 
> > 
> > VARIABLE SSP
> >: { DEPTH SSP ! ;
> >: } DEPTH SSP @ - ' SSP ! 1 DO SSP @ EXECUTE LOOP ;
> > 
> > { 1 2 3 4 5 } * gives 120
> > { 1 2 3 4 5 } + gives 15
> > 
> 
> Except it won't compile code that works when executed.
> 
> : X { 2 3 4 } * ;
> 
> throws an error. At run time, the ' tick is trying to parse for a token
> to derive its xt. Making } IMMEDIATE doesn't help, since the DO EXECUTE
> LOOP is taking place at the wrong time.

I couldn't imagine that anyone would need a routine like X, but of cause it is possible to do even such an extension in Forth. It's just a little more complicated.

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


#36161

Fromlehs <skydda.barnen@gmail.com>
Date2015-01-30 08:38 -0800
Message-ID<9187393f-42c8-4dc7-8241-914fca130a2a@googlegroups.com>
In reply to#36143
Den fredag 30 januari 2015 kl. 12:32:18 UTC+1 skrev Alex McDonald:
> on 30/01/2015 10:39:47, skydda wrote:
> 
> > 
> > VARIABLE SSP
> >: { DEPTH SSP ! ;
> >: } DEPTH SSP @ - ' SSP ! 1 DO SSP @ EXECUTE LOOP ;
> > 
> > { 1 2 3 4 5 } * gives 120
> > { 1 2 3 4 5 } + gives 15
> > 
> 
> Except it won't compile code that works when executed.
> 
> : X { 2 3 4 } * ;
> 
> throws an error. At run time, the ' tick is trying to parse for a token
> to derive its xt. Making } IMMEDIATE doesn't help, since the DO EXECUTE
> LOOP is taking place at the wrong time.

SP-FORTH - ANS FORTH 94 for Win95/98/Me/NT/2k/XP/Vista
Open source project at http://spf.sf.net
Russian FIG at http://www.forth.org.ru ; Started by A.Cherezov
Version 4.20 Build 001 at 21.Jan.2009

VARIABLE SSP
 Ok
: { DEPTH SSP ! ;
 Ok

 Ok
: EXC SSP ! 1 DO SSP @ EXECUTE LOOP ;
 Ok

 Ok
: RBR DEPTH SSP @ - ;
 Ok

 Ok
: } STATE @
  IF POSTPONE RBR
     [COMPILE] '
     POSTPONE LITERAL
     POSTPONE EXC
  ELSE RBR ' EXC
  THEN
; IMMEDIATE
 Ok

 Ok
{ 2 3 5 7 } *
 Ok ( 210 )

 Ok ( 210 )
: TEST { 2 3 5 7 } + ;
 Ok ( 210 )

 Ok ( 210 )
TEST
 Ok ( 210 17 )

But, it's difficult to compare LISP and FORTH. LISP has a great generality of one kind while FORTH has a great generality of an other kind.

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


#36174

FromCoos Haak <chforth@hccnet.nl>
Date2015-01-30 22:01 +0100
Message-ID<13dtq77dnqzri$.wxeniqwvj8p4.dlg@40tude.net>
In reply to#36161
Op Fri, 30 Jan 2015 08:38:53 -0800 (PST) schreef lehs:

<snip>
>: } STATE @
>   IF POSTPONE RBR
>      [COMPILE] '
>      POSTPONE LITERAL
>      POSTPONE EXC
>   ELSE RBR ' EXC
>   THEN
> ; IMMEDIATE

If SP-FORTH is truly ANS FORTH 94 compatible, then ' (tick) is not
immediate. Rewrite this as:
: } STATE @
  IF POSTPONE RBR
     POSTPONE '
     POSTPONE EXC
  ELSE RBR ' EXC
  THEN
; IMMEDIATE

-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web