Forth is Factorable --- factoring out DO ... LOOP

This is a discussion on Forth is Factorable --- factoring out DO ... LOOP within the Forth forums in Programming Languages category; I find that Forth is ultimately factorable. It is in fact capable of factoring loops. DO LOOP can be factored away. Here is one way to do that. : GO \ ( xt-stop xt-doer -- ) BEGIN DUP EXECUTE OVER EXECUTE UNTIL 2DROP ; Jason...

Go Back   Application Development Forum > Programming Languages > Forth

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-20-2008, 01:22 AM
Jason Damisch
Guest
 
Default Forth is Factorable --- factoring out DO ... LOOP

I find that Forth is ultimately factorable. It is in fact capable of
factoring loops. DO LOOP can be factored away. Here is one way to do
that.


: GO
\ ( xt-stop xt-doer -- )
BEGIN
DUP EXECUTE
OVER EXECUTE UNTIL
2DROP
;

Jason
Reply With Quote
  #2  
Old 08-20-2008, 03:52 AM
John Passaniti
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

On Aug 20, 1:22*am, Jason Damisch <jasondami...@yahoo.com> wrote:
> I find that Forth is ultimately factorable. *It is in fact capable of
> factoring loops. *DO LOOP can be factored away. *Here is one way to do
> that.
>
> : GO
> \ ( *xt-stop * xt-doer *-- *)
> * *BEGIN
> * * * DUP EXECUTE
> * *OVER EXECUTE UNTIL
> * *2DROP
> * *;


Most programming languages have things that aren't strictly needed. C
for example doesn't need array syntax as x[i] is equivalent to *(x +
i), but not having such notation would make common expressions
cumbersome. Forth is indeed factorable, a fact known to anyone who
has implemented a Forth or studied how given a handful of primitives,
one can bootstrap a complete Forth system. Some obvious example are
that you don't strictly need "+" because it can be defined as "negate
-" and you don't need things like "1+" and "2/" because they can be
defined in terms of other words. These kinds of things are typically
defined as primitives because it's more time-efficient, but for people
(like myself) who usually care far more about space than time, it's an
option.

Your "factored" DO/LOOP doesn't offer an index variable, so it's not a
replacement for DO/LOOP. You could of course come up with a
equivalent for words like I and J and helper functions to allow
providing the index and limit... but the result would be much more
clumsy. There might be some value in this if you routinely find your
loop bodies are typically single Forth words. Otherwise, you're going
to be forced to create names for your loop bodies or quote them
with :NONAME. Ick.
Reply With Quote
  #3  
Old 08-20-2008, 04:06 AM
Aleksej Saushev
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

John Passaniti <john.passaniti@gmail.com> writes:

> On Aug 20, 1:22*am, Jason Damisch <jasondami...@yahoo.com> wrote:
>> I find that Forth is ultimately factorable. *It is in fact capable of
>> factoring loops. *DO LOOP can be factored away. *Here is one way to do
>> that.
>>
>> : GO
>> \ ( *xt-stop * xt-doer *-- *)
>> * *BEGIN
>> * * * DUP EXECUTE
>> * *OVER EXECUTE UNTIL
>> * *2DROP
>> * *;


> You could of course come up with a
> equivalent for words like I and J and helper functions to allow
> providing the index and limit... but the result would be much more
> clumsy. There might be some value in this if you routinely find your
> loop bodies are typically single Forth words. Otherwise, you're going
> to be forced to create names for your loop bodies or quote them
> with :NONAME. Ick.


Right, that's the point.

This is the way, how, starting from Forth, you get something like Factor.


--
CE3OH...
Reply With Quote
  #4  
Old 08-20-2008, 10:30 AM
John Passaniti
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

On Aug 20, 4:06*am, Aleksej Saushev <a...@inbox.ru> wrote:
> Right, that's the point.


It is? What point is that? It doesn't seem to be the point of the
original poster.

> This is the way, how, starting from Forth, you get something like Factor.


I don't follow. I don't know the history of Factor, but it sure seems
that the starting point was functional languages. At least solutions
to problems presented in comp.lang.forth remind me of the typical
solutions one would use in functional languages. That Factor has a
Forth flavor to me seems about as relevant as other functional
languages that have chosen other syntaxes.

In any case, the notion of replacing loop bodies and terminating
conditions with functions obviously isn't new. It appears in
different forms, such as in the control structures of Smalltalk, the
generic algorithms of the STL, and functional programming languages in
the form of "map" et al.).
Reply With Quote
  #5  
Old 08-20-2008, 02:29 PM
Jason Damisch
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

well..

in instances where one doesn't use I or J and the exit condition isn't
based on a simple index then it might make sense.

Jason
Reply With Quote
  #6  
Old 08-20-2008, 02:42 PM
Anton Ertl
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

Jason Damisch <jasondamisch@yahoo.com> writes:
>I find that Forth is ultimately factorable. It is in fact capable of
>factoring loops. DO LOOP can be factored away. Here is one way to do
>that.
>
>
>: GO
>\ ( xt-stop xt-doer -- )
> BEGIN
> DUP EXECUTE
> OVER EXECUTE UNTIL
> 2DROP
> ;


Related threads contain the postings
<2007May4.214826@mips.complang.tuwien.ac.at> and
<2006Nov12.224000@mips.complang.tuwien.ac.at>.

- 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 2008: http://www.euroforth.org/ef08.html
Reply With Quote
  #7  
Old 08-20-2008, 02:44 PM
Elizabeth D Rather
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

Jason Damisch wrote:
> well..
>
> in instances where one doesn't use I or J and the exit condition isn't
> based on a simple index then it might make sense.
>
> Jason


Sure, there are many instances in which indefinite loops (BEGIN ...
UNTIL or BEGIN ... WHILE ... REPEAT) are as good as or better than DO
.... LOOP structures. There are other instances in which the presence of
a specified ending condition that isn't on the data stack and there's an
accessible current index are very valuable. That's why Forth has both
kinds of structures.

I'm not sure what your point is.

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."
==================================================
Reply With Quote
  #8  
Old 08-21-2008, 02:37 AM
astrobe
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

On 20 août, 09:52, John Passaniti <john.passan...@gmail.com> wrote:
> On Aug 20, 1:22*am, Jason Damisch <jasondami...@yahoo.com> wrote:
>
> > I find that Forth is ultimately factorable. *It is in fact capable of
> > factoring loops. *DO LOOP can be factored away. *Here is one way todo
> > that.

>
> > : GO
> > \ ( *xt-stop * xt-doer *-- *)
> > * *BEGIN
> > * * * DUP EXECUTE
> > * *OVER EXECUTE UNTIL
> > * *2DROP
> > * *;

>
> Most programming languages have things that aren't strictly needed. *C
> for example doesn't need array syntax as x[i] is equivalent to *(x +
> i), but not having such notation would make common expressions
> cumbersome. *Forth is indeed factorable, a fact known to anyone who
> has implemented a Forth or studied how given a handful of primitives,
> one can bootstrap a complete Forth system. *Some obvious example are
> that you don't strictly need "+" because it can be defined as "negate
> -" and you don't need things like "1+" and "2/" because they can be
> defined in terms of other words. *These kinds of things are typically
> defined as primitives because it's more time-efficient, but for people
> (like myself) who usually care far more about space than time, it's an
> option.
>
> Your "factored" DO/LOOP doesn't offer an index variable, so it's not a
> replacement for DO/LOOP. *You could of course come up with a
> equivalent for words like I and J and helper functions to allow
> providing the index and limit... but the result would be much more
> clumsy. *There might be some value in this if you routinely find your
> loop bodies are typically single Forth words. *Otherwise, you're going
> to be forced to create names for your loop bodies or quote them
> with :NONAME. *Ick.


Bad mood, John?
One may see a prototype of iterators, or map/reduce/filter/fold
implementation. If one moves those XTs to the return stack of course.

Amicalement,
Astrobe
Reply With Quote
  #9  
Old 08-21-2008, 04:55 PM
billy
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

John Passaniti <john.passan...@gmail.com> wrote:
> Aleksej Saushev <a...@inbox.ru> wrote:
> > This is the way, how, starting from Forth, you get something like Factor.


> I don't follow. *I don't know the history of Factor, but it sure seems
> that the starting point was functional languages.


He didn't say that this was how Slava built Factor -- he said that
this is the way you start with Forth and get something like Factor.
Slava didn't start with Forth, although Factor's design is inspired by
(among other languages) Forth.

Slava said in his first announcement:
> This language owes a lot to Joy and Lisp, and to a lesser extent, Forth.
> I'd like to thank the inventor of Joy especially for leading me to see
> the elegance and simplicity of concatenative languages.


> In any case, the notion of replacing loop bodies and terminating
> conditions with functions obviously isn't new.


This is another thing that the original poster didn't claim. No need
to refute a non-claim.

-Wm
Reply With Quote
  #10  
Old 08-22-2008, 02:00 AM
John Passaniti
Guest
 
Default Re: Forth is Factorable --- factoring out DO ... LOOP

On Aug 21, 4:55*pm, billy <wtanksle...@gmail.com> wrote:
> John Passaniti <john.passan...@gmail.com> wrote:
> > Aleksej Saushev <a...@inbox.ru> wrote:
> > > This is the way, how, starting from Forth, you get something like Factor.

> > I don't follow. *I don't know the history of Factor, but it sure seems
> > that the starting point was functional languages.

>
> He didn't say that this was how Slava built Factor


And neither did I. But you apparently are able to read all sorts of
interesting statements into my words. Witness:

> > In any case, the notion of replacing loop bodies and terminating
> > conditions with functions obviously isn't new.

>
> This is another thing that the original poster didn't claim. No need
> to refute a non-claim.


I made a simple statement of fact that is independent of whatever
motivations the original poster had for his message.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:08 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.