News for hackers. Stuff that matters.
Re:The Oforth Programming Language by luckydude on Wednesday March 28, 2018 @12:27AM (#16695285)
[I'm sticking this here because there was a dude who said this was a good reply and I tried to reply to him and HN say s his post was deleted. I don't know why, his post seemed pretty reasonable to me, he was asking if forth was a good boot loader. Shrug.]

I don't for a minute think that forth is the best answer, it's an awful answer. Even lisp, which I hate with a passion, would be a better answer because more people have experience in lisp than forth.

Forth is just less shitty than what Intel came up with, I think it was part of EFI, it's amazingly bad. I've designed a few programming languages and I'm not good at it, but holy crap, I could be drunk and come up with a better answer than Intel did. Forth is just a crappy language but it's less crappy than what Intel did.

The idea that Forth is somehow special for boot loaders is nuts. There is nothing, that I know of, that makes forth somehow magical for that.

What you want for the bootloader, and for the debugger that you drop into when there is a panic, is something like C but interpreted. You want to be able to walk a linked list of page table structures. And to its credit, Sun's forth could do that. It's sort of twisted to think it could but it did, there were forth words that did all sorts of kernel magic.

I think that the magic of forth was that it was tiny, back 30 years ago you didn't want to have a lot of storage for your debugger. That's not the case today, if someone made the case that they could make things better, here you go, here's a gig of storage. That's a little crazy but still. Forth was cool when a meg of storage was a crazy amount.

We can do better. Intel pushed us backwards, Forth would be a step forwards, but man, I'd take python or Tcl (because then I'd get my pet language L, http://little-lang.org) or even perl as a better boot language.

Froth has no special boot sauce in my opinion. It was just small.

Re:The Oforth Programming Language by lukego on Wednesday March 28, 2018 @10:42AM (#16698023)
Speaking of Lisp and Forth, I was really stunned when I noticed that adding syntactic support for "structs" in the language is about 10 lines in Forth (https://github.com/openbios/openfirmware/blob/master/forth/l...) and about 2000 lines in Lisp (https://github.com/sbcl/sbcl/blob/master/src/code/defstruct....).

Mitch Bradley wrote up an explanation of the Forth library, and lots of other cool bits of Openfirmware, at http://wiki.laptop.org/go/Forth_Lesson_18.

Re:The Oforth Programming Language by kazinator on Thursday March 29, 2018 @09:53PM (#16713010)
You could also make some ten line hack to mock up structs in Lisp over a vector. That SBCL implementation has to conform to an ANSI standard.

The TXR Lisp implementation of structs (the syntactic part) is 300 Lines: http://www.kylheku.com/cgit/txr/tree/share/txr/stdlib/struct... of which the defstruct macro is about half.

The underlying implementation is in C: http://www.kylheku.com/cgit/txr/tree/struct.c, which is some 1600 lines.

TXR Lisp structs are an OOP system; they support inheritance, static and instance slots, inheritance of both, late injection of methods into a hierarchy and such. There is a fairly sophisticated initialization model and even support for C++-like RAII style.

Structs are real objects that know their own type. They have a print and read representation, they know what slots they have and will reject invalid accesses and so on.

You don't get something for nothing; the LOC's are spent for a reason.

Looks like there is a tutorial on what appear to be these same Forth structs here: http://wiki.laptop.org/go/Forth_Lesson_18

I don't see any example of how to create a struct, how to access it, how to show that two different struct types are incompatible, how accessing a field in a struct that it doesn't have results in an error, etc. It just looks like definitions of constants denoting offsets.

Re:The Oforth Programming Language by zeveb on Wednesday March 28, 2018 @10:00AM (#16697660)
The real special sauce for Forth is that it's small and it's knowable. Anyone who wants to learn about how elegant a computer system can be should take a look at jonesforth[0], a Forth implemented in x86 assembly language. It really is possible for a programmer to easily understand everything a Forth does, which is wonderful when writing a bootloader or low-level OS.

In a lot of ways, it's a more-structured assembly language.

TCL could be cool for a low-level system too, as could be a Lisp (also: how can anyone hate Lisp with a passion‽‽‽), as of course could be Forth. Perl & Python are too big and not minimal enough.

0: https://github.com/nornagon/jonesforth/blob/master/jonesfort...

Re:The Oforth Programming Language by luckydude on Wednesday March 28, 2018 @10:12AM (#16697758)
I tried to like lisp, it just doesn't fit with my brain, dunno why. I tried to like emacs and it doesn't fit either. I'm a C/sh/vi sort of guy. I like troff, don't care for LaTex. Some stuff just works better for me, working in C comes very naturally to me, working in lisp was always a struggle.

I think if I had done more compiler work I'd like lisp better, I've been told that making an AST in lisp is trivial and it is work in C.

I get your point about small and knowable, I love stuff like that.

Re:The Oforth Programming Language by kazinator on Thursday March 29, 2018 @10:08PM (#16713103)
Much larger things are perfectly knowable; you just need a more capacious noodle.
Re:The Oforth Programming Language by jacobush on Wednesday March 28, 2018 @03:45AM (#16696135)
The special sauce was that it was tiny, that was not only important, it was imperative back when EPROMs ruled the motherboards and the backplanes. It was only until the serial flash memory arrived that bloaty alternatives became possible at all.
Re:The Oforth Programming Language by dang on Friday March 30, 2018 @05:08PM (#16719808)
The comment was deleted because its author deleted it. That's what 'deleted' means on HN.

I agree that it was a good reply!

Re:The Oforth Programming Language by luckydude on Wednesday March 28, 2018 @12:31AM (#16695300)
I do wonder why someone at HN decided that to stomp on the guy who was asking about forth as bootloader. Didn't seem weird at all to me. HN? Care to explain? Did I miss something?
Re:The Oforth Programming Language by dang on Friday March 30, 2018 @05:07PM (#16719799)
As I explained at https://news.ycombinator.com/item?id=16719808, no one at HN touched the comment. It's deleted because the person who wrote it chose to delete it. Why? No idea. You'd have to ask them.
Re:The Oforth Programming Language by exikyut on Saturday March 31, 2018 @05:35AM (#16722551)
That raises a tricky (perhaps philosophical-meta) question: whether deleted questions should keep the username visible.

I can't ask the person who deleted the question, because I don't know who they were.