SuperBASIC function for type validation

Anything QL Software or Programming Related.
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: SuperBASIC function for type validation

Post by pjw »

I cant remember whether or not WHEN ERRor is part of SuperBASIC. Q-Liberator has its own variant, as does Turbo.

Personally I prefer my own VALID% toolkit function (naturally):

ok% = VALID%(expected_type%, <variable or expression>)

It uses the standard Qdos calls to try to fetch the variable/expression on the
stack as the type you specify (int, long, float), and returns its success or not
in ok%. The advantage of this method is that its interpretation will be 100%
consistent with the S*BASIC interpreter's idea of a variable's validity.

For example x% = '1e700' is a valid integer! Namely 1. However, x = '1e700' is
not a valid float! It may not be easy to cater for such anomalies in a home-grown
validy-checking program. At least not without WHEN ERRor. Much better to let
S*BASIC do the hard work!

PRINT VALID%(3, '1e700') will return ok
PRINT VALID%(2, '1e700') will return not ok (2 being the code for float)

VALID%, including it source code (so you could, for example, add it to your own
bespoke toolkit) can be found at Knoware.no


Per
dont be happy. worry
- ?
User avatar
dex
Gold Card
Posts: 286
Joined: Thu Dec 23, 2010 1:40 pm

Re: SuperBASIC function for type validation

Post by dex »

I cant remember whether or not WHEN ERRor is part of SuperBASIC
QL ROM (post JM)
This SuperBASIC structure does not work very reliably on any QL versions other than Minerva v1.77 (or later), SMS or the THOR XVI: although Toolkit II improves the reliability...
https://superbasic-manual.readthedocs.i ... error.html


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: SuperBASIC function for type validation

Post by RWAP »

Good to see people are using and quoting from my SuperBASIC / SBASIC Reference Manual :D


Post Reply