1. Check my code

------=_NextPart_000_000D_01C012D2.1006B100
        boundary="----=_NextPart_001_000E_01C012D2.1006B100"


------=_NextPart_001_000E_01C012D2.1006B100
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

I worked out example from ABGATE2. PLease find errors if you can.=20

Thank You

-Asif

------=_NextPart_001_000E_01C012D2.1006B100
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I worked out example from ABGATE2. =
PLease find=20
errors if you can. </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thank You</FONT></DIV>
<DIV>&nbsp;</DIV>

------=_NextPart_001_000E_01C012D2.1006B100--

------=_NextPart_000_000D_01C012D2.1006B100
        name="NEW1.EX"

new topic     » topic index » view message » categorize

2. Re: Check my code

I've added comments to try to explain everything....
Hope this helps.
-- Brian


--Finally I got through advanced data object handling example by David Alan.

--Thing is, there are a few things that are not so clear. Please go through

--the code and find any errors.

--Thank You David

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
-- NOTE: Because either a sequence or an atom (-1) might be returned, you
--  should probably assign the result of 'gets' to a variable declared as
--  object.
object input_string

-- atom_recieved = 'n'
atom_received = FALSE

-- integer_rec = 'n'
integer_rec = FALSE

-- seq_var = 'n'
-- NOTE: actually, this is not needed
-- seq_var = FALSE

-- 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 "
-- ALSO, we should add a check for seq_var

  input_string = get(0)
-- NOTE: 'get' is intended to be used with reading from files
-- input_string = gets( 0 )  -- read from keyboard (user input)
  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 message » categorize

3. Re: Check my code

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 message » categorize

4. Re: Check my code

Thanks Brian, you really helped. I have another question. Since Objects
could be both atoms and sequences, can we declare the atom_recieved &
integer_recieved as objects also?

integer atom_received, integer_rec         --Could be objects as well ?

object input_string            --Clear like a crystal.

Thanks a lot. You have been a big help

-Asif

new topic     » goto parent     » topic index » view message » categorize

5. Re: Check my code

On Thu, 31 Aug 2000 08:17:54 -0700, Asif Masood Baloch wrote:

>Thanks Brian, you really helped. I have another question. Since Objects
>could be both atoms and sequences, can we declare the atom_recieved &
>integer_recieved as objects also?
>
>integer atom_received, integer_rec         --Could be objects as well ?

Absolutely.  Every variable in your program could be declared as an
object.  But the whole point of declaring variables and specifying a type
is to help track down errors in your program.  This is no big deal with
such a small program but it can happen with larger ones.  If you know your
variable will/should only hold an integer (not a float nor a sequence of
integers, etc.) then it's best to declare it as such.  This will also speed
up execution because the interpretter doesn't have to figure out a
variable's type so that it gets stored properly (again, not such a big deal
with your program but it's a good habit to get into).

>
>object input_string            --Clear like a crystal.

In my first reply I declared input_string as an object because I was
thinking of using 'gets' instead of 'get'.  The second time, I changed it
back to the way you had originally written it since 'get' always returns a
2-element sequence {error status, value}.

Yes, you could declare it as an object but... (see above).  On the other
hand, if you used 'gets' intead of 'get', then you *should* declare it as
an object because either a sequence or an atom (-1) might be returned. (The
atom -1 is returned on end of file.)

I hope I didn't cloud your crystal...

-- Brian

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu