[comp.lang.pascal] Sets

code120dp@srf-subic.navy.mil (Delfin R. Pascual Jr.) (06/06/91)

  Hi to everyone out there!

  I have a question about set elements in Pascal.  Is there a way to reference
individual elements of a set (like array elements are referenced by a
subscript) without using sets of enumerated types?

  Any help will be greatly appreciated.

Thanks,

Delfin

CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) (06/07/91)

In article <9106052050.aa01678@VGR.BRL.MIL>,
  code120dp@srf-subic.navy.mil (Delfin R. Pascual Jr.) wrote:

>  I have a question about set elements in Pascal.  Is there a way to
>reference individual elements of a set (like array elements are
>referenced by a subscript) without using sets of enumerated types?

Could you maybe give a concise example of what you are trying to do?

+====================================================================+
| Karl Brendel                           Centers for Disease Control |
| Internet: CDCKAB@EMUVM1.BITNET         Epidemiology Program Office |
| Bitnet: CDCKAB@EMUVM1                  Atlanta GA  30093       USA |
|                        Home of Epi Info 5.0                        |
+====================================================================+

bobb@vice.ICO.TEK.COM (Bob Beauchaine) (06/07/91)

In article <27126@adm.brl.mil> (Delfin R. Pascual Jr.) writes:
>
>  Hi to everyone out there!
>
>  I have a question about set elements in Pascal.  Is there a way to reference
>individual elements of a set (like array elements are referenced by a
>subscript) without using sets of enumerated types?

  Well, not exactly...

  Since you don't mention a compiler, I'll assume (quite impudently) 
  Turbo Pascal.  

  A Turbo set can hold up to 256 elements.  This requires, at one bit 
  per element, 32 bytes of storage per set variable (bet you didn't know
  sets were so memory hungry).  There are two direct methods I can think
  of that will allow you to access the individual bytes of a set (though
  not the individual bits, at least w/o a little extra work).  You can 
  use either a variable typecast, or an absolute variable.  Here's an 
  example code fragment that does both:

  type set_array = array[1..32] of byte;

  var a_set : set of char;  { Set base type.  Could be any ordinal type }
      a_set_array : set_array absolute a_set; { Array on top of a_set }
      i : integer;

      .
      .
      .
      { Either method should work }
      for i := 1 to 32 do begin
	writeln(set_array(a_set)[i]);  { Use a typecast }
	writeln(a_set_array[i]);       { Use the predefined array }
      end;

      Note that both of these expressions for the set values could
      also appear on the left hand side of an assignment statment.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ 


Bob Beauchaine bobb@vice.ICO.TEK.COM 

C: The language that combines the power of assembly language with the 
   flexibility of assembly language.

   "It seems that the less a statesman amounts to, the more he appears
   to love the flag".