Menu

"Let" assignments appear not to work within #Script - EndScript

mkstevo
2022-05-08
2022-05-10
  • mkstevo

    mkstevo - 2022-05-08

    I managed to confuse myself earlier while writing the "MyMillis" file I've been using for timing while I struggle to get the "master" version of 'millis.h' to work on the 16F1829.

    I include this in a script and it failed to work as I expected:

    #Script
      If ChipMHz = 64 Then
        Let FrequencyIncluded = 1
        Let MyPreLoad = 49356  'Preload Timer for 1mS @ 64MHz
      End If
    
      ... Other statements followed for other frequencies
    
    #EndScript  
    

    When it failed to work I was more than confused for some time before I found that using the "Let" statement rendered the assignments null and void.

    This works:

    #Script
      If ChipMHz = 64 Then
        FrequencyIncluded = 1
        MyPreLoad = 49356  'Preload Timer for 1mS @ 64MHz
      End If
    
      ... Other statements followed for other frequencies
    
    #EndScript  
    

    I presume this is due to the compiler treating the named "variables" as contants which also do not require a "Let" statement. However, "Contants" when instantiated with "#Define" also don't use the equals sign.

    Not sure it is an error, more likely intended behaviour, but perhaps it could be noted in the online help? Took me three hours to work it out...

     
  • stan cartwright

    stan cartwright - 2022-05-08

    I tried putting let var= a few times in a working program using gcstudio with no problems so a script thing maybe.
    edit.. let... nostalgia... zx spectrum with let key

     

    Last edit: stan cartwright 2022-05-08
    • mkstevo

      mkstevo - 2022-05-09

      "Let" within a program or a Sub seems fine, it was only as I tried to get "clever" with another program that I thought: #Script ... #EndScript might be useful. It confused me that it works within a program, but not in a #Script ... #EndScript. No errors were shown, the help file doesn't mention that script variables (or constants) won't be set when using "Let". It makes explicit reference to floating point values, but not "Let".

      As ever I thought I'd mention it as it may confuse someone else. And perhaps if it could be mentioned in the help file too?

       
  • Anobium

    Anobium - 2022-05-09

    Are you saying - Let is not supported in Scripts. That sounds about right to me.

     
    • mkstevo

      mkstevo - 2022-05-09

      I am indeed saying that.

      "Let" not only fails to work as intended when used within #Script ... #EndScript, it fails to show any errors regarding this, nor is it recorded in any documentation.

      It may well be "right" but I do think it should be highlighted, as the assignment of floating point values is.

       
      • Anobium

        Anobium - 2022-05-09

        I will add this to the backlog of work.
        LET should be rejected with an appropriate syntax error message.

         
        • mkstevo

          mkstevo - 2022-05-09

          At the least a mention in the help files would have saved me a number of hours confusion.

          I did say that I assumed it was intended behaviour, although as "Let" is allowed (if frowned upon) elsewhere in assignment statements I had no reason to initially doubt using it within a #Script ... #EndScript construct.

          Hopefully me mentioning this will be all that is needed to help other users and relieve some of the backlog.

          I still like to use "Let" as it helps me to see that I am making an assignment of a value as opposed to comparing a value in someway. I liked the Pascal syntax of using ":=" for assignment and "=" for equality testing. It helps me focus.

           
  • Anobium

    Anobium - 2022-05-10

    Resolved in build 1116. See attachment for resolution.

    Use of LET in scripts is now trapped. Can not use LET in scripts. Scripts can only create CONSTANTS

    Code Segment

    #Script
      If ChipMHz = 64 Then
        LET FrequencyIncluded = 1
        MyPreLoad = 49356  'Preload Timer for 1mS @ 64MHz
      End If
    
      If ChipMHz = 32 Then
        LET FrequencyIncluded = 1
        MyPreLoad = 49356  'Preload Timer for 1mS @ 64MHz
      End If
    #EndScript 
    

    Errors messages

    Great Cow BASIC (0.99.02 2022-04-27 (Windows 64 bit) : Build 1116)
    
    Compiling c:\temp\New.gcb ...
    
    Errors have been found:
    
     New.gcb (10): Error: Can not use LET in scripts.  Scripts can only create 
     CONSTANTS
     New.gcb (15): Error: Can not use LET in scripts.  Scripts can only create 
     CONSTANTS
    
    The message has been logged to the file Errors.txt.
    
     

    Last edit: Anobium 2022-05-10

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.