Re: Check my code

new topic     » goto parent     » topic index » view thread      » older message » newer message

Sorry, I posted my last response without double checking my code.  I left
in some comments that did not apply and I don't want to confuse you.  So
here it is again:


include get.e

-- NOTE: use contants to define TRUE/FALSE boolean values for greater
--  clarity
constant
  TRUE = 1,
  FALSE = 0

-- atom atom_recieved, integer_rec, seq_var
-- NOTE: Since we are using these as boolean variables, they can be
--  declared as integers.
integer atom_received, integer_rec

sequence input_string

-- atom_recieved = 'n'
atom_received = FALSE

-- integer_rec = 'n'
integer_rec = FALSE

-- seq_var = 'n'
-- NOTE: this is not needed

-- while atom_recieved = 'n' and integer_rec = 'n' do
while not ( atom_received or integer_rec ) do
-- NOTE: since 'atom_received' and 'integer_rec' are essentially boolean,
--  there is no need to see if they " = FALSE "

  -- prompt user so they know what to do...
  puts( 1, "Enter an atom, integer, or sequence:\n" )
  input_string = get(0)

  puts( 1, "\n" )  -- enter a newline so that we don't overwrite
                   --   the value entered

-- if input_string[1] = 0 then     --Here, does [1] refer to boolean?
-- ANSWER: No, [1] refers to the first element of the
sequence 'input_string'
--  the first element will be the error status (see reference manual)
  if input_string[1] = GET_SUCCESS then

    if integer( input_string[2] ) then    -- Is [2] used to seperate [1]?
-- ANSWER: [2] refers to the actual data recieved from 'get', (it is the
--  second element of the sequence 'input_string'

      --integer_rec = 'y'   --Boolean ??
-- ANSWER: Sort of, but instead of using 1/0 (TRUE/FALSE) you are
using 'y'/'n'
--  which are both equivalent to TRUE (non-zero = TRUE)
      integer_rec = TRUE

      puts(1, "WoW, you entered an integer value\n")

--    else

    elsif atom(input_string[2]) then

      --atom_recieved = 'y'
      atom_received = TRUE

      puts(1, "You entered an atom value\n")

    --else

    --if sequence(input_string[2]) then

      --seq_var = 'y'

      --puts(1, "Now you entered a sequence value\n")

        --end if

      --end if

    end if

  else   -- NOTE: if not integer nor atom then must be sequence
         --  there is no need to check and we should exit the while loop
    puts(1, "Now you entered a sequence value\n")
    exit -- exit 'while' loop

  end if

end while

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu