-- Leo's gemini proxy

-- Connecting to freeshell.de:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=en-GB

Expressing operations and psychology ➕

Addition needs two numbers as arguments. How can we express that? Lots of ways, sadly.

n1 + n2     # infix operator
+ n1 n2     # prefix (Polish)
n1 n2 +     # postfix (reverse Polish)
add(n1,n2)  # function style
n1.add(n2)  # object method call

I complained about stack manipulation in Whitespace and Forth, but maybe that's only because I'm so used to infix operators. Postfix means you're using a stack of values. Perhaps prefix would seem easier. The only language I know of that's like that is Lisp, but I did once implement it as a formula "language" in a (very simple) spreadheet app. There's still a stack, but it's the other way around. Instead of values stacked up waiting for operations, there are operations and values waiting until the top-most operation has enough params. For some reason this isn't making my head hurt so much. Maybe my problem is that the postfix stack is just a bunch of values waiting for... what? You can't look at the stack and see anything meaningful. Two values waiting for addition look just like two values waiting for subtraction. And umpteen values looks like a mess. The right number of operations might well be applied to use up all those values, but there's no way of knowing that by looking at the stack. In the prefix case, a stack of operations has a bunch of meaning in it, and I can see how many values it's waiting for so it can do its thing.


So if I like prefix notation, perhaps I should go and learn Lisp.

Again.

I've had a couple of goes. I even once contributed a Lisp example to rosettacode.org. But the language didn't grab me enough that I wanted to use it to write something useful. To make any progress I'll need to spend less time on Whitespace, which I'm still enjoying. Well, at least thinking about lists has made me implement some list handling in Whitespace.


#programming


back to gemlog

-- Response ended

-- Page fetched on Sat Sep 21 01:05:11 2024