Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Formulas to Database #283

Open
berkdemir opened this issue Mar 4, 2024 · 7 comments
Open

Custom Formulas to Database #283

berkdemir opened this issue Mar 4, 2024 · 7 comments

Comments

@berkdemir
Copy link

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
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@Proektsoftbg
Copy link
Owner

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
Copy link
Author

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:

  • myfunctions.cpd has namespace_1 with f1, f2 and f3.
  • If user include namespace_1, it should get f1, f2 and f3.
  • If user include f1, it should also be able to get the f1.
  • If there is another function named namespace_1 somehow, it should get the last item in the cpd.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants