Main Board > Wish List

Enumeration Sequencing

(1/2) > >>

James Zukowski:
There are times I'd like to have an ENUMeration-type directive available. I know the LET gets things done, but not having to repeat variable names would help.

E.g., instead of:


--- Code: ---Opt.1=1,Opt.2=Opt.1+1,Opt.3=Opt.2+1,Opt.4=Opt.3+1
--- End code ---

we would have something like:


--- Code: ---ENUM Opt.1,Opt.2,Opt.3,Opt.4
--- End code ---

Possibility?

Thomas Bock:
By the way, LET a,b,c=0 would be nice as well.

James Zukowski:
And there's also binary bit-flag generation to consider:

Flag.1=1,Flag.2=2*Flag.1,Flag.3=2*Flag.2,Flag.4=2*Flag.3

Not quite sure how to "translate" that.

Perhaps an extension of the SET--- directives might work. E.g.,

SETFLAGS Flag.1,Flag.2,Flag.3,Flag.4,...

and for enumerations:

SETENUM Opt.1,Opt.2,Opt.3,Opt.4,...

Mike King:
James, have you considered creating a simple object to do this as in...


--- Code: ---  def class "enum"
  function Integer(*)do_enum
  function Binary(*)do_enumbin
  end def
 !
 do_enumbin:
  bin=1
 do_enum:
  x$=stk(properties)
 !
  if x$="" \
   then return
 !
  if pos("N"^x$)<>0 \
   then def msg(201)="Non-numeric variable passed to function";
        exit 201
 !
  n=1
  for i=1 to len(x$)
  vars$+=",v"+str(i)
  vals$+=str(n)+sep
  if bin \
   then n=n*2 \
   else n++
  next
 !
  vars$=cpl("iolist "+vars$(2))
  enter iol=vars$
  read data from vals$ to iol=vars$
  return

--- End code ---

It could then be used like this:

-:list
0010 BEGIN
0020 LET oEnum=NEW("enum" FOR PROGRAM)
0030 oEnum'Integer(a,b,c,d,e)
0040 oEnum'Binary(x,y,z)
0050 DUMP
-:run
! ERR=0, CTL=0, RET=2
! **********************************************************
! Level=1
! PGN="<Unsaved>"
!  Statement......0050
a=1
b=2
c=3
d=4
e=5
oEnum=100001
x=1
y=2
z=4

You could also add a 'Clear function to set all the values to 0 if desired in response to Thomas Bock's request

James Zukowski:
That's an interesting approach, though I would probably make it a global object that's established on login without any dependencies. That way, we don't have to instantiate it when we want to use it; that's already done.

Also, to Thomas Bock's request, I might suggest an 'Assign (and possibly 'Assign$) method to use the first argument as the value to assign to the remaining list. I'm sure we can figure that part out from here.

Thanks for the different perspective!

Navigation

[0] Message Index

[#] Next page

Go to full version