Live data from Hacker News

Thinking Forth (1984)

thinking-forth.sourceforge.net

41–50 of 51 posts

Re: Thinking Forth (1984)

#41

Loved the language - first as an embedded developer (late 80s), then with Harris Semi's RTX microcontroller team. I see a Forth reference about once per month on HN but nothing in developer-specific forums, so I have to assume Forth is dead. What gives? Is there some use case that only Forth can satisfy? Is it just the simplicity and "strangeness"?

> I see a Forth reference about once per month on HN but nothing in developer-specific forums, so I have to assume Forth is dead.

Depends on your definition of dead |1].

> Is there some use case that only Forth can satisfy?

Interactive programming with really low resources, or the advantage of having an interpreter that you can tune and adapt at will.

[1] https://forth-standard.org/

Re: Thinking Forth (1984)

#43
post #35

Earlier quoted context omitted.

I'm no Forth expert, but I've found Gforth highly educational. It's interactive, runs under Linux, is free software, supports the ANS standard, is well documented, is widely used (at least as widely used as any Forth these days), is still maintained after 27 years, and supports SEE so you can disassemble words and see how they're written. Since Gforth 1.0 it has context-sensitive help ("help begin", etc.) Before Gfor…

Thank you, wonderful comment. Favorited.

I'm delighted you liked it! Your opinion here is especially important to me, given the work you've done.

Re: Thinking Forth (1984)

#44

Loved the language - first as an embedded developer (late 80s), then with Harris Semi's RTX microcontroller team. I see a Forth reference about once per month on HN but nothing in developer-specific forums, so I have to assume Forth is dead. What gives? Is there some use case that only Forth can satisfy? Is it just the simplicity and "strangeness"?

I haven't gone as deep as I'd like to into Forth, but I liken it somewhere in between Assembly and C in terms of level of abstraction, and from what I can see the trends of programming languages are features that move further away from hardware and computer specifics towards higher level concepts (the first thing that jumps to mind is Lisp)

It's a bit like rolling your own macro assembler, in a way.

Re: Thinking Forth (1984)

#45
post #20
post #6

Earlier quoted context omitted.

Forth has not won any popularity awards since the end of the '90s but it is still used by a small group of engineers around the world to solve their custom needs. This can be for embedded projects or firmware yes, but it has crept into larger projects. IMHO opinion Forth is hard to learn, takes more effort to bootstrap your project (more like Assembler) and more importantly it is hard to switch gears to think with Ch…

YES! I worked on the FedEx Enhanced SuperTracker software from 1999-2006, which I believe is the "Version II" you're referencing. The core software was still written in Forth, but we rebuilt the package routing logic in in C, which might be what you're referring to. Very curious to know how you are familiar with all the history, did you work there or at Forth, Inc?

I worked in a Forth shop for a few years and attended a few conferences. The FEDEX story made its way around the community.

Re: Thinking Forth (1984)

#47

Earlier quoted context omitted.

I haven't gone as deep as I'd like to into Forth, but I liken it somewhere in between Assembly and C in terms of level of abstraction, and from what I can see the trends of programming languages are features that move further away from hardware and computer specifics towards higher level concepts (the first thing that jumps to mind is Lisp)

It's a bit like rolling your own macro assembler, in a way.

Yes indeed, but even more so: Forth is vastly more powerful than a mere macro assembler, because you have the full power of Forth to write arbitrary functions and mini-compilers to assemble code, no just simple macros! It comes with structured control flow constructs, and you can even write your own. Not only is the assembler itself written in Forth, but you can seamlessly extend and build on top of the it too, building high level interfaces and domain specific languages on top of low level assembly code and hardware.

Check out the amazingly powerful x86 assembler in OpenFirmware, which is deeply integrated with the hardware, operating system, bootstrapping, debugging, tracing, breakpointing, disassembling, cross assembling, meta compiling, and calling back and forth with C code:

purpose: x86 assembler

https://github.com/openbios/openfirmware/tree/master/cpu/x86

purpose: From Forth, call the C subroutine whose address is on the stack

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

purpose: Tools for creating disembodied assembly code sequences

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

purpose: Forth access words for special 386 registers

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

purpose: After a breakpoint, displays a backtrace of C stack frames.

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

purpose: 386 disassembler.

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

purpose: Access to I/O ports and physical addresses under Linux

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

    \ One of the very best features of FORTH assemblers is the ability
    \ to use structured conditionals instead of branching to nonsense
    \ labels.
    : IF
       >MARK swap
       long-offsets @  if
          dup h# eb =  if
             drop h# e9 asm8,
          else
             prefix-0f  h# 10 + asm8,
          then
          real?  if  0 asm16,  else  0 asm32,  then
       else
          ASM8,  0 asm8,
       then
    ;
    : THEN    >RESOLVE   ;
    : BEGIN    until
https://github.com/openbios/openfirmware/blob/master/cpu/x86...

    \ Some x86 assembler macros to make it easier to write x86 early
    \ startup code.  There are macros to set MSRs to specific values,
    \ to set and clear individual MSR bits, to read and write PCI
    \ configuration registers with the common CF8/CFC mechanism,
    \ and to read and write I/O ports.

    \ The code keeps the MSR register number in %ecx, the low 32 bits
    \ of the value in %eax, and the high 32 bits in %edx, consistent
    \ with the way the rdmsr and wrmsr machine instructions work.

    \ The bitset and bitclr operations work on %eax, and the -hi versions
    \ work on %edx.

    \ The I/O port operations also leave the data in %eax, so you can
    \ use bitset and bitclr with them too.

Re: Thinking Forth (1984)

#48
post #35

I'd love to learn (a) Forth. As a beginner, where do you begin? Like Lisp there seems to be different variants. I always struggle with where to start.

I'm no Forth expert, but I've found Gforth highly educational. It's interactive, runs under Linux, is free software, supports the ANS standard, is well documented, is widely used (at least as widely used as any Forth these days), is still maintained after 27 years, and supports SEE so you can disassemble words and see how they're written. Since Gforth 1.0 it has context-sensitive help ("help begin", etc.) Before Gfor…

I also love your comments, this and others!

Of course OpenFirmware has some code for paging! ;)

purpose: Set up page tables and turn on paging

https://github.com/openbios/openfirmware/blob/master/cpu/x86...

    start-assembling
    protected-mode

    \ RAM is on and mem-info-pa tells the memory layout
    label entry
       \ Initialize virtual page table
       \ Initialize linear=physical page table (redundant page table entries)
       \ Enable paging  (note that page fault handler is not in place yet)

    [ifdef] notdef
       \ clear page tables
       ax ax  xor
       /ptab /l / #  cx  mov
       pt-pa #  di  mov
       rep  ax stos
    [then]

Re: Thinking Forth (1984)

#49
post #24
post #18

Earlier quoted context omitted.

I'd recommend gforth. It runs on lots of systems and is well maintained. https://gforth.org/ Eventually you'll build your own forth (seems to be a right of passage!)

“rite of passage”

"write of passage" too!
Post reply on HN