Re:Clac – A command-line, stack-based calculator with postfi...
by klodolph on Thursday April 13, 2017 @01:36PM
(#14109131)
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.
Re:Clac – A command-line, stack-based calculator with postfi...
by protomyth on Thursday April 13, 2017 @02:11PM
(#14109477)
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 postfi...
by soveran on Thursday April 13, 2017 @02:20PM
(#14109567)
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 postfi...
by protomyth on Thursday April 13, 2017 @03:34PM
(#14110243)
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.
Re:Clac – A command-line, stack-based calculator with postfi...
by eridius on Thursday April 13, 2017 @08:25PM
(#14111844)
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 postfi...
by auxym on Thursday April 13, 2017 @06:45PM
(#14111440)
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.
Re:Clac – A command-line, stack-based calculator with postfi...
by Animats on Thursday April 13, 2017 @03:48PM
(#14110338)
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 postfi...
by wrycoder on Thursday April 13, 2017 @07:06PM
(#14111538)
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 postfi...
by GilbertErik on Thursday April 13, 2017 @02:21PM
(#14109578)
If I need to see what's going on, I've relied on orpie for quite a long time. I like soveran's video showing off what it does, but I'd rather manipulate a stack rather than have the output appended to the end of my cursor.
Re:Clac – A command-line, stack-based calculator with postfi...
by pkd on Thursday April 13, 2017 @01:16PM
(#14108957)
I did this as part of my data structures course at University! Good exercise, but obviously mine lacked the swap, dup features etc. Instead I had min and max implemented.
Re:Clac – A command-line, stack-based calculator with postfi...
by lexpar on Thursday April 13, 2017 @01:41PM
(#14109178)
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.
Re:Clac – A command-line, stack-based calculator with postfi...
by soveran on Thursday April 13, 2017 @02:09PM
(#14109466)
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: http://files.soveran.com/misc/clac.mov
Re:Clac – A command-line, stack-based calculator with postfi...
by undershirt on Thursday April 13, 2017 @02:49PM
(#14109825)
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 postfi...
by lexpar on Monday April 24, 2017 @03:34PM
(#14187347)
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.
Re:Clac – A command-line, stack-based calculator with postfi...
by mannigfaltig on Thursday April 13, 2017 @05:13PM
(#14110967)
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 postfi...
by mwfunk on Thursday April 13, 2017 @06:33PM
(#14111385)
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 postfi...
by sevensor on Thursday April 13, 2017 @02:01PM
(#14109392)
Likewise, I don't see this replacing dc for me. The exciting thing is really the suggestion to consider what it would take to implement your own dc. Reimplementing dc was never an assignment I saw as a student, so I think it's valuable to point out that it's an interesting exercise.
Re:Clac – A command-line, stack-based calculator with postfi...
by mccv on Thursday April 13, 2017 @02:01PM
(#14109391)
dc exists, and is great for quick shell script math. As an interactive calculator REPL it is... not the greatest. Having the stack represented on the right gets closer to the HP 48 experience.
Re:Clac – A command-line, stack-based calculator with postfi...
by lutusp on Thursday April 13, 2017 @02:15PM
(#14109519)
> 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.
It was written in B before the C programming language was created.
Is there a command line Forth interpreter out there that can save words or load a startup dictionary each use?
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.
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
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/
[1]: https://en.wikipedia.org/wiki/Bc_(programming_language)
[2]: https://unix.stackexchange.com/questions/124518/how-is-bc-di...
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.
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: http://files.soveran.com/misc/clac.mov
To make this clear, I would upload your video to gfycat and link the gif in your readme.
You guys are right, I didn't realise it was this cool, and I was too quick to be cynical.
Nostalgia.
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.