PB Wishlist [> 4.50 beta 3]

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

PB Wishlist [> 4.50 beta 3]

Post 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!
Last edited by Innesoft on Sun May 09, 2010 9:37 pm, edited 1 time in total.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Re: PB Wishlist

Post 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.
Windows 7 & PureBasic 4.4
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: PB Wishlist [> 4.50 beta 3]

Post by Innesoft »

@milan1612, yep.. there's a workaround for pretty much everything I posted. It's just more work than it needs to be.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: PB Wishlist [> 4.50 beta 3]

Post 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.
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: PB Wishlist [> 4.50 beta 3]

Post 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:
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: PB Wishlist [> 4.50 beta 3]

Post 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:
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: PB Wishlist [> 4.50 beta 3]

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: PB Wishlist [> 4.50 beta 3]

Post 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?! ;)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Arcturus
User
User
Posts: 14
Joined: Tue Jan 26, 2010 11:23 am
Location: Australia
Contact:

Re: PB Wishlist [> 4.50 beta 3]

Post 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)
Give a man fire and he's warm for a day; set a man on fire and he's warm for the rest of his life
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: PB Wishlist [> 4.50 beta 3]

Post 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.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: PB Wishlist [> 4.50 beta 3]

Post 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
Post Reply