Page 1 of 1

SuperBasic: optional parameters that will work with QLiberator?

Posted: Tue Feb 15, 2022 7:06 pm
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!

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

Posted: Tue Feb 15, 2022 7:38 pm
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!

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

Posted: Tue Feb 15, 2022 7:47 pm
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.

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

Posted: Tue Feb 15, 2022 7:47 pm
by EmmBee

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

Posted: Tue Feb 15, 2022 7:50 pm
by ppe
Thank you very much for your help! I don't know why I didn't find that thread before.

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

Posted: Tue Feb 15, 2022 7:55 pm
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.

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

Posted: Tue Feb 15, 2022 8:00 pm
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!