Page 1 of 1
macro on left side of equation
Posted: Tue Oct 27, 2020 3:28 pm
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"
¯ostring="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"
macro on left side of equation
Posted: Tue Oct 27, 2020 4:01 pm
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
¯ostring := "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.
macro on left side of equation
Posted: Tue Oct 27, 2020 4:45 pm
by kevclark64
Chris, thanks for that information.
macro on left side of equation
Posted: Tue Oct 27, 2020 9:23 pm
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?
macro on left side of equation
Posted: Tue Oct 27, 2020 9:29 pm
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
macro on left side of equation
Posted: Mon Nov 16, 2020 7:41 pm
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"
¯ostring="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
macro on left side of equation
Posted: Mon Nov 16, 2020 7:52 pm
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
macro on left side of equation
Posted: Tue Nov 17, 2020 5:26 pm
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