New Key Words?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

New Key Words?

Post by RichardL »

Hi,

I'm a beginner with PureBasic so may have overlooked the obvious, please excuse!

1. It would be good to have INC and DEC to increment/decrement a variable.

INC MyVariableName

is neater than:

MyVariableName = MyVariableName + 1

etc

2. SWAP(variable1, variable2)
This makes life so much quicker when writing sorting routines that involve multiple arrays

v.l = Sernum.l(n.w) : Sernum.l(n.w) = Sernum.l(n.w+1) : Sernum.l(n.w+1)=v.l

becomes
SWAP(Sernum.l(n.w) ,Sernum.l(n.w+1)

Should work with all variable types.

3. ARRAYFILL Arrayname(),Value
Great for initialising / clearing.

4. MID(String$,Posn,Limit) = Item$
Insertion is a neat way to build/modify strings.


I have acheived the function of all these suggestions by other means, but PB would be better with them.

Also, BMOVE, MEMBFILL would be nice...

My previous BASIC was 16bit GFA, so these are the things I miss when migrating programs to PB.

Apart from the standard editor, I'm acheiving results with PB... thats what counts.
jaBPe is an improvement

RichardL
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

for your #1 use this :

Code: Select all

variable + <expression>
; it's the same as
variable = variable + <expression>
; this goes for all operators that need a LHS and RHS
so instead of your:
"INC MyVariableName"
do this:

MyVariableName + 1
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

Thanks... I did not spot that one.
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Post by Kazmirzak »

You can do Swap() with a procedure:

Code: Select all

Procedure Swap(p1,p2)
  Protected temp
  temp.l=PeekL(p1) : PokeL(p1,PeekL(p2)) : PokeL(p2,temp)
EndProcedure


a=100 : b=200 : 

Swap(@a,@b)
Notice that this works for Longs and Floats; if you want to swap Words or Bytes, you have to use PokeW,PeekW, and PokeB,PeekB.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

ah, INC... gfabasic users unite! :-)

turning asm on, you could do INC a

alternatives:

a=a+1
a+1

unfortunately, there's no a++ (which i liked, as my eyes somehow confuse my mind every time i see a a+1 without an '=' sign...)
( 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... )
Post Reply