Documentation issues

This forum is meant for questions and discussions about the X# language and tools
User avatar
Kees Bouw
Posts: 183
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Documentation issues

Post by Kees Bouw »

Hi,

It could be just me not being able to find stuff, but there does not appear to be an explanation for the "AUTO" addition in the X# documentation. For example:

Code: Select all

PROPERTY FirstName AS STRING AUTO
I can find some places where it is mentioned, such as https://www.xsharp.eu/help/new-feat-initializers.html and https://www.xsharp.eu/help/command_property.html but not really an explanation. Maybe the meaning is so obvious that it does not need any explanation, in that case maybe someone can state the obvious for me :-)

Kees.
User avatar
robert
Posts: 5068
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Documentation issues

Post by robert »

Kees,
AUTO means that the compiler will AUTOmatically create a backing field for the property and the matching Getter and Setter.
I will check the docs and add a description.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 183
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Documentation issues

Post by Kees Bouw »

Thank you Robert.

Another thing. It is not really "the documentation" but still a valuable source of information: the docs.xsharp.it website. On the page https://docs.xsharp.it/doku.php?id=code ... e&s[]=auto is an example that does not work. There is a compilation error on the line "return nResult": "Error XS0126 An object of a type convertible to 'int' is required". Strange thing is of course that nResult is actually an INT. When I remove the LOCAL and do it as follows:

Code: Select all

oPersons:Sort( ;
    DELEGATE(o1 AS Person, o2 AS Person) {
    RETURN o1:Name:CompareTo(o2:Name)
    } ;
)
(Like a C# example on https://learn.microsoft.com/en-us/dotne ... w=net-10.0)
Then the same error is still there on the RETURN line. Another strange thing I noticed is the tooltip of the CompareTo method:

Image
Here it says "AS INT" but further down it says "Returns: A Logical value" (there is also a typo there). So could it be that the compiler thinks this method will return a logical instead of an int?

Kees.
User avatar
robert
Posts: 5068
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Documentation issues

Post by robert »

Kees,
The compiler knows that it is an int.
What you see in this tooltip is coming from the XSharp.RT.Xml file.
That file is generated from documentation comments, and is apparently not correct.

And w.r.t. that website: that website is maintained by Wolfgang. We have no control over that

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 183
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Documentation issues

Post by Kees Bouw »

Hi Robert,

If the compiler knows that CompareTo() returns an INT then I do not understand why I get a compilation error in the code below at the line "RETURN nResult":

Code: Select all

FUNCTION TestDelegate() AS VOID

LOCAL oPersons		AS List<Person>
LOCAL cText		AS STRING

oPersons := List<Person>{}
oPersons:Add(Person{"Robert"})
oPersons:Add(Person{"Fabrice"})
oPersons:Add(Person{"Chris"})
oPersons:Add(Person{"Nikos"})

oPersons:Sort( ;
DELEGATE(o1 AS Person, o2 AS Person) {
	LOCAL nResult AS INT
	nResult := o1:Name:CompareTo(o2:Name)
	RETURN nResult
	};
)

cText := ""
FOREACH Ps AS Person IN oPersons
	cText += Ps:Name + CRLF
NEXT
MessageBox.Show(cText)

RETURN

CLASS Person
PUBLIC PROPERTY Name AS STRING AUTO
CONSTRUCTOR(cName AS STRING)
	SELF:Name := cName
RETURN
END CLASS
The error is: "Error XS0126 An object of a type convertible to 'int' is required", at the line "RETURN nResult". Surely this RETURN is for the DELEGATE function? Yet if I change the return type of TestDelegate() to AS INT instead of AS VOID (and also change the single RETURN to RETURN 0), the compiler error is gone and the code works. It makes no sense to me.

Kees.
User avatar
wriedmann
Posts: 4104
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Documentation issues

Post by wriedmann »

Hi Kees,

I have now looked at the Wiki sample code.
There is a typo inside:
ErrorSample.png
ErrorSample.png (13.04 KiB) Viewed 393 times
it should be "o1 as Person" and not "o1 a Person", but with this correction it compiles on my machine.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 4104
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Documentation issues

Post by wriedmann »

Hi Kees, hi Robert,
the sample compiles in Core dialect, but not in VO dialect.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 5667
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Documentation issues

Post by Chris »

Guys,

I see the problem, will investigate. But I think the best way to do this is this:

Code: Select all

oPersons:Sort( {o1 AS Person, o2 AS Person => 
	LOCAL nResult AS INT
	nResult := o1:Name:CompareTo(o2:Name)
	RETURN nResult
	})
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 4104
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Documentation issues

Post by wriedmann »

Hi Chris,
thank you very much, I have now corrected the code in the sample.
Wolfgang
P.S. not always the explicit form is better <g>
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Kees Bouw
Posts: 183
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Documentation issues

Post by Kees Bouw »

Hi Chris, Wolfgang,

An even shorter version is:

Code: Select all

oPersons:Sort({o1, o2 => o1:Name:CompareTo(o2:Name)})
This also works. But the page title on https://docs.xsharp.it/doku.php?id=code ... n_delegate is "Sorting an object collection using a delegate" and I am curious how to do it with a delegate in the VO dialect. :-)

Kees.
Post Reply