Optional Parameters Anywhere.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Optional Parameters Anywhere.

Post by Shannara »

I think this is self-explainatory. But just in case ... If we can have these, then we can group the parameters in logical order instead of shoving all optionals at the end.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Image
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i guess, trond, he means

x( a , , b , c )

so you could skip one...
( 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... )
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Oh, I thought he meant:
x( a, b, c ) ; Now, which ones of the five optional parameters did we skip? How to do type checking for this, it will be a lot of work.
Thomas
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Apr 26, 2003 8:45 pm

Post by Thomas »

For example the positional parameters for ResizeWindow() if you really just want to resize and not move the window. :?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Blueznl has it on the dot.
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

I wondered on this before myself. #PB_NoChange?

;)
Intrigued - Registered PureBasic, lifetime updates user
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

I also thought that the first post meant put any parameter anywhere ... sorry Shannara. It is silly season on the boards these last 24 hours.

The idea of "empty" parameters (a,,c) is neat. An implied "No Change" or "Use Default" or whatever.
@}--`--,-- A rose by any other name ..
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i think it's not possible though :-) as all par's are (i assume) pushed on the stack, you can't push nothing on the stack, and you can't push an identifier on the stack as it may have the same value as the identifier

so i think i can predict fred's answer, and i guess it's the right one too: no :-)
( 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... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Hmmm.

Hopefully with:

Code: Select all

Procedure myProc( myPar.l = 0, myOther.l = -1, myNext,l = 10)
  ; stuff
EndProcedure
The compiler alread knows what is required when it reaches:

Code: Select all

myProc(1,,2)
So, push comes to shove, it can load the stack with:
  • 1 (it was given)
    -1 (it is the known default)
    2 (it was given)
Cross fingers.

Edit:

Btw, Blueznl, would you object if this capability was made available?
@}--`--,-- A rose by any other name ..
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Dare2 wrote:

Code: Select all

myProc(1,,2)
That just looks ugly :P
quidquid Latine dictum sit altum videtur
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

well, ugly or not, i dunno :-)

filling in anything makes it not usefull to have optional parameters :-)

but finally, i am not the one to object anything, i'm just a user! :-)
( 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... )
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

I'm sure i read somewere that optional parameters have got to be at the end of the parameter list. I don't fully understand why but it's got something to do with the internals of how PB calls procedures.
--Kale

Image
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Kale wrote:I'm sure i read somewere that optional parameters have got to be at the end of the parameter list. I don't fully understand why but it's got something to do with the internals of how PB calls procedures.
i do suspect so as well, yes :-) but hey, i'm pretty happy we do have this feature, so don't mind!
( 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... )
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

freak wrote:
Dare2 wrote:

Code: Select all

myProc(1,,2)
That just looks ugly :P
+1 ;)
Post Reply