Shop OBEX P1 Docs P2 Docs Learn Events
Spin Syntax/Semantics — Parallax Forums

Spin Syntax/Semantics

heaterheater Posts: 3,370
edited 2008-06-24 15:27 in Propeller 1
Anyone got any idea about the following constructs in a CON block ?


CON
  a_name = 2, b_name, c_name, d_name                'Etc etc
  
  e_name, f_name, g_name = 2, h_name, i_name    'Etc etc

  j_name, k_name, l_name





None of those names exists any place else in the code at the time.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.

Post Edited (heater) : 6/3/2008 7:08:10 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-03 18:54
    What's the question? "got any idea?" is pretty broad.
  • heaterheater Posts: 3,370
    edited 2008-06-03 19:00
    Sorry Mike I'm a bit tired here.

    One can type those statements into a CON section and it compiles without complaint.

    So the question is what do they actually mean/do ?

    How can I put the subject that I forgot onto this thread ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-06-03 19:02
    Click the little "pencil" icon at the top right of the first post. Change the title. Click "Submit".
  • hippyhippy Posts: 1,981
    edited 2008-06-03 19:55
    All those names get created as constants. You can print out their values via serial or to the TV to find how they are allocated numeric values and which ... or perhaps read the manual smile.gif

    Page 194
  • heaterheater Posts: 3,370
    edited 2008-06-03 20:55
    Hippy: err Yeah. I've seen page 194 before and totally forgotten about it. That is the most succinct syntax for enumerations I have ever seen.

    Next question (and yes I am looking in the FM without success so far) are the comparisons < > etc signed or unsigned ?

    Guess I could start experimenting as you suggest but it would be nice to see it specified some where.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • hippyhippy Posts: 1,981
    edited 2008-06-03 22:00
    Not sure where it is in the manual but comparisons are between signed long. Bytes and words are promoted to long with msb's zeroed unless explicitly sign extended. That's about the best way I can think of putting it.
  • heaterheater Posts: 3,370
    edited 2008-06-04 06:52
    Yep, signed according to experiment

    CON
      #2                    ' Set "enumerator" value to 2
      a_con = $FFFFFFFF < 0 ' a_con becomes FFFFFFFF (or True)
      b_con                 ' b_con becomes 2, the enumerator which is then incremented
      #b_con + 3            ' Set the enumerator to 5
      c_con                 ' c_con becomes 5, the enumerator which is then incremented
      d_con                 ' c_con becomes 6, the enumerator which is then incremented
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2008-06-04 08:38
    Also documented in the table on manual page 157.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Agent420Agent420 Posts: 439
    edited 2008-06-04 11:16
    heater said...
    That is the most succinct syntax for enumerations I have ever seen.
    Doesn't seem much different than most C or Basic methods...

    const double x = 1.0, y = 2.0, z = 3.0;





    ·
  • heaterheater Posts: 3,370
    edited 2008-06-04 16:28
    Agent420:

    I don't mean to be picky but just this once smile.gif

    I did say "succinct" and "enumerations". Your example is not an enumeration but a series of constant definitions.

    Below are a few examples of enumerations in various languages:
    /* Traditinal C way to do enums */
    #define CAT   0
    #define DOG   1
    #define GOAT  2
    #define COW   3
    
    // ANSI C or C++  Enums*/
    enum  { CAT, DOG, GOAT, COW };
    
    // or
    enum animals {cat, dog, goat, cow};
    
    
    ' Visual Basic Enum
    Enum animals
        cat
        dog
        goat
        cow
    End Enum
    
    -- Ada Enum
    type Animals is (cat, dog, goat, cow);
    
    ' And in Spin, Assuming you are in a CON block already
    
        cat
        dog
        goat
        cow
    
    



    Now I think you'll agree that SPIN takes the cake here with the total absence of keywords, brackets, commas, semicolons or indeed any printable syntactic elements at all !

    Imagine you wanted to write a compiler wouldn't you rather just allocate an increasing number to a list of names or parse all that other junk a well?

    Of course the other languages have reasons for what they do especially when defining enumeration types.

    Cheers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2008-06-04 18:17
    OK here's a good one.

    Spin solves an age old mathematical mystery, what is the square root of minus one ?

    CON
    i = ^^ -1

    Answer seems to be $0000FFFF.

    But then i squared should be 1

    CON
    i = ^^ -1 * ^^ -1

    Gives $FFFE0001

    Oh well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2008-06-22 03:59
    The following CON block produces constants with values as per their names:

    CON
        zero, one
        two = one + one
        #one + two, three[noparse][[/noparse]one + two], six
    
    



    Is the use of array indexing a constant documented anywhere ?
    Seems a very strange idea.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2008-06-24 07:22
    Not many takers for discussing Spin quirks then.

    Here's another one anyway, the strangest form of string concatenation ever:

    DAT
    ' These two result in the same strings
    a_string byte "ABCD" + "EFGH"
    b_string byte "A", "B", "C", "D" + "E", "F", "G", "H"
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-24 15:27
    The plus sign was never intended to be a concatenation operator. Your first example only makes it look that way to Microsoft BASIC programmers. In these types of declaration statements, grouping individual characters together in "strings" (which they aren't) means nothing to the compiler. This was demonstrated even more profoundly here. It's not the best approach to parsing character groups, granted, but changing it now would break too many extant programs. We'll just have to live with it.

    Just remember: commas butt the ends of strings together; plus signs tie them in a knot. smile.gif

    -Phil
Sign In or Register to comment.