Requesting ELSEIF
03-24-2017, 05:30 PM
Post: #1
 toml_12953 Senior Member Posts: 1,478 Joined: Dec 2013
Requesting ELSEIF
If you're taking suggestions for additions to HPPL, I'd like to propose the addition of ELSEIF (or ELIF). With lengthy IF-THEN structures, it can tighten up the code considerably.

Tom L
Current way (greatly trivialized example):

Code:
IF x>7 THEN   PRINT("TOO HIGH"); ELSE   IF X<4 THEN     PRINT("TOO LOW");   ELSE     PRINT("JUST RIGHT");   END; END;

Now improved with ELSEIF

Code:
IF x>7 THEN   PRINT("TOO HIGH"); ELSEIF X<4 THEN   PRINT("TOO LOW"); ELSE   PRINT("JUST RIGHT"); END;

Tom L
I don't care for whom you voted. If you put ice in your beer, you're crazy.
03-24-2017, 05:38 PM
Post: #2
 Han Senior Member Posts: 1,831 Joined: Dec 2013
RE: Requesting ELSEIF
(03-24-2017 05:30 PM)toml_12953 Wrote:
Code:
IF x>7 THEN   PRINT("TOO HIGH"); ELSE   IF X<4 THEN     PRINT("TOO LOW");   ELSE     PRINT("JUST RIGHT");   END; END;

Now improved with ELSEIF

Code:
IF x>7 THEN   PRINT("TOO HIGH"); ELSEIF X<4 THEN   PRINT("TOO LOW"); ELSE   PRINT("JUST RIGHT"); END;

CASE blocks have similar logic to nested ELSE-IF blocks (exiting the block once a condition is met and relevant actions are executed). It doesn't make your code any shorter but can provide improved legibility.

Code:
CASE   IF x>7 THEN PRINT("TOO HIGH"); END;   IF x<4 THEN PRINT("TOO LOW"); END;   PRINT("JUST RIGHT"); END;

Graph 3D | QPI | SolveSys
03-24-2017, 06:21 PM (This post was last modified: 03-24-2017 07:17 PM by compsystems.)
Post: #3
 compsystems Senior Member Posts: 1,269 Joined: Dec 2013
RE: Requesting ELSEIF
I like the version ELSEIF. instead of using CASE

now with IFTE functional command version

PHP Code:
EXPORT elif(x)BEGIN  IFTE(x>7,print("TOO HIGH"),IFTE(x<4,print("TOO LOW"),print("JUST RIGHT")));END;

A small survey.

you need an IFT() functional command? (without ELSE block)

PHP Code:
EXPORT ift(x)BEGIN  IFTE(x>7,print("TOO HIGH"),IFT(x<4,print("TOO LOW")));END;
03-24-2017, 06:52 PM
Post: #4
 toml_12953 Senior Member Posts: 1,478 Joined: Dec 2013
RE: Requesting ELSEIF
(03-24-2017 06:21 PM)compsystems Wrote:  I like the version ELSEIF. instead of using CASE

now with IFTE functional command version

A small survey.

you need an IFT() functional command?

I'm all for anything that makes my job easier. I actually make a living converting old programs (mostly BASIC) to run on Prime. I'd share them with the group but my employer owns everything I write relating to their business (even after hours!) I'd like both ELSEIF and IFTE. I'd also like user-defined datatypes (like records), printing and a whole bunch more. We can dream, can't we?

Tom L

Tom L
I don't care for whom you voted. If you put ice in your beer, you're crazy.
03-24-2017, 07:16 PM
Post: #5
 compsystems Senior Member Posts: 1,269 Joined: Dec 2013
RE: Requesting ELSEIF
What kind toml_12953 of programs are you converting and where can you test them?
03-24-2017, 07:33 PM
Post: #6
 toml_12953 Senior Member Posts: 1,478 Joined: Dec 2013
RE: Requesting ELSEIF
(03-24-2017 07:16 PM)compsystems Wrote:  What kind toml_12953 of programs are you converting and where can you test them?

I convert environmental programs. These were used for by our field workers for years on laptops and even some BASIC handhelds. We're equipping them with Primes now and I convert programs that monitor and analyze climate data (yes it really IS changing!) and do things like calculate how fast the liquid level in different shaped tanks such as underground tanks used by abandoned gas stations will go up or down based on the input or leakage (a lot of differential equations there). We also keep track of changing migratory patterns of birds and other animals. It's a lot of fun at times but sometimes converting the spaghetti code makes me want to hit the sauce! Gee, C, Pascal and other languages have GOTO. Why can't Prime?

Tom L

Tom L
I don't care for whom you voted. If you put ice in your beer, you're crazy.
03-24-2017, 07:45 PM
Post: #7
 Carlos295pz Senior Member Posts: 363 Joined: Sep 2015
RE: Requesting ELSEIF
(03-24-2017 06:21 PM)compsystems Wrote:  you need an IFT() functional command? (without ELSE block)

IFTE can be defined without ELSE

Viga C | TD | FB
03-24-2017, 08:16 PM
Post: #8
 compsystems Senior Member Posts: 1,269 Joined: Dec 2013
RE: Requesting ELSEIF
(03-24-2017 07:45 PM)Carlos295pz Wrote:
(03-24-2017 06:21 PM)compsystems Wrote:  you need an IFT() functional command? (without ELSE block)

IFTE can be defined without ELSE

but only HOME PRG, for CAS fails

PHP Code:
EXPORT iftHOME(x)BEGIN IFTE(x>7,print("true")); return "Done";END;#casiftCAS(x):=BEGIN IFTE(x>7,print("true")); return "Done";END;#end

iftHOME(8); returns "Done"
iftCAS(8); returns

"when(x>7,print(""true"")) in iftCAS(5) instruction #1 error, try debug(iftCAS(5))
Error: Bad Argument Type"
03-25-2017, 11:43 AM
Post: #9
 toml_12953 Senior Member Posts: 1,478 Joined: Dec 2013
RE: Requesting ELSEIF
(03-24-2017 05:38 PM)Han Wrote:  CASE blocks have similar logic to nested ELSE-IF blocks (exiting the block once a condition is met and relevant actions are executed). It doesn't make your code any shorter but can provide improved legibility.

Just to show you, here's the actual ANSI/ISO BASIC statement statement I'm converting:

PHP Code:
IF (t = 1) OR (t = 2) OR (t = 3) THEN! circle, ellipse, or hyperbola   LET Xo = -Dr/(2*Ar)   LET Yo = -Er/(2*Cr)   PRINT "translation = {"; USING$("-%.####",Xo); ", "; USING$("-%.####",Yo); "}"   LET r(1) = Ar/(Ar*Xo*Xo + Cr*Yo*Yo - Fr)   LET r(3) = Cr/(Ar*Xo*Xo + Cr*Yo*Yo - Fr)   LET r(6) = -1.0   IF ABS(r(1)) < ABS(r(3)) THEN    ! foci on x-axis      LET a2 = ABS(1 / r(1))      LET b2 = ABS(1 / r(3))      IF t = 2 THEN                 ! ellipse         LET c1 = SQR( a2 - b2 )         PRINT "foci = {±"; USING$("-%.####",c1); ", 0.0000}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      ELSEIF t = 3 THEN            ! hyperbola         LET c1 = SQR( a2 + b2 )         PRINT "foci = {±"; USING$("-%.####",c1); ", 0.0000}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      END IF   ELSE                             ! foci on y-axis      LET a2 = ABS(1 / r(3))      LET b2 = ABS(1 / r(1))      IF t = 2 THEN                 ! ellipse         LET c1 = SQR( a2 - b2 )         PRINT "foci = {0.0000, ±"; USING$("-%.####",c1); "}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      ELSEIF t = 3 THEN            ! hyperbola         LET c1 = SQR( a2 + b2 )         PRINT "foci = {0.0000, ±"; USING$("-%.####",c1); "}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      END IF   END IFELSEIF t = 4 THEN                   ! parabola   IF ABS(Ar) > ABS(Cr) THEN        ! form: x² - 4·p·y = 0      LET Xo = Dr/(2*Ar)      LET Yo = (Fr - Dr*Dr/(4*Ar))/Er      PRINT "translation = {"; USING$("-%.####",Xo); ", "; USING$("-%.####",Yo); "}"      LET r(1) = 1      LET r(5) = Er / Ar      LET p = -r(5)/4      PRINT "focus = {0, "; USING$("-%.####",p); "}" ELSE ! form: y² - 4·p·x = 0 LET Xo = (Fr - Er*Er/(4*Cr))/Dr LET Yo = Er/(2*Cr) PRINT "translation = {"; USING$("-%.####",Xo); ", "; USING$("-%.####",Yo); "}" LET r(3) = 1 LET r(4) = Dr / Cr LET p = -r(4)/4 PRINT "focus = {"; USING$("-%.####",p); ", 0}"   END IFEND IF

Tom L
I don't care for whom you voted. If you put ice in your beer, you're crazy.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)