Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

macro on left side of equation 27 Oct 2020 16:28 #16399

  • kevclark64
  • kevclark64's Avatar
  • Topic Author


  • Posts: 123
  • 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:
    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"

    Please Log in or Create an account to join the conversation.

    macro on left side of equation 27 Oct 2020 17:01 #16400

    • Chris
    • Chris's Avatar


  • Posts: 3843
  • 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:

    &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.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    macro on left side of equation 27 Oct 2020 17:45 #16401

    • kevclark64
    • kevclark64's Avatar
    • Topic Author


  • Posts: 123
  • Chris, thanks for that information.

    Please Log in or Create an account to join the conversation.

    macro on left side of equation 27 Oct 2020 22:23 #16402

    • kevclark64
    • kevclark64's Avatar
    • Topic Author


  • Posts: 123
  • Maybe I'm confused about macros in general. Given the following code:
    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?

    Please Log in or Create an account to join the conversation.

    macro on left side of equation 27 Oct 2020 22:29 #16403

    • robert
    • robert's Avatar


  • Posts: 3446
  • 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:
    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

    Please Log in or Create an account to join the conversation.

    macro on left side of equation 16 Nov 2020 20:41 #16663

    • mainhatten
    • mainhatten's Avatar


  • Posts: 199
  • 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:

    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.
    local variable1, exprstring as string
    variable1="This is a string"
    exprstring="variable1"
    Store "This is a new string" To (exprstring)

    regards
    thomas

    Please Log in or Create an account to join the conversation.

    macro on left side of equation 16 Nov 2020 20:52 #16664

    • robert
    • robert's Avatar


  • Posts: 3446
  • 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

    Please Log in or Create an account to join the conversation.

    macro on left side of equation 17 Nov 2020 18:26 #16669

    • mainhatten
    • mainhatten's Avatar


  • Posts: 199
  • 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

    Please Log in or Create an account to join the conversation.

    Last edit: by mainhatten.
    • Page:
    • 1