bjForth v0.0.3 is out! (github.com)
from bahmanm@lemmy.ml to programming@programming.dev on 29 Dec 00:03
https://lemmy.ml/post/24148184

I’m thrilled to announce the release of bjForth v0.0.3 🎉

There’s been a a heap of improvements and additions compared to the last release.

What’s best is that they are automatically tested every time a change is pushed 😎

I dare you to Grab the latest tarball and hack yourself some serious Forth 😄

#programming

threaded - newest

Azzu@lemm.ee on 29 Dec 01:55 collapse

Not knowing forth, why would you ever want this language?

bahmanm@lemmy.ml on 29 Dec 04:01 collapse

Besides the fun of stretching your mental muscles to think in a different paradigm, Forth is usually used in the embedded devices domain (like that of the earlier Mars rover I forgot the name of).

This project for me is mostly for the excitement and joy I get out of implementing a Forth (which is usually done in Assembler and C) on the JVM. While I managed to keep the semantics the same the underlying machinery is vastly different from, say, GForth. I find this quite a pleasing exercise.

Last but not least, if you like concatenative but were unable to practice fun on the JVM, bjForth may be what you’re looking for.

Hope this answers your question.

Azzu@lemm.ee on 29 Dec 09:53 collapse

It looks to me to be the same paradigm as pure functional languages, is this false? The only difference to lisp seems syntactic.

vext01@lemmy.sdf.org on 29 Dec 10:34 next collapse

Forth is stackier.

Azzu@lemm.ee on 29 Dec 10:43 collapse

Yeah that’s what I meant with syntactically. You could act as if in Lisp arguments to functions are pushing on the stack, and functions are removing them and pushing the result back.

bitcrafter@programming.dev on 29 Dec 20:10 collapse

In Forth, though, the number of results pushed to the stack after an execution of a word could be a function of the input rather than a single value or even a fixed number of values.

Likewise, the number of arguments that a word pops from the stack could be a function of a value pushed earlier to the stack.

Azzu@lemm.ee on 30 Dec 00:51 collapse

That’s what macros are and let you do in Lisp

bitcrafter@programming.dev on 30 Dec 01:34 collapse

Perhaps you could explain exactly what you mean?

Azzu@lemm.ee on 30 Dec 19:17 collapse

If you don’t know Lisp, it’d probably take too long for me explain (i.e. I don’t want to). Basically, macros let you rewrite your code arbitrarily, which would have the same effect as arbitrarily modifying the stack.

bitcrafter@programming.dev on 30 Dec 20:03 collapse

You are making the extremely incorrect presumption that I am unfamiliar with Lisp and how macros work. What is unclear to me is how you specifically think that arbitrarily rewriting code at macro expansion time is exactly equivalent to arbitrarily manipulating the stack at runtime.

Kacarott@aussie.zone on 29 Dec 11:10 next collapse

Forth is fairly different AFAIK. If you want a “Forth style” language for general purpose, with more “batteries included”, try Factor! It’s a really nice language.

bahmanm@lemmy.ml on 29 Dec 17:08 next collapse

Not really I’m afraid. Effects can be anywhere and they are not wrapped at all.

In technical terms it’s stack-oriented meaning the only way for functions (called “words”) to interact with each other is via a parameter stack.

Here’s an example:

: TIMES-10  ( x -- y )
  10 
  * 
;

12
TIMES-10
.S
120

TIMES-10 is a word which pops one parameter from stack and pushes the result of its calculation onto stack. The ( x – y) is a comment which conventionally documents the “stack effect” of the word.

Now when you type 12 and press RETURN, the integer 12 is pushed onto stack. Then TIMES-10 is called which in turn pushes 10 onto stack and invokes * which pops two values from stack and multiplies them and pushes the result onto stack.

That’s why when type .S to see the contents of the stack, you get 120 in response.

Another example is

5 10 20 - *
.S
50

This simple example demonstrates the reverse Polish notation (RPN) Forth uses. The arithmetic expression is equal to 5 * (20 - 10) the result of which is pushed onto stack.

PS: One of the strengths of Forth is the ability to build a vocabulary (of words) around a particular problem in bottom-to-top fashion, much like Lisp. PPS: If you’re ever interested to learn Forth, Starting Forth is a fantastic resource.

bitcrafter@programming.dev on 29 Dec 20:01 collapse

No. Roughly speaking, functional languages implicitly manage the stack for you, whereas Forth requires you to manage it explicitly.