Why no Procedures in Residents
Why no Procedures in Residents
Hello,
in the light of my last question, AddElement() with an optional parameter to also assign a value to the new element, someone suggested to use residents for this. I now read what residents do and a bit how they work.
My question is, why can't I add procedures? It would be a good way to auto-add new functions without the use of include files.
in the light of my last question, AddElement() with an optional parameter to also assign a value to the new element, someone suggested to use residents for this. I now read what residents do and a bit how they work.
My question is, why can't I add procedures? It would be a good way to auto-add new functions without the use of include files.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Why no Procedures in Residents
I haven't tried Procedures, but you can definitely have macros in Residents files; I've done this before. So if your procedures are short non-complicated things, maybe try using them as resident Macros instead?
Re: Why no Procedures in Residents
The help explicitely states that procedures or dynamic code is not possible.
E.g. I want to include the Windows registry functions from ts-soft as native commands without having to always include the pbi-file. I thought I could do that with a resident, but that doesn't seem possible.
E.g. I want to include the Windows registry functions from ts-soft as native commands without having to always include the pbi-file. I thought I could do that with a resident, but that doesn't seem possible.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Why no Procedures in Residents
Dynamic code isn't possible? What do you mean? You can definitely use macros with passed parameters as resident, but maybe you don't mean that?
For example, this works just fine in a Resident file:
Then I can just run the following code without any IncludeFile, just as though Msg() was a native command:
For example, this works just fine in a Resident file:
Code: Select all
Macro Msg(text)
MessageRequester("Title",text)
EndMacro
Code: Select all
text$=InputRequester("Test","Enter some text:","")
Msg("Text was: "+text$) ; Text was dynamic, yes?
Re: Why no Procedures in Residents
I don't know, I just quoted the help file.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Why no Procedures in Residents
Dynamic code means it must be compiled.
Macros are text replacement only before compilation.
For procedures and prototypes, you need to consider dll. Static libs are not officially supported yet. Those would be cool.
Macros are text replacement only before compilation.
For procedures and prototypes, you need to consider dll. Static libs are not officially supported yet. Those would be cool.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Why no Procedures in Residents
I'm curious what "residents" are
Re: Why no Procedures in Residents
Thanks! seems useful
Re: Why no Procedures in Residents
Ok, so I tried to create a resident file from a function (ToFraction), which created a resident file, but id doesn't work. So the help is right, I cannot use procedures within residents. This is an unfortunate limitation, but due to my poor knowledge about this topic I can't complain. Maybe Fred can help out, it would be extra cool to be able to enhance the list of functions by useful functions that are always available without includes.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Why no Procedures in Residents
What's the function look like? I want to try it as a macro.
Re: Why no Procedures in Residents
Taken from this (http://forums.purebasic.com/german/view ... 77#p358136) thread and slightly changed:
This can't be changed into a macro. Also, even if, this wouldn't solve my problem (or say, do what I want to do).
Code: Select all
Procedure.s ToFraction (Double.d, MaxRelativeError.d=1e-6)
Protected.q LowNumerator = 0, LowDenominator = 1, HighNumerator = 1, HighDenominator, Numerator = 1, Denominator, Fraction, OldFraction, Factor, Iteration
Protected sign$
If IsNAN(Double) Or IsInfinity(Double)
ProcedureReturn StrD(double) ; NaN, +Infinity or -Infinity
EndIf
If Double < 0
Double = Abs(Double)
sign$ = "-"
EndIf
If Double > 1e16
ProcedureReturn "Overflow"
ElseIf Double < 1e-16
ProcedureReturn "Underflow"
EndIf
HighDenominator = Round(1/Double, #PB_Round_Down) - 1
Denominator = HighNumerator + HighDenominator
Fraction = Infinity()
Repeat
Iteration + 1
OldFraction = Fraction
Fraction = 1 - Double * Denominator / Numerator
; Debug "Iteration "+RSet(Str(Iteration),3)+": " + Str(Numerator) + " / " + Str(Denominator) + " ( δ = "+Fraction+" )"
Factor = Abs(Fraction) / (Abs(OldFraction) - Abs(Fraction))
If Factor < 1 Or Fraction > 0 Or OldFraction > 0
Factor = 1
EndIf
If Fraction < -MaxRelativeError ; zu klein
LowNumerator = Numerator
LowDenominator = Denominator
Numerator + Factor*HighNumerator
Denominator + Factor*HighDenominator
ElseIf Fraction > MaxRelativeError ; zu groß
HighNumerator = Numerator
HighDenominator = Denominator
Numerator + Factor*LowNumerator
Denominator + Factor*LowDenominator
Else
ProcedureReturn sign$ + Str(Numerator) + "/" + Str(Denominator)
EndIf
ForEver
EndProcedure
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Why no Procedures in Residents
Yeah, that's definitely not short and non-complicated.
It's not that hard to put a quick IncludeFile line in your code though? Looks like you're creating a lot of grief over a non-issue?
It's not that hard to put a quick IncludeFile line in your code though? Looks like you're creating a lot of grief over a non-issue?
Re: Why no Procedures in Residents
This may be. I have found a lot of useful, optimized and well working code found here and in some other places. I save them into pbi-files, to include it, like the Windows-Registry-include, my ListIconGadget-enhancements etc. Of course, I can include them into every project I want to, it would be just much more convenient to automatically have the functions available. It was just a thought, I know it can become complicated if one function calls another not-predefined function and so on. That's why I wanted to discuss and understand it.
I guess xincluding it isn't so inconvenient at all. I'm just lazy.
I guess xincluding it isn't so inconvenient at all. I'm just lazy.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Why no Procedures in Residents
When I wanted to solve this problem, the first thing that came to my mind was to use alternative auto-completion. That is, you use an abbreviation to insert "xinclude ...".