Live data from Hacker News

Clac – A command-line, stack-based calculator with postfix notation

github.com

21–29 of 29 posts

Re: Clac – A command-line, stack-based calculator with postfix notation

#21
post #13

Earlier quoted context omitted.

That's interesting: commands that consume everything in the stack. About saving/loading words: I have plans to work on that, it could be a very useful feature.

Postscript had the concept of dropping a mark on the stack that allowed commands that would consume the whole stack to also stop at a mark if encountered. 5 4 mark 3 2 1 sum -> 5 4 6

I love the idea, thanks for the tip!

Re: Clac – A command-line, stack-based calculator with postfix notation

#22
post #5

I don't understand why things like this get posted to HN so often. This kind of program is a very common exercise in university courses and appears in countless programming books. Heck, you implemented it in C, and this exact exercise appears in K&R C. I hope this doesn't come off as snide... I just don't understand why the author would think this is something worth showing off.

Actually, the prospect of maybe, randomly getting to the front page of HN with some small interesting program is a nice motivator for small side projects. Overall it's probably a good thing introducing people to new concepts and ideas along the way (in this case Forth, post-fix notation and stack-based evaluation strategies).

Re: Clac – A command-line, stack-based calculator with postfix notation

#23
post #4

For those not familiar with "dc", try running dc and then running "7 100 ^ p". Arbitrary precision! One of the reasons dc doesn't print things out is so you can use it to do arithmetic in your shell scripts.

you can use $((5+5)) if you want to do arithmetic in a bash shell. Most of the time that's all that's needed.

But when it was written when there was no bash. Or even sh.

It was written in B before the C programming language was created.

Re: Clac – A command-line, stack-based calculator with postfix notation

#24
post #5

I don't understand why things like this get posted to HN so often. This kind of program is a very common exercise in university courses and appears in countless programming books. Heck, you implemented it in C, and this exact exercise appears in K&R C. I hope this doesn't come off as snide... I just don't understand why the author would think this is something worth showing off.

Sharing a side project, even a simple one, is hardly showing off. It would be showing off if he claimed it was some amazing earth-shattering new thing that's going to blow everyone's minds. On the other hand, being dismissive about its mundanity is clearly an attempt to show off.

Re: Clac – A command-line, stack-based calculator with postfix notation

#25
orpie has been my main calculator-on-the-pc for a while now. Curses based interface, written in OCaml, extensive library of scientific functions, configurable hotkeys. It's quite neat.

Unfortunately, the homepage seems to be down at the moment, but here's a freecode link. It's also packaged for most popular distros.

http://freecode.com/projects/orpie

Re: Clac – A command-line, stack-based calculator with postfix notation

#26
post #17

Surprisingly, postfix calculators fell out of fashion. I still have an original HP-11C on my desk. Students are now introduced to calculators that meet the "educational standard", that is, the TI-84 and its approved clones. That seems to have set what people expect in a calculator.

There is a great HP-41C for iOS: i41Cx. I believe it's the most expensive app I have, and it's worth every penny. I still have my HP-41, but I never drag it out because of this.

Re: Clac – A command-line, stack-based calculator with postfix notation

#27
When I saw the headline, I wondered what was so special about this. But actually reading the description, the UI sounds like a significant improvement in usability, such that I might actually consider using a postfix calculator like this.

On a side note, the description of arithmetic says that - and / swap the inputs, and it describes the operators as popping values a and b (and in the case of swap, then pushing a and b back on). This is a little confusing. It would be much simpler just to say that all binary operators pop values b and a. Now you don't have to swap anything, because - and / will still just perform a - b and a / b. And the fact that this swaps + and * is irrelevant, because those operators are commutative. And the swap operator makes more sense, because it "pops values b and a, and pushes values a and b", so you can now actually see the swapped values in the description.

Re: Clac – A command-line, stack-based calculator with postfix notation

#28
post #17

Surprisingly, postfix calculators fell out of fashion. I still have an original HP-11C on my desk. Students are now introduced to calculators that meet the "educational standard", that is, the TI-84 and its approved clones. That seems to have set what people expect in a calculator.

There is a great HP-41C for iOS: i41Cx. I believe it's the most expensive app I have, and it's worth every penny. I still have my HP-41, but I never drag it out because of this.

There's an open-source clone of the HP-42s that has found it's way into different smartphone apps.

I use Free42 for iOS and it works beautifully. Plus I can leave my real 42s safe in a drawer at home.

https://itunes.apple.com/us/app/free42/id337692629

There are other builds for Android, Windows, Mac, and Linux:

http://thomasokken.com/free42/

Re: Clac – A command-line, stack-based calculator with postfix notation

#29
post #19

Earlier quoted context omitted.

I just want to say great work. The parent comment here didn't realize that you drastically improved the user experience by showing the stack, which I think makes all the difference here. To make this clear, I would upload your video to gfycat and link the gif in your readme.

I just updated the README with a gif of that video. Thanks for the idea!

Just looked at the video, the 'as you type' updated stack info is actually pretty cool. I thought based on the description that it only printed the contents of the stack after a command was executed. This is much nicer.

You guys are right, I didn't realise it was this cool, and I was too quick to be cynical.

Post reply on HN