Enumeration Sequencing

Started by James Zukowski, October 09, 2018, 11:39:30 AM

Previous topic - Next topic

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:

Opt.1=1,Opt.2=Opt.1+1,Opt.3=Opt.2+1,Opt.4=Opt.3+1

we would have something like:

ENUM Opt.1,Opt.2,Opt.3,Opt.4

Possibility?
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

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,...
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Mike King

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


  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


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
Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com

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!
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Peter.Higgins

James,

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

read data from $$ to a,b,c,iol=nomadsVars$,tmp$
read data from "" to a,b,c ,iol=nomadsVars$,tmp$ 

Suppressing the "highly practical" LET is an option too. 
Personally I find them distracting, and suspect they are a prime reason for BASIC disdain.

Mike King

To suppress the "LET" directive simply set the 'NL' system parameter.
Mike King
President - BBSysco Consulting - http://www.bbsysco.com
eMail: mike.king@bbsysco.com