News for hackers. Stuff that matters.
Re:Running Forth Unikernels by protomyth on Monday April 01, 2019 @03:11PM (#19546993)
As much as I love Forth, I am a bit troubled by the list in the article:

Some interesting but by no means complete Forth properties:

    no errors
    no files
    no operating systems
    no syntax
uhm... Forth does have errors like Stack Underflow. When I programmed in Forth we did have the notion of files. It most certainly does have a syntax also.
Re:Running Forth Unikernels by delish on Monday April 01, 2019 @03:18PM (#19547070)
That list is probably inspired by Chuck Moore's article "1% the Code" https://web.archive.org/web/20060104084410/http://www.colorf...

Relevant excerpt:

>colorForth does it differently. There is no syntax, no redundancy, no typing. There are no errors that can be detected. Forth uses postfix, there are no parentheses. No indentation. Comments are deferred to the documentation. No hooks, no compatibility. Words are never hyphenated. There's no heirarchy (sic). No files. No operating system.

He probably means "blocks" instead of files and "a condition system or exception system" instead of "stack underflow."

Re:Running Forth Unikernels by astrobe_ on Tuesday April 02, 2019 @03:28AM (#19551813)
ColorForth is actually pretty much an image-based system. Moore observes that PCs have a lot more memory than he needs (indeed 1Mb is huge for a Forth system), so the image is loaded into memory and the memory is saved to disk.

It should be mentioned that Forth is one of those languages that do configuration by editing the source code. This is probably the recommendable practice, instead of INI files or worse, XML (why write another parser when you already have one?). For really big data, binary format would probably be preferred (I actually have no experience in the area), with blocks (as defined in an extension of the ANS Forth standard) acting like Linux' mmap. Strings are a little bit of a pain to deal with in Forth, so you'd rather avoid them where possible (in addition to the consideration that plain text data are inefficient). You'd rather use an hex editor or write visualization and manipulation tools for binary data rather than processing text strings. The fact that Colorforth uses a custom source format to be edited by a custom editor (the colors in the source code is not syntax highlighting, the colors are part of the "syntax") is symptomatic of this kind of approach.

A condition/exception system would probably be in the category of "hooks" according to Moore. Stack underflow/overflow are not even an error condition in some of the chips he made that feature circular stacks. However, it is true that for casual Forth programmers like me, a stack underflow condition is usually the result of an error in the program. In a way, just like Haskell programs are "most certainly correct when they compile", Forth programs are most certainly correct if they don't stack-underflow (or just segfault because that's a typical result of messing up the return stack).

Re:Running Forth Unikernels by agumonkey on Monday April 01, 2019 @04:04PM (#19547604)
has moore written books or articles ?
Re:Running Forth Unikernels by dang on Monday April 01, 2019 @04:24PM (#19547829)
Re:Running Forth Unikernels by agumonkey on Monday April 01, 2019 @09:53PM (#19550343)
dank u
Re:Running Forth Unikernels by 4thaccount on Monday April 01, 2019 @10:58PM (#19550674)
Safari online has a lengthy interview with him that is an excerpt from a book with lots of interviews on programming Titans. I read the one from Moore every year and I don't even write Forth. It is simply that good and thought provoking.
Re:Running Forth Unikernels by fizfaz on Tuesday April 02, 2019 @05:40AM (#19552414)
this one: https://www.oreilly.com/library/view/masterminds-of-programm... ? Very interesting interview indeed.
Re:Running Forth Unikernels by elisharobinson on Tuesday April 02, 2019 @04:48AM (#19552183)
yes I read it once and it genuinely is the stuff to start cults
Re:Running Forth Unikernels by 4thaccount on Tuesday April 02, 2019 @09:54AM (#19554057)
Haha, yes that is a good way to explain it. Moore isn't necessarily wrong, but I don't think he is 100% correct either. Not everybody is a software engineer who can spend all day writing code. There are a lot of folks who write shell scripts and the like who need to do talk to computers without getting into machine code and Forth. Does a lawyer need to know the machine? Sounds inefficient use of time.
Re:Running Forth Unikernels by mruts on Monday April 01, 2019 @03:18PM (#19547065)
People talk about forth having no syntax the same way people talk about lisp having no syntax: not entirely correctly. Of course, every textual representation of anything has a syntax, but when people talk about something not having a syntax what they really mean is that the syntax is uniform: there is only one global (uniform) syntax.
Re:Running Forth Unikernels by madhadron on Tuesday April 02, 2019 @01:00AM (#19551222)
> there is only one global (uniform) syntax.

Not quite. You have access to the reader in Forth, and it's quite typical to write a word that takes over for the reader for some time and then hands back to the usual reader. Julian Noble used this to implement a subset of FORTRAN for computational physics (more convenient than postfix for doing that) and to make state machine transition tables into code. Sadly, he is no longer with us.

Common Lisp also provides access to the reader, so you can do the same trick, but it's not a ubiquitous thing to do the way it is in Forth.

Re:Running Forth Unikernels by boomlinde on Monday April 01, 2019 @08:08PM (#19549699)
> there is only one global (uniform) syntax.

While I agree with the general sentiment that Forth does have a syntax, this statement is not true in Forth. Instead, syntax is extremely local, because words may take over the parser and compiler to implement their own syntax.

For example, "(" (which is used for comments) is typically implemented as a word that immediately executes during the compilation phase, takes over the input loop and just reads and discards characters until it has discarded the matching ")" character before returning control to the regular compiler. It has its own little parsing loop going on with its own syntax, totally overriding any global syntax for as long as it feels like.

Re:Running Forth Unikernels by bunderbunder on Monday April 01, 2019 @05:32PM (#19548508)
I'd argue that Lisp has a syntax in that you do need at least a context-free grammar to describe valid Lisp programs.

With Forth, on the other hand, while there is a rule for deciding when one word ends and another ends, and how to interpret literals, I think that, for all practical purposes, there aren't actually any strings that are syntactically invalid.

As the ANSI Forth standard puts it:

> This Standard does not require a syntax or program-construct checker.

(page 33)

Re:Running Forth Unikernels by benj111 on Monday April 01, 2019 @03:35PM (#19547256)
I've always interpreted it as a lack of keywords etc.

Both lisp and forth can be built up from a small number of primitives. Everything you use day to day is basically optional.

Re:Running Forth Unikernels by MrEldritch on Monday April 01, 2019 @04:27PM (#19547859)
Yeah, there's "no syntax" in the sense that you could adequately describe the syntax rules on a Post-it.
Re:Running Forth Unikernels by Someone on Monday April 01, 2019 @03:24PM (#19547140)
Traditional forth has blocks each 1k in size, n≥1 buffers that each can hold a single block, and words

- BLOCK: reads an individual block, returns address where it was loaded.

- UPDATE: marks most recent block as dirty.

- FLUSH: writes out all dirty blocks.

ANSI forth (I think) added EMPTY-BUFFERS, which marks all blocks as not-dirty.

If you wanted more, you could implement a file system on top of that.

Example usage at http://wiki.c2.com/?ForthBlocks (includes a full-screen editor)

Re:Running Forth Unikernels by abecedarius on Monday April 01, 2019 @05:12PM (#19548277)
ANS Forth does include file I/O as well as blocks. Back when I worked at FORTH, Inc. we all just used blocks.

(also iirc EMPTY-BUFFERS predates ANS Forth, though maybe it wasn't standard then.)

Re:Running Forth Unikernels by upofadown on Monday April 01, 2019 @05:32PM (#19548506)
It gets philosophical fast, but something like a stack underflow error is a feature of the interpreter. It is not a part of the language itself. A misbehaving Forth program will happily underflow through all of memory.
Re:Running Forth Unikernels by MaxBarraclough on Tuesday April 02, 2019 @05:32PM (#19558787)
According to the language spec, it seems to be non-compliant to handle stack overflow that way (even if it's obviously a good feature):

> In all integer arithmetic operations, both overflow and underflow shall be ignored. The value returned when either overflow or underflow occurs is implementation defined.

http://www.forth.org/svfig/Win32Forth/DPANS94.txt

Re:Running Forth Unikernels by upofadown on Wednesday April 03, 2019 @05:10PM (#19567292)
I think they mean arithmetic overflow and underflow.
Re:Running Forth Unikernels by MaxBarraclough on Wednesday April 03, 2019 @06:40PM (#19567826)
Oops! Second attempt: looks like they single out "stack underflow" as implementation-defined behaviour:

> A system shall document the system action taken upon each of the general or specific ambiguous conditions identified in this Standard.

So, essentially the opposite of what I said.