Load/import functions/constant from a file instead of redefining them everytime.; Edit: Changed to QnA #69
-
There could be some functions/constant you probably add again and again in calc whenever you use it. So, it would be better if you could just import them from a file... Like, in my case i have to define some functions again and again which are very useful to me, examples:
so it wold be really cool if you we could have a file like <filename.calc> and a basic import function like: import(<filename.calc>) and it would just load/import all the constants and function from that file... the structure of file would be exactly how u think it should be:
there could be field for pub/priv too ig,, (idk i am poor at designing/explaining) but u prolly got the point |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Thank you for suggestion, @BilakshanP, before we considered in more detail, we want to be sure you're aware of existing capabilities within calc. There is a calc startup file that is automatically processed when calc starts (unless you give a The calc startup file is controlled by the $CALCRC environment variable, which it is does exist will mean that the file Let's assume you have a For example, you could set change display and default precision when calc start by adding these to your
Now you may not want those commands to spew out details of every time calc starts. There are ways to silence them. For example instead of saying adding to your calcrc file: You could instead add:
Similarly, when you define functions, you can set a configuration state to not print the fact that the functions to find and then unset it afterwards. I know some people prefer to know that functions are being define when calc is starting up and that's OK it'll do that automatically. I'm just pointing out you can disable that in various ways if you wish. Now, if you want to have some calc script or situation load commands when you type something, you could use the read command. Say you have those commands you listed above in the file "foo.cal". By entering into calc:
They will be "imported" as you say. You can even put that command into another file, that when executed will read ("import") those commands as well. Some people like to use the
maybe be what you want to do. You mentioned that you wanted:
You could create a "physics.cal" file containing various constants and load them into your calc session by:
Again, you might want to silence variable settings by using in "physics.cal" commands of the form such as:
You could even add to your calc startup file:
to always have them. You mentioned that you wanted to do:
Did you know that calc now has built in functions such as
See the help command in calc for details:
For a complete list of calc buildin functions:
For more information on things like the environment variable $CALCRC, see:
For help on the above mentioned read command (and other useful commands) see:
For help with help, including some ideas of other things you can get help on, try:
See also the calc man page. You could even define your own sine in degrees function such as:
And, of course, you can put that in your calc start up file We hope this helps. If there are additional request or concerns or something that you didn't quite understand or something else related to your original request, please follow up with a comment. |
Beta Was this translation helpful? Give feedback.
Thank you for suggestion, @BilakshanP, before we considered in more detail, we want to be sure you're aware of existing capabilities within calc.
There is a calc startup file that is automatically processed when calc starts (unless you give a
-q
to the calc command line). See the calc man page for details.The calc startup file is controlled by the $CALCRC environment variable, which it is does exist will mean that the file
.calcrc
will be searched for along a path. People usually put a.calcrc
file in their home directory for a general purpose, although you may have a.calcrc
file in your local directory that will take priority.Let's assume you have a
~/.calcrc
file (in your home direct…