Code Monkey home page Code Monkey logo

clac's People

Contributors

eloyesp avatar matthiasbeyer avatar soveran avatar srabuini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clac's Issues

Suggestion: Sci-Calc

Adding the basic functions for a scientific calculator would be great! Something along the lines of trig fn, logs. Anyways great setup for the calculator! As an engineer, these are functions I use on a regular basis.

Stack operator to roll top three values

Let's say I have two items on the stack

>  4 3

And I want to square the second number (3) and add that to the product of the two numbers (4,3). There's no obvious way to do this, you do something like this, and hit a wall (where the pipe indicates the division between input and the printed stack).

> 4 3 dup dup * | 4 3 9

There's no obvious way to solve this. If, however, we had a word (e.g. roll) that changes a b c to c a b, we could do this:

> 4 3 dup dup *          | 4 3 9
> 4 3 dup dup * roll     | 9 4 3
> 4 3 dup dup * roll *   | 9 12
> 4 3 dup dup * roll * + | 21  

Suggestion: Comments in words file

Hello, I have been using this program for a bit and I have noticed that the words file doesn't allow for comments. I think have some comments would useful even for a small words file.

Here's my proposal:

  • There would only be whole-line comments, where clac would just ignore the line if it starts with a comment character. Probably having inline comments wouldn't be that much harder, but given how simple this program is, I think it wouldn't be worth it.
  • The comment character would be the pound sign #, as in it is various UNIX(-like) shells, python, and various configuration languages.
  • Played a bit with the words file, it seems like "#" is already interpreted as just #, so I thinking there would be no need for any escape sequences here, just an update to the man page.

I'm not exactly the world's greatest C programmer, but I would be willing to try doing it if you think it's a reasonable idea.

Clarification in the docs

Hello again. While I was working on the stuff in #16 I noticed there is a point of confusion in the docs. Under the "commands" section it says "When a command requires an argument, it pops a value from the stack. If the stack is empty, a zero is provided instead."

This is not true for most of the commands; this is the internal behavior when pop is called on an empty stack, but most commands don't trigger that since they are guarded by if (count(s0) > ..) and the observed behavior is instead that the command becomes a noop. It is true for others, e.g. sum. This makes things a bit confusing and could probably stand to be clarified (or made consistent in the code if you prefer).

Again, nice project. It's been fun poking around and I appreciate how clean the code is.

postfix after number should work and not be "ignored"

3.5 8 *
= 28
3.5 8*
= 3.5

The latter format should work as well to

  • reduce typing effort and
  • prevent errors by overlooking the sane looking but erroneous result and possibly continue computation with that value

Add a tag or create release

It would be nice to have a tag/release so we could package this nice calculator in distributions (working on it for Arch).

Thanks !

Suggestion: Factorial function

Hello hello! This is a stupendous tool that's being made here, I like it a lot!

I would like to know if a factorial function would be acceptable for this tool. For most functions, I suspect defining words would be sufficient, but in the case of factorials, there's a bit more than just a one-run set of operations. If factorial is defined, I suspect that most other probability problems I would use this tool with could use words that utilize that factorial function.

I imagine the use case being something like the following:

> 9 !
= 362880

or

> 9 fact
= 362880

Again, thank you for this wonderful tool!

Suggestion: reduce need for spaces

I find it somewhat annoying that I have to write 3 4 * instead of 3 4*. I know that clac uses sdssplitargs(), which needs whitespace between tokens, and that any enhancement needs to be unambiguous for both the code and the user. I propose the following solution:
Every token output by sdssplitargs() is examined first in its entirety, as it is now, and then, if it's not recognized, it is split into a head and a tail in a loop, where the tail is 1, 2, 3... characters long, until the head is recognized (or until the head would be empty, in which case everything is discarded). As soon as the head is recognized, it is processed, and then the tail is handled in the same way (cyclically or recursively).
E.g., if the input is 2pi* (supposing pi is a word): it is not recognized, so 2pi is tried (the tail being *), then 2p (with tail i*) and then 2, which is recognized and processed. Then the tail pi* is not recognized, so that pi is tried, which is recognized and processed, and finally the tail * is recognized and processed.
In other words: tokens are parsed in a "greedy" way, with backtracking.

It's even better

Hello Michel!
I've looked at this project and found it even more clever than your map one.
Such a beautiful thing!
It's a pure UNIX philosophy I guess, so minimalistic and so functional programs.
Thanks for that!

Great Code

I just checked out your code, pretty good. But "switch " statement would be my choice if I am to match single length string. I noticed that you didn't check for zero denomination before division.

Segmentation fault for circular definition in words

Hi ,
I found that call stack overflow occurs when use a word defined circularly.

A word can define circularly like below.

a "a"

or It can be defined circularly with multiple words like below.

a "b"
b "c"
c "d"
d "a"

And program is terminated by segmentation fault when there is the word defined circularly in the expression.

$ clac "a"
Segmentation fault

Add more functions in `math.h`

So, wouldn't it make sense to simply implement all/most of the functions (and probably some of the constants) in math.h as primitives, since you're already using it? That should automatically give you most of the functions of a scientific calculator, plus the standard library implementations for those functions are very high quality. Having some of the standard unary operations like exp is also very convenient syntactically, because you can just do something like 5 3 exp * instead of 5 e 3 ^ * or 5 e 3 swap ^ * (I usually think in right to left order). At the very least more transcendental functions like atan and erf since you can't easily implement those in terms of other functions (and even if you could it's not a good idea because of numerical problems).

As another point regarding adding constants like e, pi etc., I feel like it'd make sense to just have those pre-loaded. It's not like anybody wants to customize the value of pi. Trying to add every obscure constant in existence isn't feasible, but the ones in math.h are already there and would be nice simply for numerical correctness.

I don't mind doing the legwork to add them, it's pretty easy. I already did exp, that was what motivated this. I'm interested in building a physical calculator using clac, hence the desire to make it a more complete scientific calculator.

This is relevant to issue #10.

0.3.2 build failure on macOS

==> Downloading https://github.com/soveran/clac/archive/0.3.2.tar.gz
Already downloaded: /Users/joe/Library/Caches/Homebrew/clac-0.3.2.tar.gz
==> Verifying clac-0.3.2.tar.gz checksum
tar xzf /Users/joe/Library/Caches/Homebrew/clac-0.3.2.tar.gz
==> make PREFIX=/usr/local/Cellar/clac/0.3.2 install
clang  -Wall -Os -g  -c linenoise.c
clang -o sds-test sds.c -Wall -std=c99 -pedantic -O2 -DSDS_TEST_MAIN
>>> Type ./sds-test to run the sds.c unit tests.
clang -I./deps/linenoise -I./deps/sds -Wall -Os -o clac clac.c -lm deps/linenoise/linenoise.o deps/sds/sds.o
clang: error: no such file or directory: 'deps/sds/sds.o'
make: *** [clac] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.