SuperBasic: optional parameters that will work with QLiberator?

Anything QL Software or Programming Related.
Post Reply
User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

SuperBasic: optional parameters that will work with QLiberator?

Post by ppe »

Hi,

this might be an incredibly stupid question but for the life of me I can't figure out if it is possible to implement optional parameters in SuperBasic. What I mean is something along these lines:

Code: Select all

def proc foo(bar$,goo$)
  REM This I don't know how to do:
  if is_empty(goo$) then goo$="default value"
end def
And then being able to call foo with just one parameter:

Code: Select all

foo "val_for_bar$"
And since goo$ is passed in as empty/undefined then it would be set to the default value.

Toolkit II has PARSTR$ which lets me implement what I want this way:

Code: Select all

def proc foo(bar$,goo$)
  g$=PARSTR$(goo$,2)
  if g$='' then g$='default value'
  ....
BUT this will not work if I compile it since QLIb does not support PARSTR$ or PARNAM$

Are there any extensions or clever tricks in SuperBasic to check for undefined/empty parameter?

Thanks in advance for any tips or pointers to docs!


User avatar
RalfR
Aurora
Posts: 872
Joined: Fri Jun 15, 2018 8:58 pm

Re: SuperBasic: optional parameters that will work with QLiberator?

Post by RalfR »

ppe wrote:this will not work if I compile it since QLIb does not support PARSTR$ or PARNAM$
As TT has written in the TK2 manual. You should read it!


4E75 7000
User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: SuperBasic: optional parameters that will work with QLiberator?

Post by ppe »

RalfR wrote:
ppe wrote:this will not work if I compile it since QLIb does not support PARSTR$ or PARNAM$
As TT has written in the TK2 manual. You should read it!
I'm afraid I don't understand your comment. I have read both TK2 and QLiberator manuals. TK2 manual in my opinion does not address compiled code and PARSTR$. QLiberator manual does and it explicitly says it is not supported. That is why I'm asking if there is another way to do it using plain SuperBasic or some other SuperBasic extensions than TK2.


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: SuperBasic: optional parameters that will work with QLiberator?

Post by EmmBee »



User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: SuperBasic: optional parameters that will work with QLiberator?

Post by ppe »

Thank you very much for your help! I don't know why I didn't find that thread before.


User avatar
pjw
QL Wafer Drive
Posts: 1315
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: SuperBasic: optional parameters that will work with QLiberator?

Post by pjw »

ppe wrote:<>
Are there any extensions or clever tricks in SuperBasic to check for undefined/empty parameter?
The function VALID% from http://www.Knoware.no/htm/toolkits.htm#math can be useful in some cases. A very simple
demo:

Code: Select all

DEFine PROCedure test(t%)
PRINT HEX$(VALID%(-1, t%), 16)
END DEFine
test x%, with x% undefined will print 0003.
a$ = 'abc': test a$, prints 0201
test b$, with b$ undefined print 0001, etc
Sadly, test without any parameter at all doesnt help much.


Per
dont be happy. worry
- ?
User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: SuperBasic: optional parameters that will work with QLiberator?

Post by ppe »

pjw wrote: The function VALID% from http://www.Knoware.no/htm/toolkits.htm#math can be useful in some cases.
Thank you, Per! Will take a look!


Post Reply