Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
X# examples - Finger prints
Message
From
02/11/2019 02:09:23
 
 
To
01/11/2019 06:51:53
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
VFP Compiler for .NET
Miscellaneous
Thread ID:
01671748
Message ID:
01671776
Views:
44
Hi Dragan,
>Talking about readability, this is very confusing.
Yes it confused me too in the beginning...
>LOCAL Hello as SayHello
>What, a variable is declared as a function? And actually just a declaration, because the function doesn't exist. And it's not even a function class, it's a dummy. Next it doesn't say FUNCTION French() AS SayHello, but "as string". Then
>Hello = English
Yes the compiler is clever enough to understand that DELEGATE is a Type and hence can be used as an assignment type. It returns a string hence our SayHello will also returns a string.

>variable is assigned a function (!).

Yes it is a variable that holds a pointer to a function.

> How would that name translate into one of those function names? Would you have to write a long case statement with
>case method="m01"
> CalcFn=method01

No, you would first create a DELEGATE to declare parameters and return value
DELEGATE InterestCalc(rStart AS REAL4, rInt AS REAL4, nPeriods AS INT) AS REAL4

FUNCTION Compound(rStart AS REAL4, rInt AS REAL4, nPeriods AS INT) AS REAL4
RETURN nStart * (1.0 + rInt/12.0) ^ nPeriods

FUNCTION Straight(rStart AS REAL4, rInt AS REAL4, nPeriods AS INT) AS REAL4
RETURN nStart * (1.0 + rInt / 12) * nPeriods

LOCAL myCalc AS InterestCalc
&& Then yes we have to tell it which calc to use
SWITCH intType
  CASE Compound
    myCalc = Compound && Note the address of Compound is stored in myCalc
  CASE Straight
    myCalc = Straight
END SWITCH
&& We can now even pass this around as a parameter
SomeOtherFunction(myCalc)

FUNCTION SomeOtherFunction(calc AS InterestCalc) AS VOID
  ? calc(100.0, 10.0, 36)
RETURN
>Keep in mind that in fox I could simply add a method99.prg and store "m99" in the contracts table without even recompiling the project - just existence of

Yes because fox is an interpretive language, X# also have macro substitution, and also add something called a codeblock that can be runtime compiled. It is very similar to delegates, but late bound. That is however a discussion on its own.

>You can see how this can look confusing for native foxen who don't speak .net - and such things were mostly the reason I still don't speak it :).

Indeed, but just wanted to show some of the new features that X# brings to the table, love it or hate it, it is there to be used...
Johan Nel
George, South Africa
Friend of XSharp (FOX) member
E-mail : johan(dot)nel(at)xsinet(dot)co(dot)za
Web site : https://xsharp.info
X# runtime : https://github.com/X-Sharp/XSharpPublic
Radio talk : https://blog.aksel.com/2019/07/why-xsharp-might-be-tool-foxpro.html
Previous
Reply
Map
View

Click here to load this message in the networking platform