Proektsoftbg / Calcpad

Free and open source software for mathematical and engineering calculations.
https://calcpad.eu
MIT License
313 stars 38 forks source link

Custom Formulas to Database #283

Open berkdemir opened 2 months ago

berkdemir commented 2 months ago

Hi, For my usual functions, I created a formulas.cpd, and when I need it, I copy from there. Is there a better way for this, such as saving my formulas to Calcpad's own database, so I can use them by default?

marcostrmuniz commented 2 months ago

This is something I was thinking about requesting. We could have a pre-established folder so we could place several *.cpd files in it. And just type #include filename.cpd for any new project.

Proektsoftbg commented 2 months ago

You can also write the full path instead of just filename, like

include c:\Users\Ned\Documents\Calcpad\formulas.cpd

Then, you will not need to copy the file each time. However, we can consider implementing something like environmental variables, say set PATH = c:\Users\Ned\Documents\Calcpad and then #include PATH\formulas.cpd

berkdemir commented 2 months ago

To be honest, I don't like the #include function, since it takes everything inside the file. Because, in my formulas.cpd file, I have maybe 20 common formulas I use. But, for the sheet that I am preparing, I want to "import" only one of them. So, that's why I asked if we can have a injection point to the native database of Calcpad. For example, you can have one file called user_functions in Documents, and any formula that we write there is automatically imported to Calcpad, and we can call those functions natively. It should overwrite any existing functions, if the user mistakenly chooses same function name.

Proektsoftbg commented 2 months ago

Hi!

But what if I do not want to import them of some worksheet? Or I need only some of them? What saves me to not write: #include user_functions.cpd and always import it on startup. Is it even worse than that?

Probably what you need is something like in Python: #include mysin from user_functions.cpd

I also do not understand what is "injection point to the native database of Calcpad". Calcpad native functions are written in c# and they are part of the Calcpad code. Nothing can be "injected" there from outside.

berkdemir commented 2 months ago

Include x from y seems like a good solution, in that case.

Proektsoftbg commented 2 months ago

Or maybe we can even introduce namespaces like @cser proposed some time ago. (I do not know where this guy disappeared, but he had a lot of good ideas.)

Say, we have myfunctions.cpd and inside:

#namespace functions1
...
#end namespace

#namespace functions2
...
#end namespace

In your main file, then you can write: #include functions1 from myfunctions.cpd

Namespaces will give you freedom to include one or group of related functions by your choice. We can even make difference between functions with equal names from different namespaces by calling:

functions1::func(x)
functions2::func(x)

What do your think?

berkdemir commented 2 months ago

It might definitely have some use cases to import a bunch of functions. But importing one function has also use cases. I think we should do the following:

I think namespace might need some work from your side, maybe we can start with importing functions first.