Shop OBEX P1 Docs P2 Docs Learn Events
Why can't I chain "!" or "~" operators? — Parallax Forums

Why can't I chain "!" or "~" operators?

Dennis FerronDennis Ferron Posts: 480
edited 2007-02-11 21:16 in Propeller 1
I want to toggle a pin from high to low and back to high. I tried this:

!!outa[noparse][[/noparse]Reset6502]

And the Spin compiler doesn't like it. It also won't let me get away with:

!(!outa[noparse][[/noparse]Reset6502])

It seems to me that that ought to work; it should be a one line equivalent to:

!outa[noparse][[/noparse]Reset6502]
!outa[noparse][[/noparse]Reset6502]

I would also like to be able to say:

(outa[noparse][[/noparse]Reset6502]~)~~

But that doesn't work either.

Edit: Spin needs C-style preprocessor macros! My kingdom for a macro feature! Then I could just say #define TOGGLE(x) !x; !x

Comments

  • codekingcodeking Posts: 39
    edited 2007-02-11 19:56
    Why do you want to put those operators together in the first place?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Theron Luhn

    "There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
  • CJCJ Posts: 470
    edited 2007-02-11 20:03
    I would imagine for a brief pulse, say for latching a 595 shift register

    or reseting a 6502 as his code would suggest

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-02-11 20:05
    Dennis,

    The operators "!", "~", and "~~" return the value of the pin, during runtime, after the operation takes place. When you attempt to apply the operator again, you are telling the compiler you want to apply it to the result of the previous operation (a number) and not to the pin itself. That, of course, makes no sense to the compiler, and it flags the error.

    Now, having said that, it's possible when compiling to keep track of two elements of an operation: the value and the "lvalue", where one exists. The "l" stands for "left", and relates to the "value" of a variable when it's encountered on the lefthand side of an assignment operator. The lvalue is just a reference to the original operand and not to its assigned value. Then, when a subsequent operation is performed, the compiler has to decide, based on context, whether to apply that operation to the value or to the lvalue.

    Sometimes when interpretations like what you hoped for are implemented, ambiguities creep into the language's semantics. Spin's semantics have the advantage of being simple and unambiguous. And I'm sure that was done on purpose.

    -Phil
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-11 20:09
    Then just put them on different lines, if the reason its trying to be placed on on the same line is from the belief it runs faster (which it wouldn't by much), use a counter generate acurate pulses as small as 12.5ns in width.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Dennis FerronDennis Ferron Posts: 480
    edited 2007-02-11 21:16
    No the timing is not important - and I realize it wouldn't be any faster. I was just trying to find a "shorthand" notation for a common task.
Sign In or Register to comment.