Page 2 of 3
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 11:21 am
by FoxProMatt
This discussion is good, letting me see all the things I was NOT thinking about.
I'm anxious to get the basic VFP functions working soon so that when an old VFP dog learns about X# and they do give it a try but the basic functions are not yet implemented, if will be a big let down for them, and they will there badly of VFP.
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 11:21 am
by atlopes
Matt,
If X# supports empty dates and datetimes (I'm not working with the machine where I have X# installed right now, so I can't verify this), then YEAR(someDate) or YEAR(someDatetime) should return 0 in case of emptiness.
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 11:25 am
by Zdeněk Krejčí
Is it possible to use generics like c#?
Zdeněk
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 11:39 am
by lumberjack
Zdeněk Krejčí wrote:Is it possible to use generics like c#?
Zdeněk
Yes!
Code: Select all
LOCAL x AS List<String>
x := List<String>{}
x:Add("abc")
x:Add(123) // Error at compile time
You can also define your own generic classes.
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 12:07 pm
by FoxProMatt
lumberjack - He's talking about using generics to implement EVL().
Let's not take this thread off on a tangent with code examples of new X# programming examples. X# must implement the EVL() function as-written without users having to change their code, so that's what I want to stay focused on here in this thread.
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 1:37 pm
by mainhatten
Hi Antonio,
atlopes wrote:In VFP, in general, any function that accepts a .NULL. for one of its arguments returns .NULL. as a result.
...
Obvious exceptions are NVL(), ISNULL(), and VARTYPE().
"most" would be better. There are string functions not following that rule, but they are few - I had mentioned that missing Nullcheck in xSharp quite a while back. Uncertain if those should be implemented only in vfp dialect calling base implementation, base implementation needs to be enhanced or new implementation (for 1-3 liners, cutting out method call) are appropriate. Will check when new version is available to non-FoXers and if not done perhaps do it in 1 swoop for those I calling my attention early on.
regards
thomas
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 1:41 pm
by mainhatten
Hi Robert,
robert wrote:The string type in .Net has a Chars property which is an indexable collection of characters in the string. No allocation is needed as far as I know to address individual characters .
The string class is written in CPP:
You can see here that it simply indexes the character in the buffer
https://github.com/dotnet/coreclr/blob/ ... ve.cpp#L52
interesting - might speed up my GetWord* functions if not already tweaked by Chris or you.
regards
thomas
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 2:18 pm
by Zdeněk Krejčí
Code: Select all
FUNCTION EVL(eExpression1 AS USUAL, eExpression2 AS <T>) AS USUAL
If IsEmpty(eExpression1)
Return eExpression2
Endif
Return eExpression1
....
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 2:23 pm
by robert
Zdenek,
What would the benefit of this be over
FUNCTION EVL(eExpression1 AS USUAL, eExpression2 AS USUAL) AS USUAL
If IsEmpty(eExpression1)
Return eExpression2
Endif
Return eExpression1
Robert
Let's write the EVL() function for X#...
Posted: Fri May 08, 2020 4:06 pm
by atlopes
Robert
The string type in .Net has a Chars property which is an indexable collection of characters in the string. No allocation is needed as far as I know to address individual characters .
I've been trying this for a bit in the context of Matt EVL() draft. I'm probably missing something, but since Chars is a String collection, this won't work until a) we create a new string from the Usual parameter, and thus facing a string replication problem again; or b) we have a different implementation of the EVL() function for strings.
Code for option a)
Code: Select all
Case dataType == "C"
LOCAL emptyChars = " " + CHR(9) + CHR(10) + CHR(13) AS String
LOCAL testString = uValue.ToString() AS String
FOR VAR idx = 0 TO testString.Length - 1
If (emptyChars.IndexOf(testString.Chars[idx]) == -1)
Return uValue
Endif
NEXT
Return uReturnValue
Code for option b)
Code: Select all
Function Evl (sValue AS String, uReturnValue)
LOCAL emptyChars = " " + CHR(9) + CHR(10) + CHR(13) AS String
FOR VAR idx = 0 TO sValue.Length - 1
If (emptyChars.IndexOf(sValue.Chars[idx]) == -1)
Return sValue
Endif
NEXT
Return uReturnValue
End Function
Handling of .NULL. seems a problem, really, and appearing in various places, as Thomas mentioned. I found out that I can't even issue
without raising an error.