Home Forums Tips & Techniques Capytalk ‘nil’

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1967
    Cristian Vogel
    Participant

      Hi.

       

      after 18 years using Kyma , I just tried this and it worked. Seems that the behaviour of nil acts like a sampleAndHold of the value computed by the true: expression

      ?freeze true: ( (?BackNForth + 1) * ?grainSize ) false: nil

      #1968
      Cristian Vogel
      Participant

        …or?    Maybe not. I can’t quite tell in the context I am working right now. Except that it compiles, so perhaps SSC can clarify 🙂

         

        its not urgent

        #1969
        SSC
        Keymaster

          In the expression you propose, the nil case returns whatever is on the top of the stack, so the result is undefined (depends on what is happening in other parameter fields and Sounds).

          #1975
          Alan Jackson
          Participant

            Yikes. I’ve used the false: nil  expression a lot in the past kind of assuming it meant “if false don’t do anything”, but now I come to think about it the expression has to return something. It’s always worked fine when I’ve used it but I think I’ve been lucky!

            I guess a way to use this reliably is to use an EventVariable, assign the new value to the EventVariable in the true: clause, put nil in the false: clause, put a comma after the expression then explicitly return the EventVariable.

            Something like:

            | ev |
            
            ev := EventVariable new initialValue: 0.
            
            (?freeze true: (ev <+ ( (?BackNForth + 1) * ?grainSize )) false: (nil)),
            ev.

             

            Is that the best way?

            #1976
            Alan Jackson
            Participant

              Ah, maybe you could simplify that a little by not popping the value off the stack when assigning it to the EventVariable like:

              | ev |
              
              ev := EventVariable new initialValue: 0.
              
              ?freeze true: (ev <~ ( (?BackNForth + 1) * ?grainSize )) false: (ev)
              #1977
              SSC
              Keymaster

                This last variation is the best. 🙂

              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.