What if Forth was written using Scheme S expressions? The result is a weird language that's kinda like Forth, but also a bit like Scheme. Hence why I am posting this in the Forth sub-forum. It would look like the code below, and be Forth from an alternate universe:
Code:
(define factorial
(lambda
(if (= dup 0) 1
(* dup (factorial (- dup 1))))))
So to make this crazy idea a reality I've been building a toy cross compiler written in Python that generates 6502 assembly. The language syntax uses Scheme S expressions, a data, and a return address stack. Here's my repo:
https://github.com/Martin-H1/TinyCompThe compiler will translate the code above into assembler like this:
Code:
factorial:
.scope
`dup
`pushi 0
jsr equals16
.scope
bne _else
`pushi 1
bra _endif
_else:
`dup
`dup
`pushi 1
jsr sub16
jsr factorial
jsr mul16
_endif:
.scend
rts
.scend
This code assumes the use of the Ophis assembler and my page zero stack macros, and 16 bit math functions. This is also in the really early stages and my never go anywhere. But I figured people here might be interested in the concept.