Switch to force procedure output to a string...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Switch to force procedure output to a string...

Post by DoubleDutch »

A switch to force procedure output to a string could be pretty handy ($ could be appended to the procedure name).

eg:

Code: Select all

a=Len(x$)  ; output is a number

b$=Len$(x$) ; output is a string
It could be ignored if the output is already a string (so Left( and Left$( would be identical).

A side effect is that syntax would be more compatible with traditional BASICS.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

-1 :-)

Why?

Well...

Code: Select all

a$ = str$(len("-1000"))
a$ = len$("-1000")
I personally think it would just muddle up code, and I have enough problems as it is to keep my code straight :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

It would be optional, you wouldn't have to use it = no muddle for you. lol ;)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

At first I couldn't work out what you wanted, then I realised you just wanted
a way to avoid using Str. So why not just make a macro for yourself? Example:

Code: Select all

Macro LenS(code)
  Str(Len(code))
EndMacro

x$="123"
a=Len(x$)
b$=LenS(x$)
Granted, I know this means making a macro for every numeric command,
but you only need to do it once and stick it in a Residents file, and then it's
always there for you.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Another advantage is that PureBasic syntax would become more compatible with standard BASICs, thus making it easier for newcomers to become familiar with.

Mid$(x$,2,3) would work the same as Mid(x$,2,3)

If this was extended so that any datatypes could override the output from a procedure then it would be even better. If its the same as the default datatype then no conversion, else the conversion could be added to the compiled code automatically.

eg.

Code: Select all

Procedure xyz.s()
  result$="123"
  ProcedureReturn result$
EndProcedure

z$=xyz()
x=xyz.l()

The default datatype being the one specified when the procedure was created.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply