Page 1 of 1

PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 5:21 pm
by Innesoft
These are all related to minor annoyances I've come across in PB, that would make life a lot easier in an otherwise excellent language. If you put even half of these in, I'll buy you cake. :o

-RandomF() for floating point randomness
-Random(from,to) instead of from+Random(max)
-Hex(RGB()) & Hex(RGBA()) currently for some reason returns $BBGGRR, instead of $RRGGBB!!! - fix?
-Forward referencing of Globals, and Procedures (making Declare obsolete) / multipass compiler
-Protected ForEach, to avoid linked-list itterator clashes in nested procedures

Edit: I know these have workarounds... I'm not asking for code in this thread. these are feature requests. Thanks!

Re: PB Wishlist

Posted: Sun May 09, 2010 5:27 pm
by milan1612
Innesoft wrote:-Protected ForEach, to avoid linked-list itterator clashes in nested procedures

Code: Select all

*CurrentElement = @LinkedList()

ForEach LinkedList()
  ; Do your work
Next

ChangeCurrentElement(LinkedList(), *CurrentElement)
That way you preserve the currently selected element and you can nest foreach's.

Re: PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 5:29 pm
by Innesoft
@milan1612, yep.. there's a workaround for pretty much everything I posted. It's just more work than it needs to be.

Re: PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 5:40 pm
by Trond
-Hex(RGB()) & Hex(RGBA()) currently for some reason returns $BBGGRR, instead of $RRGGBB!!! - fix?
It's because intel is a little-endian architecture.

Re: PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 9:28 pm
by STARGĂ…TE
-RandomF() for floating point randomness

Code: Select all

Macro RandomF(Float)
  ( (Float)*Random($7FFFFFFF)/$7FFFFFFF )
EndMacro

RandomSeed(10)
For n = 1 To 10
  Debug RandomF(2.5)
Next
-Random(from,to) instead of from+Random(max)

Code: Select all

Macro RandomArea(StartValue, EndValue, StepValue=1) 
  ( Random(Int(((EndValue)-(StartValue))/(StepValue)))*(StepValue)+(StartValue) ) 
EndMacro
 
RandomSeed(10)
For n = 1 To 10
  Debug RandomArea(-10, 10, 5)
Next
not more work than it needs to be, just 2 Macros :wink:

Re: PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 9:33 pm
by Innesoft
sigh. yeah thanks for the code everyone, but I wasn't really looking for code.. just making *feature suggestions* since this is "feature requests and wishlists"

never mind. :roll:

Re: PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 9:52 pm
by skywalk
Hi,
I agree.
But, I needed the Random code now, so here's what I use for integers and doubles.

Code: Select all

Procedure.d RandomD(Min.d, Max.d, ndec.i = 3)
  ; Create a random double  
  ; (upperbound - lowerbound) * Rnd + lowerbound)
  ;                                  0 <= Rnd <= 1
  ; The higher the ndec, the less likely a boundary occurrence. Exactly = mins or maxes less frequent.
  Protected.d x  
  ndec = Pow(10, ndec) 
  x = (max - Min) * Random(ndec) / ndec + Min
  ProcedureReturn x
EndProcedure

Procedure.i RandomI(Min.i, Max.i, ndec.i = 6)
  ; Create a random integer
  ; Note the "+ 1" in the equation for integers, NOT doubles
  ; (upperbound - lowerbound + 1) * Rnd + lowerbound)
  ;                            0 <= Rnd <= 1
  ; ndec < 6 produces rare fails slightly > Max or slightly < Min.
  Protected.i x  
  ndec = Pow(10, ndec)
  x = (max - Min + 1) * Random(ndec) / ndec + Min
  ProcedureReturn x
EndProcedure

For i = 0 To 9
  Debug Str(i) + ", " + Str(RandomI(1,10)) + ", " + StrD(randomD(1.1,9.9),4)
Next i

Re: PB Wishlist [> 4.50 beta 3]

Posted: Sun May 09, 2010 9:56 pm
by c4s
Sorry, but it doesn't make sense at all to have functions for every basic stuff.
I mean if I want to have for example a "AddOne()" function I make my own and that's it:

Code: Select all

Macro AddOne(Number)
(Number + 1)
EndMacro
Freak said something similar just a few days ago. See, we have over 1100 build in functions. Handling all of these is hard enough. So making your own set of macros is really a trivial thing. I mean what you've requested is really easy to code by yourself.


And yes, I didn't forget it's just a feature request. But we are allowed to discuss it, right?! ;)

Re: PB Wishlist [> 4.50 beta 3]

Posted: Fri May 28, 2010 10:25 am
by Arcturus
The RGB() bug is really annoying, I have been writing my own file formats and trying to interpret the header, but the program crashes because '1000' is read as '15205120' (I am using three byte numbers)

Re: PB Wishlist [> 4.50 beta 3]

Posted: Fri May 28, 2010 11:52 am
by Thorium
Arcturus wrote:The RGB() bug is really annoying, I have been writing my own file formats and trying to interpret the header, but the program crashes because '1000' is read as '15205120' (I am using three byte numbers)
As Trond said, this isnt a bug.
Intel stores values in reversed byte order, thats called little endian. If you are creating a file format you have to be aware of that. Especially if it should work on different plattforms. PPC for example is big endian.

Re: PB Wishlist [> 4.50 beta 3]

Posted: Fri May 28, 2010 3:35 pm
by Michael Vogel
c4s wrote:Sorry, but it doesn't make sense at all to have functions for every basic stuff.
I mean if I want to have for example a "AddOne()" function I make my own and that's it:

Code: Select all

Macro AddOne(Number)
(Number + 1)
EndMacro
Freak said something similar just a few days ago. See, we have over 1100 build in functions. Handling all of these is hard enough. So making your own set of macros is really a trivial thing. I mean what you've requested is really easy to code by yourself.


And yes, I didn't forget it's just a feature request. But we are allowed to discuss it, right?! ;)
There are (only?) two points why integrated functions are better than self defined macros: compatibility and speed

Compatibility could be a problem when sharing code snippets and a simple MyOwnSignumFunction() macro could produce different results than the macro of other users. Workarounds are "simple": just post also all macros added to the code or build up a commonly accepted "include.pbi" together with other PB users. :wink:

Speed differences between native and macro functions won't be a big deal for quite a wide range of functions, but not for all: I still miss some integer math functions (e.g. abs) which won't be as fast as long assembler is not your best friend...

Michal