Arc Forumnew | comments | leaders | submitlogin
My new app: a postfix language and its live-updating text-mode environment (archive.org)
5 points by akkartik 1502 days ago | 11 comments


2 points by zck 1501 days ago | link

Super interesting! I like how you can zoom into the system, almost like using a microscope to see how code works.

One thing that isn't quite clear from your examples here (and maybe that wasn't the point, but I am wondering): why have a different stack when a function is called? Your examples would work fine if they used the same stack. That is, if functions used the same stack, `1+` could be defined as `1 +`.

Perhaps it would be more clear if an example used two variables, or used the same variable twice.

-----

3 points by akkartik 1500 days ago | link

That's a great point. As I've built this, the keystone example in my mind has been the `square` function:

    x square = x x *
So it's really funny that I haven't added it yet. Now added.

-----

2 points by zck 1500 days ago | link

Nice!

Is it that you're trying to reduce stack juggling? That's hard to understand from simple examples (that you need to have to grok the syntax). Maybe compare something like finding the hypotenuse of a right triangle given the two other sides. Without naming arguments, you'd have to do something like:

  hypot = dup * swap dup * + sqrt
But with named arguments:

  hypot x y = x x * y y * + sqrt
That seems a little easier to read, but even the original isn't so complicated. Is there an example that makes it more obvious why it's better? Even your `square` example is more tokens than with stack juggling (without arguments, `square = dup *` is just four tokens, compared to six with named arguments). I'd say the with-arguments one is easier to read, but I've far less familiar with stack-based postfix programming.

-----

2 points by akkartik 1500 days ago | link

Yeah, some other polynomial might be a better example. The Pythagorean formula has a clean separation when it comes to which args each term uses. How about the roots of a quadratic equation when you start out with a, b and c on the stack?

-----

2 points by zck 1500 days ago | link

Yes, that is definitely simpler, although the formula is more esoteric. At least, for me, it triggers the "I was taught this in school and haven't used it since" filter.

Maybe something like:

  total-price cost-per-item number-of-items shipping-cost-per-item rush-cost = cost-per-item number-of-items * shipping-cost-per-item number-of-items * + rush-cost +
This doesn't seem super great; it could be refactored to use each thing once, but it's late and I can't think of any better example.

-----

2 points by akkartik 1500 days ago | link

You're right that in general any such example can be refactored to reduce stack operations. That's even a fun game for many Forth programmers to play. (We lispers have our own equivalents.) But it usually makes the code less comprehensible, in my experience.

-----

3 points by jsgrahamus 1499 days ago | link

Very interesting. This would have made learning Forth easier!

-----

1 point by akkartik 1485 days ago | link

New 2-minute video: support for strings, arrays and file handles that starts to give this the feel of a shell language.

https://archive.org/details/akkartik-2min-2020-10-27

-----

2 points by rocketnia 1467 days ago | link

Did you build all these dialogue boxes yourself too? Very snazzy. :D

-----

2 points by akkartik 1465 days ago | link

https://github.com/akkartik/mu/blob/3d31467c0d/apps/tile/box... :D

-----

1 point by akkartik 1492 days ago | link

New 2-minute video: defining functions in this postfix language.

https://archive.org/details/akkartik-2min-20201020

-----