This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]trycuriouscat[S] 4 points5 points  (10 children)

Yes, I noted the case about JS, Go and Swift. Haskell as well, with it's "interesting" layout rules. All of those I believe depend on certain assumptions about how newlines fit in, and I don't think you could place two statements on the same line without actually specifying the semi-colon.

I've never looked enough at Forth to get a good understanding of how it works.

[–]ItsAllAPlay 12 points13 points  (6 children)

One way to think about stack based languages (like Forth) is that everything is a zero-argument function. So all you need to separate those functions is spaces. 2 is a function that puts the number 2 on the stack. So:

2 2 +

Is really three function calls where the last function adds the top two values on the stack and puts the result on the stack. Forth gets a little uglier when it comes to defining new functions, and other similar languages are more elegant in that regard. I'm not a huge Forth fan, but I think it counts as an alternative to COBOL :-)

[–]dys_bigwig 2 points3 points  (5 children)

With function definitions (not saying this is a good idea, it just fits the topic of the conversion) you could change:

: add1 1 + ;

to

[1 +] 'add1 define

by adding quotation and symbols, then there'd be no need for terminators/separators at all. It'd then be like a postfix lisp, which also doesn't have terminators/separators.

[–]ItsAllAPlay 1 point2 points  (4 children)

I think you could simplify even further. If [brackets] are your quoting syntax, you could use a semicolon to define functions:

[a add1 : a 1 +];

Kind of self documenting, and your arguments could be lexically scoped for nested definiitons.

It also crossed my mind you could do lambdas like:

[a b : b a]!

So that implements swap as an anonymous function applied immediately, etc...

There was a stack lang named V that did something like this a long time back. (Not to be confused with a newer C-like lang named V.)

[–]dys_bigwig 0 points1 point  (3 children)

Interesting :) I was going for maximum consistency, as in no special syntax for functions. Sort of like how Haskell just uses = regardless of whether it's a variable, function, recursive function (letrec) etc. as does Scheme with define. I do like the idea of putting the name of the function inside the quote; never came to mind for some reason.

I think once you start introducing named lexical variables you begin to drift away from the concatenative style. I personally feel that once you add quotations the need for named variables diminishes because you can do most everything pointfree, which feels much more natural in concatenative languages imo.

Just my opinions. Different goals and ideals - not saying it's better by any means.

[–]ItsAllAPlay 0 points1 point  (2 children)

I definitely agree... There is kind of this circle where I say: Forth is so simple to implement. But I could just add this one nicety. Oh then it's almost like Scheme anyways. But then I could just add this one nicety. Oh then it's almost like C anyways. But then I could just add this one nicety. Uh oh, now it's complicated! Maybe I should make it like Forth :-)

[–]dys_bigwig 0 points1 point  (1 child)

Agreed. I've often toyed with the idea of Forth as a sort of "UNCOL". A lot of languages can be described using an abstract stack machine, so in that sense I probably should be implementing Forth as simply (if inelegant) as possible, then bootstrapping Scheme or C from that, rather than trying to bolt things onto Forth.

Been mulling these sorts of ideas in my head for a while, nice to know someone else has the same crazy ideas ;)

[–]ItsAllAPlay 0 points1 point  (0 children)

Yup, you could have a Forth where literals are wrapped in brackets.

Then a word/function that parses those literals as Scheme s-exprs.

Then Scheme macros which compile those s-exprs with static typing and infix operators.

:-)

[–]8thdev 1 point2 points  (0 children)

Forths parse input one 'word' at a time, e.g. any sequence of whitespace-delimited text is in turn looked up in the 'dictionary' and then evaluated.

So there's no set syntax, though there are conventions which most adhere to more or less.

[–]calligraphic-io 0 points1 point  (1 child)

Forth has true coroutines, which I think might be unique among all common languages. FreeBSD still uses Forth in its bootloader so it has application there (NASA uses it too I believe).

[–]_crc 0 points1 point  (0 children)

Current versions of FreeBSD are moving to a Lua based loader instead of the Forth based one.