PureBASIC Procedures : Procedure() and new one Function()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
idStefke
User
User
Posts: 25
Joined: Sun May 04, 2003 10:01 pm
Location: BELGIUM

PureBASIC Procedures : Procedure() and new one Function()

Post by idStefke »

Hey Fred

I want to like to see that there is an different of the procedures that return an value or without an value

Syntax of the statement :

DECLARE FUNCTION (BYVAL / BYREF a AS INTEGER) AS INTEGER[()]

- The keywords BYVAL => Parameters By value passed
- The keywords BYREF => Parameters By references passed


[PRIVATE|PUBLIC|LOCAL|STATIC] FUNCTION <function_name>([BYVAL | BYREF] AS <datatype|array()|struct|pointer>) AS <Return_data_type>[()]

- Scope: PRIVATE | PUBLIC | LOCAL | STATIC

RETURN (value or reference)

END FUNCTION

I hope that this added in the next update/upgrade of PowerBASIC

Kind regards
Stephane
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Re: PureBASIC Procedures : Procedure() and new one Function(

Post by Berikco »

idStefke wrote:Hey Fred

I hope that this added in the next update/upgrade of PowerBASIC

Kind regards
Stephane
:D
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

I don't know for powerbasic, but I don't find this necessary for PureBasic. You can already define the return type:

Code: Select all

Procedure.l Whatever(mylong.l, mystring.s)
Procedure.f Whatever(mylong.l, mystring.s)
Procedure.w Whatever(mylong.l, mystring.s)
Procedure.b Whatever(mylong.l, mystring.s)
Procedure.s Whatever(mylong.l, mystring.s)
Long is the default, if no type is declared. If you don't need the return value, just don't use it. VB just complicates things unnecessarily.
El_Choni
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Edit: removed my incorrect ramblings, so as to not cause confusion.
Last edited by tinman on Sat Jun 07, 2003 10:52 pm, edited 1 time in total.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

By default a procedure returns a long, no need to specify a type

Code: Select all

Procedure JustSomething()
  ProcedureReturn 123
EndProcedure

Debug JustSomething()
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

Powerbasic does have some nice things I'd like to see in Pure (such as Static variables), but the current Pure is fine for what I use it for.

On a related note, though, I'm used to using 'Function' instead of 'Procedure' and thought it would be cool if 'Function' and 'Procedure' could be used interchangeably for the same thing. This way, old code would not be affected and those users would be able to continue to use 'Procedure' if they like.

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Berikco wrote:By default a procedure returns a long, no need to specify a type
Hmm, so it does. Oh well, that sucks.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

tinman wrote:
Berikco wrote:By default a procedure returns a long, no need to specify a type
Hmm, so it does. Oh well, that sucks.
:D

If you use a=1, its also a long (by default)
So if you use ProcedureReturn, and the procedure has no type, its long
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PureBASIC Procedures : Procedure() and new one Function(

Post by PB »

> I hope that this added in the next update/upgrade of PowerBASIC

This is the PureBasic forum, NOT PowerBasic forum.
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

A quick little story: I find out about Pure Basic by accident when I was doing a search for "PB graphics library" for PowerBasic (PowerBasic is also known by its initials 'PB'). Maybe there was some similar accidental finding in this case?

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Regarding ByVal and ByRef.

You don't need byVal and ByRef.

If you are passing a String, then you pass a string. If you are passing a pointer, then you pass a long.

Pointers cause terrible confusion in other languages because they are always trying to pretend that they are not pointers.

In C they try to treat a pointer like it is really the thing it is pointing to. So you have a pointer to a String, but you try to treat it like it really is a string. This causes so much confusion that they had to invent Hungarian Notation to tell you its really a long pointer to a string (lpsz). Then their listings looks like Hungarian (hence the name)

Its so much easier to just admit that a pointer is a pointer. It is a numerical value that points to a memory location.

Then, when you want to use that pointer you call a function that accepts that numerical value, like the Peek functions or CallFunctionFast.

Easy to understand, easy to use.
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

I know what you mean, GedB. They try to make pointers 'easier to understand', but in the process make it more complicated. All we need to know is that a pointer is a long value that represents an address of something. It should be up to us to name our variables so that we remember, for example, that 'Text' is a pointer to some text ('pText'). Forgetting to do so can cause problems later when you look at someone else's code and are trying to figure out what is happening.

Pointers that point to a sequence of pointers can REALLY be a head scratcher, but can really speed certain things up if you can wrap your brain around the idea! :)

Nobody can make pointers more complicated to understand than C++, though... Well maybe 'forth' (Even asm has an easier concept when it comes to pointers).

Russell

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

pointers

Post by PolyVector »

I dun think they're a head scratcher MOST of the time... :D
you can do some fun stuff when the compiler knows it's pointer and not just a long variable...
example:

Code: Select all

Structure PlayerType
  *TargetBaddie.BaddieType
  name.s
EndStructure
Structure BaddieType
  *TargetPlayer.PlayerType
  name.s
EndStructure

;Create characters
Player.PlayerType
Baddie.BaddieType

;Name them
Player\name="Mario"
Baddie\name="Goomba"

;Set their targets (who's ass they wanna kick)
Player\TargetBaddie=@Baddie
Baddie\TargetPlayer=@Player

;Display some information
Debug "Player Name:  "+Player\name
Debug "Baddie Name:  "+Baddie\name

Debug "=== Fun Part ==="
Debug Player\name+"'s Target:  "+Player\TargetBaddie\name
Debug Baddie\name+"'s Target:  "+Baddie\TargetPlayer\name

Debug "=== Fun-er Part ==="
Debug Player\name+"'s Target's Target:  "+Player\TargetBaddie\TargetPlayer\name
Debug Baddie\name+"'s Target's Target:  "+Baddie\TargetPlayer\TargetBaddie\name

Debug "=== HEHEHE ==="
Debug Player\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\name
[/i]
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Player\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\name
WTF! LOL! 8O
--Kale

Image
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Now pay a visit to the IBasic forum and awaite it's rquests.. :)
Post Reply