[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mobile variables



Mobile variables: irrelevant correction
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have just noticed that I committed a sin in my ping/pong example :-)
I am sure you all noticed and were too polite to mention it.  I have been
reading a lot of C recently:    >:-(

I modified "i" in the scope of an abbreviation which used its value. I
intended that MOBILE (eh, SHARED?) abbreviations should obey all the usual
rules, of course. I wasn't intending to destroy referential transparency!
A quick fix:-

--{{{  7) ping/pong
[2] MOBILE [rows][cols]INT image: -- MOBILE [2][rows][cols]INT image:
                                  --  also allowed since mobile
                                  --  applies to whole address range
--{{{  produce
PROC produce(CHAN OF VAR [rows][cols]INT image[0], image[1] in,out)
  INITIAL INT i IS 1:
  SEQ
    WHILE TRUE
      SEQ
        i := i >< 1
        ping IS MOBILE image[i]     :
        pong IS MOBILE image[i >< 1]:
        PAR
          SEQ
            CLAIM ping
            ...  fill ping from camera
            out ! VAR ping
          in ? CASE VAR pong
:
--}}}
--{{{  consume
PROC consume(CHAN OF VAR [rows][cols]INT image[0],image[1] in,out:)
  INITIAL INT i IS 1:
    WHILE TRUE
      SEQ
        i := i >< 1
        ping IS MOBILE image[i]     :
        pong IS MOBILE image[i >< 1]:
        PAR
          SEQ
            CLAIM pong
            out ! VAR pong
          SEQ
            in ? CASE VAR ping
            ...  process
:
--}}}

CHAN OF VAR image[0],image[1] up,down:

PAR
  produce(down,up)
  consume(up,down)

--}}}

Adrian

-- 
A E Lawrence, MA., DPhil.  	adrian.lawrence@xxxxxxxxxxxxxx
MicroProcessor Unit, 13, Banbury Road, Oxford. OX2 6NN. UK.                
Voice: (+44)-1865-273274,  Fax: (+44)-1865-273275