Skip to main content


So I had this idea a few days ago, which I likely do not have the computery words to explain properly, but it goes something like this:

So, #forth has this syntax to define words which is just a comment saying what goes in, and what comes out. And I was wondering if I could use this in conjunction with the actual body of the routine while counting how many items are expected at the end of the routine, and throwing a warning when it doesn't match.

Is it arity validator?

https://en.m.wikipedia.org/wiki/Arity
Unknown parent

Devine Lu Linvega
@eli_oat yeah it's not quite type checking, I don't think it has anything to do with types at all after all. It's .. honestly, I'm not sure what that is? is it related to proofing?
in reply to Devine Lu Linvega

Oh cool! I had a very, very similar thought for auto-checking something like these stack effect comments. But have in no way attempted to implement any of it yet.
in reply to ratfactor

@ratfactor Implementing a basic version of it that is not too smart is kind of easy, I can see it becoming very very convoluted very fast. I think I'll have "safe" routines which are 100% predictable unless tainted by self-modification, and basicaly dirty routines which are just too hard to figure out if they're actually stack balanced.
Unknown parent

mel :ms_coyote:
From their documentation:

"The optimizing compiler checks the stack effect declarations of words before they can be run. This ensures that words take exactly the number of inputs and outputs that the programmer declares in source.

Words that do not pass the stack checker are rejected and cannot be run, and so essentially this defines a very simple and permissive type system that nevertheless catches some invalid programs and enables compiler optimizations. "
in reply to Devine Lu Linvega

I mean, I would simply call this a form of typechecking, but arity validation or arity checking sounds like a good and specific way of describing it.
Unknown parent

Devine Lu Linvega
@mel I have to give it a try over the winter, I feel like I've toyed around with every other forth except that one. I've been using their wiki a lot, just never the actual language. I'll remedy this-
Unknown parent

Devine Lu Linvega
@mel Oh wow, what a gorgeous little thing. It'll make for a nice little pocket computer.

You'd have to make your own input method I think, will your lisp only be dealing with numbers and arithmetic? Or will it have named functions too?
Unknown parent

tired blip
@ratfactor
This transitive tagging is something I've reserved memory for in gluumy for "effects tracking" ("does anything in this call chain do IO?")
in reply to tired blip

@klardotsh @ratfactor So, @mel sent me this wonderful page, which you might wanna look through, you might already be familiar with it all, but if not, it's a very good breakdown of all the various types of inference.

Straight-line stack effects
Combinator stack effects
Recursive combinator stack effects
Branch stack effects

https://docs.factorcode.org/content/article-inference.html
Unknown parent

Devine Lu Linvega
@mel uxntal could be input entirely with a 16 key keyboard with two mod keys, and instead of words, I'd use http://wiki.xxiivv.com/site/uxntal_alphabet.html
Unknown parent

Devine Lu Linvega
@mel through no fault of yours, the wiki is a mess.
in reply to Devine Lu Linvega

#Forth Stack comments! They are indeed comments only. A Forth compiler could build validity checks using them, but I don't know of any that do.

vmgen, a sub-project of gforth, has a compiler that uses them in code generation.

https://www.complang.tuwien.ac.at/anton/vmgen/
in reply to Zorro Notorious MEB 😡

@AlgoCompSynth it turns out Factor does and it's really well handled too, it won't even let you build the program if it's not equivalent. It also runs through loops and recursion which is shown as a warning.

https://docs.factorcode.org/content/article-inference.html
in reply to Devine Lu Linvega

@mel ok for the opcodes but how would you input text ? I'm curious 😊
in reply to Devine Lu Linvega

It is arity. It's also what I've been adding for some of my #forth environments. I only implemented it as opt-in feature and used `::` instead of `:` to define such guarded words. The stack comments (e.g. `( a b c -- n )` for those words are then also mandatory and parsed to ensure behavior. Internally, `::` just defines a second hidden "normal" word of the main code, which is then wrapped with the pre & post guards based on the stack comment. Still wanted to experiment with adding types to that system, but even without it was already a vast improvement over "standard" Forth, esp. when sketching out code in the REPL... 👍
in reply to max22-

@maxime_andre @mel you mean label names? They'd have to be phonetics of the opcode or some other scheme like it, like little pictures or something.
in reply to Devine Lu Linvega

@mel i was thinking of strings, like how would you enter "hello world" ?
Unknown parent

⛧ esoterik ⛧
@AlgoCompSynth fwiw i don't think factor runs on the JVM (although i think a very old version of it did) @neauoire
in reply to ⛧ esoterik ⛧

@d6 I should check on that - maybe it was Joy that ran / runs on the JVM. But two interesting languages, Scala and Clojure, definitely got my veto for JVM dependency.
in reply to Devine Lu Linvega

@d6 Ah yes ... I should look at Joy some more. The Wikipedia description is intriguing.

https://en.wikipedia.org/wiki/Joy_(programming_language)

@d6 is right - Factor was originally on the JVM but isn't any more.

https://en.wikipedia.org/wiki/Joy_(programming_language)

But I still want a true interactive macro-assembler - a subroutine-threaded #Forth with inline CODE word capabilities.

Lo, thar be cookies on this site to keep track of your login. By clicking 'okay', you are CONSENTING to this.