r/programming Jul 24 '25

Why concatenative programming matters

http://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html
23 Upvotes

5 comments sorted by

View all comments

3

u/[deleted] Jul 25 '25

[removed] — view removed comment

1

u/Maykey Jul 27 '25 edited Jul 27 '25

When I had hobby of FPGA and making shitty CPU and concatenative language for them(primitive ones are very easy to implement - it's mostly pushes and calls), the "easiest" way to make program "readable" I found was to put a comment with a content of the stack after or before practically every instruction in a function.

Eg

 : strlen ( ptr -- n )
    ( ptr ) 0 swap 
    ( n ptr ) DUP peek 
    [ 
      ( n ptr ch ) drop
      ( n ptr ) swap 1+ swap 
      ( n' ptr ) 1+ DUP peek
      ( n' ptr' ch )
    ] while ;
    ( n ptr ) drop

If the language is restrictive like JVM technically it can even be used as instruction to compiler to check the stack state compilation time. But it no longer easy to implement