Reply by rickman November 30, 20152015-11-30
On 11/30/2015 2:02 AM, Paul Rubin wrote:
> rickman <gnuarm@gmail.com> writes: >> We have had similar discussions before. You criticize my possible >> lack of experience with Python, then acknowledge your lack of >> experience with Forth. So if you aren't really fluent with Forth, why >> do you feel you are in a position to criticize it or even discuss it? > > No idea what possessed you to necro a 4 month old post but I've written > a KLOC or so of Forth and studied the implementation techniques closely. > That's not enough to have the instincts of an expert, but it's way > beyond zero experience or newbie range. Plus I've read discussions > between experts here on CLF and see the kind of stuff that they find > difficult. So I have a reasonable sense of Forth's strong and weak > points, it seems to me. Anyway, do you really want a scripting > extension that requires an expert to be able to use it?
I think your 1 KLOC has given you a false sense of familiarity with the language. What sorts of things do the experts here claim to have difficulty with in Forth? -- Rick
Reply by Paul Rubin November 30, 20152015-11-30
rickman <gnuarm@gmail.com> writes:
> We have had similar discussions before. You criticize my possible > lack of experience with Python, then acknowledge your lack of > experience with Forth. So if you aren't really fluent with Forth, why > do you feel you are in a position to criticize it or even discuss it?
No idea what possessed you to necro a 4 month old post but I've written a KLOC or so of Forth and studied the implementation techniques closely. That's not enough to have the instincts of an expert, but it's way beyond zero experience or newbie range. Plus I've read discussions between experts here on CLF and see the kind of stuff that they find difficult. So I have a reasonable sense of Forth's strong and weak points, it seems to me. Anyway, do you really want a scripting extension that requires an expert to be able to use it? You might give the MicroPython live demo a try: http://micropython.org/live/ (Hmm, it's not working right now, but it's really cool when it does). MicroPython needs around 100k of code space and 10k of ram from what I understand. That's less tiny than Forth can be, but still within range of cheap midrange MCU's including the 2 dollar ESP8266 boards. If not, NodeMCU definitely fits in those things (eLua instead of Python) and lots of them are shipping with it pre-installed.
Reply by rickman November 29, 20152015-11-29
On 7/24/2015 1:15 PM, Paul Rubin wrote:
> rickman <gnuarm@gmail.com> writes: > [Ok, replying to your crosspost even though my own earlier post was only > on comp.arch.embedded where the original question was. The question > regards scripting home automation stuff on an embedded Linux system]. > >>> Forth is likely to be too low level for this sort of programming. >>> It's virtue is being able to run in very small memory space, like >>> under 10K of code space and a few hundred ram bytes in an MCU. >> I find your analysis of Forth to be very naive. Much the same as >> other languages like C, Forth provides a basic capability with more >> advanced capabilities provided through libraries. > > Sure, I'd consider C to also be low level though. I'd have to add that > Forth doesn't have nearly as many available libraries, because of the > smaller userbase, but I think partly from a minimalist "do everything > yourself" spirit in Forth culture. > >> Suggesting that Forth is only useful where the entire development >> system needs to reside in 10 KB of code is a red herring. > > I didn't mean to suggest a 10K maximum. I meant Forth had the > capability of running in such small space and that this is IMHO a big > achievement and advantage that it has, but it dictated a lot of Forth's > design decisions. Historically Forth was most successful in the era of > 16-bit systems with up to 64k ram, or maybe on MSDOS PC's with up to > 640k. Once you have tens of MB available the tradeoffs in scripting > become a lot different. > > Other Forth advantages include pauseless operation (necessary for > real-time programs), higher cpu efficiency than Python even in simple > interpreters, and very high efficiency (comparable to C) if you use an > optimizing compiler. But, in the context of scripting, these are > usually not important. Python burns more machine resources, but in > return it takes care of a lot of issues for you that you'd have to spend > your own time looking after in Forth or C. > >> Otherwise Forth can be used to advantage in the same environments >> where you would use C, Python or any others. > > I didn't say anything about C and I'd consider it comparable to Forth in > most regards. C would IMHO be a poor choice of scripting language in > this situation too. > > Have you actually used Python? It's not anything like C or Forth. > Lumping Python with C seems to miss the distinction. If you haven't > actually used both, then making comparisons between them isn't > convincing. > >> It typically comes with exactly the sort of capabilities needed for >> this project. A parser is built in with full capability of being used >> in the application and most Forths running under an OS support >> networking. > > If the OP has control over the network protocol then using the Forth > parser can be a simple and efficient solution, especially if the network > devices are all trusted. If there are devices speaking protocols like > XML (some home automation stuff is like that) then Forth starts to be > painful. I don't know if a Forth TLS stack even exists. > >> Referring to Forth as being "like assembler" just shows how little you >> understand the language and appreciate its features. > > I understand Forth pretty well at a technical level, though I'm not a > very fluent user in terms of being used to the idioms it takes to use it > productively.
We have had similar discussions before. You criticize my possible lack of experience with Python, then acknowledge your lack of experience with Forth. So if you aren't really fluent with Forth, why do you feel you are in a position to criticize it or even discuss it? -- Rick
Reply by WJ November 28, 20152015-11-28
WJ wrote:

> Paul Rubin wrote: > > > > Otherwise Forth can be used to advantage in the same environments > > > where you would use C, Python or any others. > > > > I didn't say anything about C and I'd consider it comparable to Forth in > > most regards. C would IMHO be a poor choice of scripting language in > > this situation too. > > > > Have you actually used Python? It's not anything like C or Forth. > > Lumping Python with C seems to miss the distinction. If you haven't > > actually used both, then making comparisons between them isn't > > convincing. > > It's obvious that the reason that he is recommending Forth > over all other languages is that he knows no language that > is higher-level than Forth. And he finds it too difficult > to learn another language. > > If a hammer is the only tool that you have, then you use > a hammer for everything. > > How would these tasks be done with a hammer? > > Using Gauche Scheme: > > Write a function that accepts a vector (1-dimensional array) of > 16-bit numbers and replaces each number with its difference > from the average. > > (use gauche.uvector) > (use gauche.collection) > > (define (relativize vec) > (let ((avg (round->exact (/ (fold + 0 vec) (s16vector-length vec))))) > (s16vector-sub! vec avg))) > > (define my-vec (s16vector 0 1 2 3 4 5 6 7 8 9)) > (relativize my-vec) > my-vec > ===> > #s16(-4 -3 -2 -1 0 1 2 3 4 5) > > > Take a string that contains numbers separated by semicolons or > commas and convert it to a list of numbers. > > (map string->number (string-split "2,3.14;5.8,9" #/[,;]/)) > ===> > (2 3.14 5.8 9)
Ocaml: #load "str.cma";; List.map float_of_string (Str.split (Str.regexp "[,;]") "2,3.14;5.8,9");; ===> [2.; 3.14; 5.8; 9.]
Reply by rickman July 24, 20152015-07-24
On 7/24/2015 8:00 PM, Don Y wrote:
> On 7/24/2015 4:06 PM, WJ wrote: > >> It's obvious that the reason that he is recommending Forth >> over all other languages is that he knows no language that >> is higher-level than Forth. And he finds it too difficult >> to learn another language. >> >> If a hammer is the only tool that you have, then you use >> a hammer for everything. >> >> How would these tasks be done with a hammer? >> >> Using Gauche Scheme: >> >> Write a function that accepts a vector (1-dimensional array) of >> 16-bit numbers and replaces each number with its difference >> from the average. >> >> (use gauche.uvector) >> (use gauche.collection) >> >> (define (relativize vec) >> (let ((avg (round->exact (/ (fold + 0 vec) (s16vector-length vec))))) >> (s16vector-sub! vec avg))) >> >> (define my-vec (s16vector 0 1 2 3 4 5 6 7 8 9)) >> (relativize my-vec) >> my-vec >> ===> >> #s16(-4 -3 -2 -1 0 1 2 3 4 5) >> >> >> Take a string that contains numbers separated by semicolons or >> commas and convert it to a list of numbers. >> >> (map string->number (string-split "2,3.14;5.8,9" #/[,;]/)) >> ===> >> (2 3.14 5.8 9) > > What role would these have in the scripting of an automation system? > IME, tasks in that domain tend to be more procedural oriented.
WJ is an odd sort. You won't find that he is much of a conversationalist. Rather he communicates in terms of code for any manner of interesting, even if irrelevant, examples. Just one of the many odd birds flitting about in the Forth newsgroup. -- Rick
Reply by Don Y July 24, 20152015-07-24
On 7/24/2015 4:06 PM, WJ wrote:

> It's obvious that the reason that he is recommending Forth > over all other languages is that he knows no language that > is higher-level than Forth. And he finds it too difficult > to learn another language. > > If a hammer is the only tool that you have, then you use > a hammer for everything. > > How would these tasks be done with a hammer? > > Using Gauche Scheme: > > Write a function that accepts a vector (1-dimensional array) of > 16-bit numbers and replaces each number with its difference > from the average. > > (use gauche.uvector) > (use gauche.collection) > > (define (relativize vec) > (let ((avg (round->exact (/ (fold + 0 vec) (s16vector-length vec))))) > (s16vector-sub! vec avg))) > > (define my-vec (s16vector 0 1 2 3 4 5 6 7 8 9)) > (relativize my-vec) > my-vec > ===> > #s16(-4 -3 -2 -1 0 1 2 3 4 5) > > > Take a string that contains numbers separated by semicolons or > commas and convert it to a list of numbers. > > (map string->number (string-split "2,3.14;5.8,9" #/[,;]/)) > ===> > (2 3.14 5.8 9)
What role would these have in the scripting of an automation system? IME, tasks in that domain tend to be more procedural oriented.
Reply by WJ July 24, 20152015-07-24
Paul Rubin wrote:

> > Otherwise Forth can be used to advantage in the same environments > > where you would use C, Python or any others. > > I didn't say anything about C and I'd consider it comparable to Forth in > most regards. C would IMHO be a poor choice of scripting language in > this situation too. > > Have you actually used Python? It's not anything like C or Forth. > Lumping Python with C seems to miss the distinction. If you haven't > actually used both, then making comparisons between them isn't > convincing.
It's obvious that the reason that he is recommending Forth over all other languages is that he knows no language that is higher-level than Forth. And he finds it too difficult to learn another language. If a hammer is the only tool that you have, then you use a hammer for everything. How would these tasks be done with a hammer? Using Gauche Scheme: Write a function that accepts a vector (1-dimensional array) of 16-bit numbers and replaces each number with its difference from the average. (use gauche.uvector) (use gauche.collection) (define (relativize vec) (let ((avg (round->exact (/ (fold + 0 vec) (s16vector-length vec))))) (s16vector-sub! vec avg))) (define my-vec (s16vector 0 1 2 3 4 5 6 7 8 9)) (relativize my-vec) my-vec ===> #s16(-4 -3 -2 -1 0 1 2 3 4 5) Take a string that contains numbers separated by semicolons or commas and convert it to a list of numbers. (map string->number (string-split "2,3.14;5.8,9" #/[,;]/)) ===> (2 3.14 5.8 9) -- The report card by the American Society of Civil Engineers showed the national infrastructure a single grade above failure, a step from declining to the point where everyday things simply stop working the way people expect them to. --- washingtonpost.com/local/trafficandcommuting/us-infrastructure-gets-d-in-annual-report/2013/03/19/c48cb010-900b-11e2-9cfd-36d6c9b5d7ad_story.html
Reply by rickman July 24, 20152015-07-24
On 7/23/2015 3:08 PM, rickman wrote:
> On 7/23/2015 5:24 AM, abhishekkumardwivedi@gmail.com wrote: >> I was automating my home LAN. >> Need suggestion for automation scripting upon embedded Linux, to do >> some operations over LAN, such as scan and ping other devices, string >> like data transfer,etc. And there is need of some logic to parse >> received content. Perl, python, lua or simple shell scripting .. which >> one? There will be branch and loop operations, better to have more >> ready tools for network operations.. >> >> Parser and LAN are the key here. > > The obvious choice for this is Forth. You can commercial products from > Forth, Inc in the US or MPE in Europe. A good open source product is > Gforth among many others.
I cross posted this here so the OP could get some insight into the Forth community. However, many of the replies are only to the Forth group where they will never be seen by the OP. -- Rick
Reply by Paul Rubin July 24, 20152015-07-24
rickman <gnuarm@gmail.com> writes:
[Ok, replying to your crosspost even though my own earlier post was only
on comp.arch.embedded where the original question was.  The question
regards scripting home automation stuff on an embedded Linux system].

>> Forth is likely to be too low level for this sort of programming. >> It's virtue is being able to run in very small memory space, like >> under 10K of code space and a few hundred ram bytes in an MCU. > I find your analysis of Forth to be very naive. Much the same as > other languages like C, Forth provides a basic capability with more > advanced capabilities provided through libraries.
Sure, I'd consider C to also be low level though. I'd have to add that Forth doesn't have nearly as many available libraries, because of the smaller userbase, but I think partly from a minimalist "do everything yourself" spirit in Forth culture.
> Suggesting that Forth is only useful where the entire development > system needs to reside in 10 KB of code is a red herring.
I didn't mean to suggest a 10K maximum. I meant Forth had the capability of running in such small space and that this is IMHO a big achievement and advantage that it has, but it dictated a lot of Forth's design decisions. Historically Forth was most successful in the era of 16-bit systems with up to 64k ram, or maybe on MSDOS PC's with up to 640k. Once you have tens of MB available the tradeoffs in scripting become a lot different. Other Forth advantages include pauseless operation (necessary for real-time programs), higher cpu efficiency than Python even in simple interpreters, and very high efficiency (comparable to C) if you use an optimizing compiler. But, in the context of scripting, these are usually not important. Python burns more machine resources, but in return it takes care of a lot of issues for you that you'd have to spend your own time looking after in Forth or C.
> Otherwise Forth can be used to advantage in the same environments > where you would use C, Python or any others.
I didn't say anything about C and I'd consider it comparable to Forth in most regards. C would IMHO be a poor choice of scripting language in this situation too. Have you actually used Python? It's not anything like C or Forth. Lumping Python with C seems to miss the distinction. If you haven't actually used both, then making comparisons between them isn't convincing.
> It typically comes with exactly the sort of capabilities needed for > this project. A parser is built in with full capability of being used > in the application and most Forths running under an OS support > networking.
If the OP has control over the network protocol then using the Forth parser can be a simple and efficient solution, especially if the network devices are all trusted. If there are devices speaking protocols like XML (some home automation stuff is like that) then Forth starts to be painful. I don't know if a Forth TLS stack even exists.
> Referring to Forth as being "like assembler" just shows how little you > understand the language and appreciate its features.
I understand Forth pretty well at a technical level, though I'm not a very fluent user in terms of being used to the idioms it takes to use it productively.
Reply by rickman July 24, 20152015-07-24
On 7/24/2015 1:00 AM, Paul Rubin wrote:
> abhishekkumardwivedi@gmail.com writes: >> like data transfer,etc. And there is need of some logic to parse >> received content. Perl, python, lua or simple shell scripting .. which >> one? There will be branch and loop operations, better to have more >> ready tools for network operations... Parser and LAN are the key here. > > I'd suggest Python of the ones you mention, assuming you have enough ram > (a Raspberry pi would be more than plenty). I use it all the time > myself. Or if you want something really different and interesting, look > at Erlang. > > Perl is old-school by now, and shell scripts too inflexible. Lua is > very elegantly implemented and compact but it lacks Python's creature > comforts. Forth is likely to be too low level for this sort of > programming. It's virtue is being able to run in very small memory > space, like under 10K of code space and a few hundred ram bytes in an > MCU. But it makes programming very low level and painstaking, almost > like assembler.
I find your analysis of Forth to be very naive. Much the same as other languages like C, Forth provides a basic capability with more advanced capabilities provided through libraries. Suggesting that Forth is only useful where the entire development system needs to reside in 10 KB of code is a red herring. This capability comes with limitations and so is only used where it is a significant advantage. Otherwise Forth can be used to advantage in the same environments where you would use C, Python or any others. It typically comes with exactly the sort of capabilities needed for this project. A parser is built in with full capability of being used in the application and most Forths running under an OS support networking. Referring to Forth as being "like assembler" just shows how little you understand the language and appreciate its features. -- Rick