Live data from Hacker News

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

github.com

11–20 of 29 posts

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

#11
Nice. I did one in Perl a long while back. I added sum to sum the contents of the stack (good for bill paying day) and pt for Pythagorean theorem because I was doing a lot of cable distances.

Is there a command line Forth interpreter out there that can save words or load a startup dictionary each use?

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

#12
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.

> I just don't understand why the author would think this is something worth showing off.

There's a large class of people who can be relied on to see this as a noteworthy accomplishment -- students. More experienced hands will note the absence of range checking and error trapping.

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

#13

Nice. I did one in Perl a long while back. I added sum to sum the contents of the stack (good for bill paying day) and pt for Pythagorean theorem because I was doing a lot of cable distances. Is there a command line Forth interpreter out there that can save words or load a startup dictionary each use?

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.

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

#15
post #10
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.

I'm not the author of the post, I just wrote the tool. I agree with you that it's not groundbreaking technology :-) In fact, the code is extremely simple. As I mentioned in the README, I've used dc a lot and what I propose with clac is an improvement (for my taste) regarding the UI, as there's an always-visible representation of the stack that gets updated as you type. I recorded a short video to show it in action: h…

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.

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

#16
post #13

Nice. I did one in Perl a long while back. I added sum to sum the contents of the stack (good for bill paying day) and pt for Pythagorean theorem because I was doing a lot of cable distances. Is there a command line Forth interpreter out there that can save words or load a startup dictionary each use?

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

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

#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.

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

#19
post #10

Earlier quoted context omitted.

I'm not the author of the post, I just wrote the tool. I agree with you that it's not groundbreaking technology :-) In fact, the code is extremely simple. As I mentioned in the README, I've used dc a lot and what I propose with clac is an improvement (for my taste) regarding the UI, as there's an always-visible representation of the stack that gets updated as you type. I recorded a short video to show it in action: h…

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!

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

#20
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.
Post reply on HN