Page 1 of 2

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

Posted: Sat Jun 07, 2003 8:14 am
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

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

Posted: Sat Jun 07, 2003 10:47 am
by Berikco
idStefke wrote:Hey Fred

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

Kind regards
Stephane
:D

Posted: Sat Jun 07, 2003 5:14 pm
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.

Posted: Sat Jun 07, 2003 9:45 pm
by tinman
Edit: removed my incorrect ramblings, so as to not cause confusion.

Posted: Sat Jun 07, 2003 10:16 pm
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()

Posted: Sat Jun 07, 2003 10:18 pm
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

Posted: Sat Jun 07, 2003 10:51 pm
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.

Posted: Sat Jun 07, 2003 11:13 pm
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

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

Posted: Sun Jun 08, 2003 3:51 am
by PB
> I hope that this added in the next update/upgrade of PowerBASIC

This is the PureBasic forum, NOT PowerBasic forum.

Posted: Mon Jun 09, 2003 3:51 am
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

Posted: Mon Jun 09, 2003 12:01 pm
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.

Posted: Tue Jun 10, 2003 6:54 am
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

pointers

Posted: Wed Sep 17, 2003 9:49 pm
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]

Posted: Thu Sep 18, 2003 12:18 pm
by Kale
Player\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\TargetPlayer\TargetBaddie\name
WTF! LOL! 8O

Posted: Thu Sep 18, 2003 1:06 pm
by Edwin Knoppert
Now pay a visit to the IBasic forum and awaite it's rquests.. :)