On Fri, 11 May 2012 17:01:02 -0700, Paul Rubin wrote:
> Arnold Doray <
inv...@invalid.com> writes:
>>>> 333833500 1000001 ok How would you do this in "mainstream" forth?
>>> Loops and stack juggling or accumulation variables.
>> Of course, Forth is "Turing Complete". However I'd bet the result would
>> be much harder to debug and understand.
>
> Not when you count implementing all the infrastructure (such as the JVM)
> needed to get the "abstract" version to do anything. At least one
> aspect of Forth culture seems to include blurring/erasing the boundary
> between the user program and the system environment, as part of getting
> rid of abstraction. That makes certain sense in an embedded product: if
> the software does the wrong thing, it must be fixed, no matter what part
> of the software is at fault. Taking that approach means "debugging" has
> to include fixing any JVM or Java compiler bugs that interfere with your
> program's operation (or similarly fixing any bugs in a traditional Forth
> that you might use instead). From that perspective, the traditional
> Forth is probably easier to debug and understand, just because there's
> orders of magnitude less code.
>
What I'm advocating here is that Forth is capable of much more than just
being relevant to embedded programming. So the question is "what is
Forth?". I don't know. But what I am coming to appreciate is CM's spirit
of innovation - he's always advocated finding your own Forth. I used to
think that this "zeitgeist" was counterproductive for Forth as a
language, for obvious reasons. But perhaps there is a middle ground
between standardization and innovation?
I know that Java at least has taken this tack, with separate editions for
different environements.
Coming back to your objection above, I cannot agree. I wrote this Forth
in Java in a few days. I am in no way an expert in these matters, but it
just worked. A lot of it was just bootstrapped using Forth.
From this experience, I believe once you get the VM right (in this case I
used the JVM), the rest is dead easy.
I must empahasize that I have not changed Forth -- I can't agree with
approaches like Reva that change the language substantially.
In the Forth I wrote, all the constructs you are used to in "traditional"
Forth will work. Well, at least the ones I've bothered to implement :). I
have only added other things like boxed quantities, seqs, etc. But the
thinking about these things is trivially the same.
There are some things that are a little different, one of which is
operator overloading (not in the C++ sense). For example, the / operator
will work on ints, floats, rationals and complex numbers. Eg, to divide
45 + 3i and 2/3 + 3i, you'd do just:
45::3 2/3::3 / .
{351/85 , -1197/85i} ok
But this change is not too hard to grasp surely. It simplifies the
language because there is no need for the additional words for floats,
etc.
One thing I have stayed away from is some notion of type. There are
*huge* benefits with types - eg, the ability to define sets of operations
on a type. For example, you might want to implement quarternions (or
complex numbers), instead of having them be natively defined. But I can't
think of a way to do this that would still feel like "Forth". Any
pointers?
>> Part of the reason for doing this is that we have a huge load of legacy
>> code (in Java), which needs to be accessed by non-programmers. I really
>> don't think they could use Clojure effectively in their work. I can see
>> them using Forth.
>
> I'm skeptical but it will be interesting to find out. I think Lisp is
> far easier to use because functions have named parameters that you can
> refer to without having to juggle the stack (locals in Forth aren't
> traditional). I personally find Forth rather difficult (though
> enjoyable) even though I'm a programmer relatively comfortable with
> unusual languages. Lazy sequences are fundamental to Haskell and
> reasoning about their behavior is a notorious obstacle to becoming
> productive in Haskell. I have trouble with it myself, which is why I
> consider myself not really that far out of the beginner zone in Haskell.
>
All you need are locals really, and most stack juggling disappears.This
makes Forth accessible to even beginners. The lack of syntax makes it
easy to pick up.
I feel "traditional" Forth is only "difficult" when it is pressed to do
work outside its narrow embedded domain. But this could be said of any
language.
I don't think lazy sequences are the problem with Haskell. The problem
with Haskell is that it is lazy everywhere. That's why it's easy to get
lost.
> So I think expecting non-programmers to deal with stack manipulation,
> lazy evaluation, and (this didn't come up so I'm presuming) the absence
> of a type system to explain their errors, sounds wildly optimistic.
>
No, I don't think it is hard to understand. I would go so far to say that
it is actually very intuitive for beginners.
What most people find hard is recursive thinking -- upon which much of
the elegance of Lisp/Scheme hinges on. I know because I have had to
teach domain experts. Not something I want to repeat.
>
>> Here is a practical example of reading and parsing a CSV file
>> containing energy estimates and getting the RMS errors:
>
> I found that example 1) hard to read, and 2) reminds me of APL. If you
> want APL, why not use it?
LOL. I'll probably get the same response from comp.lang.apl -- "What
you're doing sounds like Forth. Why not use Forth?" :)
Cheers,
Arnold