On Oct 21, 6:36 am, "Rod Pemberton" <do_not_h...@notemailnotz.cnm>
wrote:
> "Hugh Aguilar" <
hughaguila...@yahoo.com> wrote in message
>
> news:717bab9e-8733-4399...@i2g2000pbi.googlegroups.com...> On Oct 20, 6:00 pm, "Rod Pemberton" <do_not_h...@notemailnotz.cnm>
> > wrote:
>
> ...
>
> > [Novices] should have basic stuff such as records,
> > arrays and linked-lists available already.
>
> C has structs and arrays. That's what's needed.
>
> > This is necessary for even the simplest program.
>
> As C proves - it's missing them too - there is minimal need for
> linked-lists. Are they needed from time to time? Yes. So are complex
> numbers, but C didn't support those for a long time either.
I was impressed by how Factor uses "sequences" as its primary data
structure (these are arrays, but with Factor's dynamic memory they can
be resized easily). There are other data structures available, and you
can write whatever you want, but all the libraries primarily expect
data in sequences. Similarly, Scheme and Lisp use lists, which behave
very similarly to sequences although they are implemented differently
internally. Lua has tables. Awk has associations, which are similar.
I think that every language needs to have a standard data structure
that all the libraries primarily work with. This is what Forth sorely
lacks however. I implemented linked-lists in the novice package for
this purpose. Almost all programs can use them. In some cases a
different data structure, such as a hash table or a binary tree, might
be a better choice (I provided association arrays based on LLRB trees
in the novice package for anybody who needs this). You can go pretty
far with lists however --- I use them all the time.
Complex numbers are completely different. This isn't a general-purpose
data-structure; this is for a specific and rare use. Fortran had
complex numbers and matricies, but it was not a general-purpose
language --- it was for numerical work (something that most
programmers avoid like the plague).
The word "computer" implies that the things compute numerically. This
may have been true in the 1950s when the machines were replacing rooms
full of guys with slide-rules, but it isn't true anymore. Beginning in
the 1960s, almost all software involves converting data from one
format to another. The machines should be called "formatters" rather
than "computers."
> > I remember in MS-DOS days that we had QBasic that lacked records.
> > The typical solution was to define multiple arrays, each of which
> > contained one field of the record. After you calculate your index it
> > would be used in the appropriate array to get whatever field you need.
>
> Isn't that the way Forth _still_ does it?
>
> See CFA, LFA, PFA, or >BODY, >NAME, >LINK, etc. They all define
> offsets from the start of a "struct". I think I may have mentioned this in
> a prior conversation. The only C compiler I'm aware of that requires the
> user to use offsets to implement struct's is an old and very primitive
> compiler known as SmallC.
I don't understand what you are saying. All records (structs) are
implemented with offsets. You have the record with all of the fields
adjacent to each other, and you access the fields by their offset from
the base of the record.
In QBasic, the fields weren't adjacent to each other. There was a
separate array for each field. This was a crude workaround for
QBasic's lack of support for records.
> > I agree that Forth has weaknesses. I don't think that C is any better
> > though; C is worse.
>
> Yet, nearly every language in existence uses or has used C as it's backend.
> Doesn't that prove C's effectiveness?
That doesn't "prove" anything.
Look at how horribly slow Gforth is. That is because it was written in
C rather than assembly-language. Your C-based Forth will also be
horribly slow for the same reason.
I have never seen any language written in C that provided decent
speed. C is used primarily for convenience. We have scripting
languages such as Lua or AutoLisp that don't have to be fast, but are
just provided to allow the user of the software to customize it. We
also have languages such as Gambit or Chicken Scheme that allow the
programmer to take advantage of the many C libraries available. In all
cases however, C implementations are grossly inefficient compared to
assembly-language implementations.
> > In Forth something like EACH is difficult to implement because
> > ANS-Forth lacks closures. Both Forth and C are seriously hamstrung
> > by their lack of support for closures.
>
> "Closures" seems to be the one "magic" feature that everyone seems to think
> is missing from their favorite language. What's so special about closures?
>
> What does C need closures for? What does Forth ... ?
>
> I may have asked you that previously. I know I've asked others on
> comp.lang.misc and elsewhere. I doubt I've gotten a satisfactory answer so
> far. I may need to see sample code to grasp the issue ...
Look at my slide-rule program. See how I use EACH. ANS-Forth doesn't
really support closures, but this is pretty close.
Closures are hugely important! I think that OOP is overrated; I'm only
going to support a very rudimentary form of OOP in Straight Forth. By
comparison however, closures can't be overrated --- they really
simplify programs a lot.
> C has been used to implement nearly all, if not all, of the languages on
> Wikipedia's "closure" page that have closures or closure like structures. I
> know I've been over _this_ previously on c.l.f. ...
>
> > [...] and C be phased out.
>
> Lol! (I just don't foresee that happening any time soon.)
>
> C still very effectively captures the "essence" of a modern microprocessor.
That is definitely bad news, that the essence of modern
microprocessors could be something so ugly and limiting as C. I think
that is more the essence of C programmers, rather than the essence of
the hardware --- the hardware can support any language.
It is true that many microprocessors were designed to support C. The
x86, for example, has support for the C stack-frame, and it even has
ENTER and LEAVE instructions (as does the 68000). The processors were
designed this way because C was popular, and this doesn't at all imply
that C became popular because it C is a natural language for micro-
processors --- you are getting cause and effect mixed up. Processors
can be designed to support any language --- Forth and Lisp have both
been targeted successfully.
As a practical matter, I agree that C won't get phased out any time
soon. I am learning Gambit Scheme primarily because it compiles into C
and hence can use C libraries. There are a lot of C libraries! By
comparison, Racket Scheme and the several Common Lisp systems can
interface to C libraries but this isn't really what they are for ---
they each have their own ecosystem of libraries. By using Gambit
Scheme I can use C without having to actually program in C --- keep
the ugliness hidden under the hood.