| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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... |
|
#4
| |||
| |||
| 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.). |
|
#5
| |||
| |||
| 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 |
|
#6
| |||
| |||
| 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 |
|
#7
| |||
| |||
| 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." ================================================== |
|
#8
| |||
| |||
| 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 |
|
#9
| |||
| |||
| 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 |
|
#10
| |||
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.