macro on left side of equation

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

Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

macro on left side of equation

Post by kevclark64 »

Not sure if this has been addressed before, but I get a compile error if I use a macro on the left side of an equation, like this:

Code: Select all

local variable1, macrostring as string
variable1="This is a string"
macrostring="variable1"
&macrostring="This is a new string"
That is valid in Foxpro and assigns "This is a new string" to variable1. In X# I get the error "The left-hand side of an assignment must be a variable, property or indexer"
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

macro on left side of equation

Post by Chris »

Hi Kevin,

This is actually supported, but there seems to be a small bug in the compiler currently which does not allow this exact syntax. But if you change "=" with ":=" it will work:

Code: Select all

&macrostring := "This is a new string"

I will log this though as a bug to be fixed, so in a newer build it will be possible to use "=" as well.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

macro on left side of equation

Post by kevclark64 »

Chris, thanks for that information.
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

macro on left side of equation

Post by kevclark64 »

Maybe I'm confused about macros in general. Given the following code:

Code: Select all

local lcMacroTest = "Success" as string
local lcInsertString as string
lcInsertString = "This is the macro: &lcMacroTest "
MessageBox(lcInsertString)
the messagebox should display "This is the macro: Success" but it's displaying "This is the macro: &lcMacroTest" Am I doing something wrong here?
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

macro on left side of equation

Post by robert »

Kevin,
This automatic expanding of strings that have an embedded macro is not on by default. It adds quite an overhead to the speed of the compiler and runtime because all strings need to be checked for an embedded ampersand.

We do support this:

Code: Select all

local lcMacroTest = "Success" as string
local lcInsertString as string
lcInsertString = "This is the macro: &lcMacroTest "
MessageBox(StrEvaluate(lcInsertString))
We assume that you as a developer know when a string has a macro (or may have a macro) and you can decide when to add this and when not.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

macro on left side of equation

Post by mainhatten »

Hi Kevin,
Kevin Clark wrote:Not sure if this has been addressed before, but I get a compile error if I use a macro on the left side of an equation, like this:

Code: Select all

local variable1, macrostring as string
variable1="This is a string"
macrostring="variable1"
&macrostring="This is a new string"
That is valid in Foxpro and assigns "This is a new string" to variable1. In X# I get the error "The left-hand side of an assignment must be a variable, property or indexer"
On the vfp side using name expressions combined with "Store" is faster as no macro expansion is involved and allows you to set multiple targets if needed.

Code: Select all

local variable1, exprstring as string
variable1="This is a string"
exprstring="variable1"
Store "This is a new string" To (exprstring)
regards
thomas
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

macro on left side of equation

Post by robert »

Thomas,
This has been implemented in X# in the mean time.

In fact it was already working for the := operator (which is handled by the "assignmentexpression" rule in the compiler.
However we forgot to check for macro expressions in the LHS of the "binaryexpression" rule (the '=' operator can also be a comparison) . This binary expression is "promoted" to an assignment expression when it is the first expression on an expression statement.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

macro on left side of equation

Post by mainhatten »

Hi Robert,
robert wrote:This has been implemented in X# in the mean time.
I had realized that - but I expect the "Store to (nameexpr)" to be faster compared to macrocompilation in xSharp as well, so I decided to mention the vfp "better practice" in the hope that no premature micro-benchmark comparison between vfp and xSharp ensues, as such code parts should be the exception and not really relevant fo compare between runtimes.

regards
thomas
Post Reply