PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Enumeration Sequencing  (Read 2427 times)

James Zukowski

  • Diamond Member
  • *****
  • Posts: 297
    • View Profile
Enumeration Sequencing
« on: October 09, 2018, 11:39:30 AM »
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: [Select]
Opt.1=1,Opt.2=Opt.1+1,Opt.3=Opt.2+1,Opt.4=Opt.3+1
we would have something like:

Code: [Select]
ENUM Opt.1,Opt.2,Opt.3,Opt.4
Possibility?
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Thomas Bock

  • Diamond Member
  • *****
  • Posts: 177
    • View Profile
Re: Enumeration Sequencing
« Reply #1 on: October 10, 2018, 01:57:06 AM »
By the way, LET a,b,c=0 would be nice as well.

James Zukowski

  • Diamond Member
  • *****
  • Posts: 297
    • View Profile
Re: Enumeration Sequencing
« Reply #2 on: October 25, 2018, 10:13:21 AM »
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

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Enumeration Sequencing
« Reply #3 on: October 25, 2018, 10:57:55 AM »
James, have you considered creating a simple object to do this as in...

Code: [Select]
  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
eMail: mike.king@bbsysco.com

James Zukowski

  • Diamond Member
  • *****
  • Posts: 297
    • View Profile
Re: Enumeration Sequencing
« Reply #4 on: October 25, 2018, 11:26:53 AM »
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

  • Diamond Member
  • *****
  • Posts: 124
    • View Profile
Re: Enumeration Sequencing
« Reply #5 on: November 08, 2018, 08:31:13 AM »
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

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Enumeration Sequencing
« Reply #6 on: November 08, 2018, 09:05:11 AM »
To suppress the "LET" directive simply set the 'NL' system parameter.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com