Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / To Paul - Passing by reference in v2?

Author
Message
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Aug 2013 14:52
So, this is from the Kickstarter page:


You are going to touch these things, my guess is that they are in the same area. Why not include pass by reference for functions? So we can get more out of our UDTs, arrays and lists. And write better functions. I don't think this was even mentioned in the poll. I have no idea how much work is involved. But I think it would be very useful for more complex projects. And while we are doing dynamic lists, how about a foreach command?

This is an example of what I want to be able to do:


Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Aug 2013 15:56
i like to see for each also, but more like this example.
the function get the array pointer.
for each do not copy the pos. it use the extry in this array.
above the function the .x value was changed.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Aug 2013 17:36
Markus:
Your method is also nice, but doesn't give you the index (position in the array). But why not support both?

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Aug 2013 17:53 Edited at: 2nd Aug 2013 09:25
@Digital Awakening
you don't need the brackes.
in blitzmax you can use foreach also with the object type.
you can put objects different types in it and you can loop
through the type you want (and also foreach all objects).
maybe both this syntax foreachindex i in position[].
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Aug 2013 23:50
@Markus: just reminding you that this is a family friendly forum. Expletives aren't allowed even if they're starred out. Please remove it from your post.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 2nd Aug 2013 01:25
The example does not make a proper distinction between what is reference or value. Passing a pointer is intrinsically a reference - passing what is effectively a copy is value. In most languages the default is probably by value.

Always passing by reference would be dangerous.

In C or Pascal the use of * or VAR in the parameter indicates that this is modifiable.

Procedure LookAtMe( s : string); // this is a copy
Procedure LookAtMe( var s: string); // wow - I can change it

The second example will not accept LookAtMe('Hello world') because that is not a var parameter, but the first will.

There's also the little question of the range of array parameters!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Aug 2013 09:45
@JimHawkins
Quote: "
Always passing by reference would be dangerous."

yes, at ms it is doubtful because something is byval other parameters
are byref if you not write beside parameter.

for a basic language i would expect definition like this:
Function A(a as integer) < the changed value appear above call
Function A(a[] as udt)

Function B(copy a as integer) < exact copy of parameter/array etc.
Function B(copy a[] as udt)
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 6th Aug 2013 20:48
Markus....you should try using free pascal with AGK. You can have a list of classes which you can iterate through to call methods and functions....simply beatiful!

www.bitmanip.com
All the juicy you could ever dream of!
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 6th Aug 2013 22:45
In my humble opinion, AppGameKit Basic should do as Java, Lua and other OOP languages that have no "pointer" concept (* in C and C++, or the ^ in Pascal), that is a big source of confusion, and best practices of OOP have removed the need for that.
A simple rule of thumb could be:
- Arrays, that can be roughly compared to objects (tables in LUA), should be passed by reference
- simple types (string, int, float, ecc) should be passed by values.
And that's all.
My big question is: how and when? My understanding is that Paul is not the coder of the compiler, and he have to rely on Lee, that seems to be busy elsewhere...Paul has to fix V1 bugs, close V1 with last beta, start with coding AppGameKit V2, ecc
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Aug 2013 23:38
Paul will be getting to grips with the compiler at some point to fully make it his own, or so he said in another thread.


Yes, he's me
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th Aug 2013 00:42
Marco - To be boringly pedantic (who, me?) all OOP languages have implicit pointers. That includes Lua (which is an extension scripting language and relies upon a C or Pascal or whatever "host"). Java has pointers - but they are references.

Generally, by "pointer" we mean an untyped memory reference. With such a pointer it can be given an explicit address, and pointer arithmetic can be used with it.

Pascal's ^ operator is a pointer to an allocated type, exactly like the equivalent in Java. You cannot assign a numeric value to it.

Access to lower level operating system functions (like graphics surfaces) requires pointers. Java is usually written in C because it is effectively a hardware abstraction layer. Lua is written in C.

Object Pascal allows low-level operations because it has an explicit pointer type : Pointer. These are used in very special circumstances only, and then they will probably need a type-cast to do anything sensible.

Adding call by reference to the current AppGameKit Pascal requires some fundamental changes to the language and its implementation. There is no quick fix for this.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 7th Aug 2013 19:50
Quote: "Java has pointers - but they are references."

Sorry, but this is incorrect. Believe to me, I have been many years ago a Java evangelist for IBM Italy, I read much of SUN (now Oracle) documentation, and I ensure that one of the (true) claims of Java was: no more pointers as in C.
I have also programmed commercial software in ANSI C, and I know how a source code may become messy with pointers.
Java has got no pointers, only references and pointer are not references. Maybe we do not agree on terminology, but at least on one thing we should agree: pointers may be modified, references may not modified. The Java sandbox model prevents the users from modifying anything about memory addresses.
I agree that both pointers and references refer to "memory", real memory addresses as in C or C++, or Sandbox memory addresses in bytecode bases languages.
I am sure that you have a lot of experience, but me too , so we could continue this discussion for months...anyway we can stay at ease with our own ideas and live happily
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 8th Aug 2013 09:02
Quote: "pointers may be modified, references may not modified."


That's exactly what I said. Call them what you like, in implementation terms they're pointers into some kind of memory pool or other.

It should be perfectly possible to implement call by reference etc using the Basic as it exists by declaring your own virtual heap and stack, and passing "object" indices. I would do it for fun, but I'm very busy.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-04-27 06:26:19
Your offset time is: 2024-04-27 06:26:19