Snippets in VS 2017 RC .... some success ....

Public forum to share code snippets, screen shorts, experiences, etc.
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Snippets in VS 2017 RC .... some success ....

Post by wriedmann »

Hi Robert,

this is really great, thank you very much! It will save a lot of code and keep the code cleaner at the same moment.

I have now tried something different:

Code: Select all

property mySuperProp as string get self:_Get<string>() set self:_Set( value )
and it seems to work. Unfortunately I have to specify the

Code: Select all

self:_Get<string>()


otherwise I have a compiler error.

It is the same in the in the extended version of this property:

Code: Select all

property mySuperPropX as string 
  get 
    return self:_Get<string>() 
  end get
  set 
    self:_Set( value )
  end set
end property
IMHO the compiler should be able to understand the type of return code. Or I'm making a wrong assumption?

Wolfgang

P.S. my test code is attached as XIDE export file
Attachments
PropertyTest.zip
(1.43 KiB) Downloaded 60 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Snippets in VS 2017 RC .... some success ....

Post by lumberjack »

Wolfgang,
Wolfgang Riedmann wrote:Hi Robert,

means this we can use the command preprocessor directive on X# Beta 9?

I have now tried the following code (on a single line):

Code: Select all

#command PROPERTY <n> AS <t> GETSET <v> => ; property <n> as <t>;;; get;;; return self:<v>;;; end get;;; set;;; if self:<v> <> value;;; self:<v> := value;;; endif;;; end set;;; end property

Code: Select all

class File1      
  protect _cCmdProp as string

property myCmdProp as string GETSET _cCmdProp

end class
but it gives the error

Code: Select all

error XS9002: Parser: mismatched input 'GETSET'	16,30	File1.prg	PropertyTest
Wolfgang
You state you have the #command on a single line, then you have too many ";" there should only be 1 between statements and none after the =>

Robert indicated #command will be available around Cologne except if I missed something.

Jack
______________________
Johan Nel
Boshof, South Africa
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Snippets in VS 2017 RC .... some success ....

Post by wriedmann »

Hi Jack,

this can be.... But since we don't have the preprocessor I cannot try it out yet.

I can wait, of course. The preprocessor will be a really cool thing, I'm looking forward to use it.

Really, fun has returned to programming thanks to the "Gang of Four"!

In the meantime I will use the short property syntax - I like it very much!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Snippets in VS 2017 RC .... some success ....

Post by lumberjack »

Hi Robert,
Robert van der Hulst wrote:Jac,

You probably know this already, but the single line syntax for properties is already supported by the compiler:
The GET clause expects an expression, the SET clause expects an expression list.
No I have not known it, well done, good to know. Must have missed it in the "whats new" section.

Regards,

Jack
______________________
Johan Nel
Boshof, South Africa
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Snippets in VS 2017 RC .... some success ....

Post by robert »

Jack,

This was probably never mentioned in the readme, since the single line property syntax is also supported b Vulcan.

You can see the EBNF notation for the property on:
http://www.xsharp.eu/help/property.html

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Snippets in VS 2017 RC .... some success ....

Post by lumberjack »

Thanks Robert,
Robert van der Hulst wrote:Jack,
This was probably never mentioned in the readme, since the single line property syntax is also supported b Vulcan.
You can see the EBNF notation for the property on:
http://www.xsharp.eu/help/property.html
Robert
If I remember correctly the #command single line was initially shown before PPOPERTY was available in Vulcan as wrapper to ACCESS/ASSIGN to align it with the then to be released PROPERTY.

The #command was done to not have to GET _var SET _var := VALUE, but shorten it to GETSET _var.

Although thus not 100% needed for a one liner property, I still think the concept of the pre-processor is a beauty and set the Clipper based dialects far ahead of the rest of the XBase pack.

It is however good to have a discussion around it to make people aware of the power that it brings to the language. We can "emulate" many other dialect syntax that the compiler does not understand yet to produce meaningful and useful code.

Jack
______________________
Johan Nel
Boshof, South Africa
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Snippets in VS 2017 RC .... some success ....

Post by robert »

Jack,

You are absolutely right that having a pre-processor adds a lot of power to a language.
I think that we can emulate 99% of the FoxPro syntax with the preprocessor as well.

I remember in the past, many years ago in 1993, that there was a product called the "CA-Clipper Compiler Kit for dBase IV". This product, written by Matt Whelan was using UDCs to convert dBase IV code to functions, which were then supplied in the form of a special library.

Most likely I still have a version of that (probably on 5 1/4 floppy disks), so I can have a look and use similar UDCs when we are going to add the FoxPro support.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4907
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Snippets in VS 2017 RC .... some success ....

Post by Chris »

Hi Wolfgang,

What you are looking for, is (generic) type inference based on the return type of the method, here's a simplified version of your code:

FUNCTION Start() AS VOID
LOCAL s AS STRING
s := TestClass.GenericMethod<STRING>() // OK
s := TestClass.GenericMethod() // error

CLASS TestClass
STATIC METHOD GenericMethod<T>() AS T
RETURN Default(T)
END CLASS

here you ask the compiler to figure out that the generic argument type of the method is STRING, because the result of that method is being assigned to a STRING var. While I agree that (in this case) it looks straightforward, type inference on return type is not supported by design (it's the same as in c#). Here is a discussion about this:

http://stackoverflow.com/questions/3203 ... ferred-why

Chris

ps. please don't shoot the messenger ;-)
Chris Pyrgas

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

Snippets in VS 2017 RC .... some success ....

Post by wriedmann »

Hi Chris,

thank you very much!

In the meantime I'll write the short form

Code: Select all

property mySuperProp as string get self:_Get<string>() set self:_Set( value )
until the preprocessor will be available.

After I'll use it to build the correct code.

Wolfgang

P.S. the only person I would like to shoot sometimes is myself when I'm doing something really stupid (you know several samples...)
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Snippets in VS 2017 RC .... some success ....

Post by robert »

Jack,

I tested one of your snippets with the new UDC support and the result is below;
prop1.png
prop1.png (29.25 KiB) Viewed 543 times


You can see:
- UDC definition is recognized and colored in the preprocessor color
- UDC usage is recognized ans colored as keyword (especially the GETSET, NOTIFY and CHANGE words which are not normal keywords)
- The editor shows the difference between the statement separator semi colon (which is part of the UDC) and the line continuation semi colon, so they are both colored in a different color!
And in the image below you see the preprocessor output:
prop2.png
prop2.png (57.87 KiB) Viewed 543 times

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply