Let's write the EVL() function for X#...

This forum is meant for questions about the Visual FoxPro Language support in X#.

FoxProMatt

Let's write the EVL() function for X#...

Post 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.
atlopes
Posts: 83
Joined: Sat Sep 07, 2019 11:43 am
Location: Portugal

Let's write the EVL() function for X#...

Post 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.
User avatar
Zdeněk Krejčí
Posts: 19
Joined: Wed Sep 04, 2019 8:07 am

Let's write the EVL() function for X#...

Post by Zdeněk Krejčí »

Is it possible to use generics like c#?
Zdeněk
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Let's write the EVL() function for X#...

Post 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.
______________________
Johan Nel
Boshof, South Africa
FoxProMatt

Let's write the EVL() function for X#...

Post 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.
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

Let's write the EVL() function for X#...

Post 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
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

Let's write the EVL() function for X#...

Post 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
User avatar
Zdeněk Krejčí
Posts: 19
Joined: Wed Sep 04, 2019 8:07 am

Let's write the EVL() function for X#...

Post 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
....
User avatar
robert
Posts: 4522
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Let's write the EVL() function for X#...

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
atlopes
Posts: 83
Joined: Sat Sep 07, 2019 11:43 am
Location: Portugal

Let's write the EVL() function for X#...

Post 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

Code: Select all

? .NULL.
without raising an error.
Post Reply