syntax : pointer to an element of a sub-array of 2D array

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
I have a pointer to a 2D array
Array text($My_Array;5;10)
$ptr:=->$My_Array

I know that $ptr->{2} will reference the sub-array (of 10 elements) at
element 2.
I need to provide a pointer to this sub-array
ex:
My_Method(->($ptr->{1}))

The above syntax does not seem to work, can someone help with syntax?

Thanks!
Chip
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
It almost seems like you are doing the inverse of what is described here:
http://kb.4d.com/assetid=48814

Try this:

C_POINTER($ptr)
ARRAY TEXT($My_Array;5;10)
$ptr:=->$My_Array{1}
My_Method ($ptr)

-Tim



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list

> Le 1 juin 2017 à 22:10, Chip Scheide via 4D_Tech <[hidden email]> a écrit :
>
> I have a pointer to a 2D array
> Array text($My_Array;5;10)
> $ptr:=->$My_Array
> [...]
> The above syntax does not seem to work, can someone help with syntax?

Turnarounds I could find (execute formula, Get pointer, plugins…) always failed in some particular situation (compiled, component, etc.). While considering a 2D array is a collection of 1D arrays (columns) is safe:

• pass one column:

array text($data_a2t;5;10)
myMethod(->$data_a2t{2})

• pass all columns:

array text($data_a2t;5;10)
array pointer($arr2Dcolumn_ap;0)
for($i;1;size of array($data_a2t))
 append to array($arr2Dcolumn_ap;->$data_a2t{$i})
end for
myMethod(->$arr2Dcolumn_ap)

--
Arnaud de Montard



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
Everyone who has replied so far.
Thanks

I am still struggling with this, but I am now closer, and have some
direction, I'll report back my final solution.

The actual implementation I am working on is :
In a component, a method which can build 1 or more arrays of table and
field information from the structure of the host.
Maybe I am too ambitious...

(from Host)
 
Build_Table_Arrays(->$Table_Names_array;->$Table_num_array;->$Table_Pointer_array)
This call would build 1D arrays with the (respectively) table names
(formatted for users), Table numbers, and pointers to the tables.

The 'trick' is that I want to allow a slightly different call to the
same component method
 
Build_Table_Arrays(->$Struct_Names_array;->$Struct_num_array;->$Struct_Pointer_array)
Where $Struct_xxxx is a 2D array which will contain not only Table, but
also field information; so the resulting arrays would contain
(respectively) ALL table and field names (formatted for the users), ALL
Table and Field numbers, and pointers to ALL tables and Fields.

And this is where the dereferencing a pointer to a 2D array, sub-array
access problem is occurring, inside the component method and it's
internal method calls for parameter validation (my post on Type issue),
and for resizing the sub-array(s) for field information (this post).

<Irony on>  
*Of course*
</Irony off>
the methods in the component that do type validation, and array
resizing ALL require pointers as parameters, because these methods are
themselves ALSO exposed as part of the Utility component package I am
trying to create....   :)

... and now my head hurts again...
:)

Thanks
Chip




---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
sometimes its much easier to simply COPY ARRAY the whole array and back.

> 2017/06/02 22:46、Chip Scheide via 4D_Tech <[hidden email]> のメール:
>
> And this is where the dereferencing a pointer to a 2D array, sub-array
> access problem is occurring, inside the component method and it's
> internal method calls for parameter validation (my post on Type issue),
> and for resizing the sub-array(s) for field information (this post).




**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
Yep :)

I am not sure... Does this work in newer versions of 4D, or is this
something that should be entered as a bug?
Array text(My_2D-Array;5;10)
c_pointer($ptr;$ptr2)
$ptr:=->My_2D_Array

$ptr2:=->$ptr->{1}  // <- this fails : Field variable or table expected
$ptr2:=->($ptr->{1}) // this fails : Field variable or table expected
$test:=$ptr->{1}  // as expected this gets the value of the array at
$ptr->{1} element zero

I found a solution (workaround actually)
- As Keisuke suggested COPY ARRAY will resolve the specific
problem.(Implemented)

So:
// method to get table names etc
// For each table - get table info and if appropriate get field info

COPY ARRAY($Name_Array->{$i};$Temp_Names)
   //$Name_Array is a pointer to a 2D Text array
   //$Temp_Names is a 1D Text array
utl_struct_Field_Arrays ($i;->$Temp_Names) //populate Temp array with
field names for table $i
COPY ARRAY($Temp_Names;$Name_Array->{$i}) // copies the temp array to
the correct place in 2D array


The actual method allows the creation of upto 3 2D arrays, at the same
time, for table information
Table & Field names
Table and Field numbers
Table and Field pointers


THANKS Everyone for the help


On Fri, 2 Jun 2017 14:58:33 +0000, Keisuke Miyako via 4D_Tech wrote:

> sometimes its much easier to simply COPY ARRAY the whole array and back.
>
>> 2017/06/02 22:46、Chip Scheide via 4D_Tech <[hidden email]> の
>> メール:
>>
>> And this is where the dereferencing a pointer to a 2D array, sub-array
>> access problem is occurring, inside the component method and it's
>> internal method calls for parameter validation (my post on Type issue),
>> and for resizing the sub-array(s) for field information (this post).
>
>
>
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Jun 2, 2017, at 2:00 PM,Chip Scheide wrote:

> Maybe I am too ambitious...
>
> (from Host)
>
> Build_Table_Arrays(->$Table_Names_array;->$Table_num_array;->$Table_Pointer_array)
> This call would build 1D arrays with the (respectively) table names
> (formatted for users), Table numbers, and pointers to the tables.
>
> The 'trick' is that I want to allow a slightly different call to the
> same component method
>
> Build_Table_Arrays(->$Struct_Names_array;->$Struct_num_array;->$Struct_Pointer_array)
> Where $Struct_xxxx is a 2D array which will contain not only Table, but
> also field information; so the resulting arrays would contain
> (respectively) ALL table and field names (formatted for the users), ALL
> Table and Field numbers, and pointers to ALL tables and Fields.
>
> And this is where the dereferencing a pointer to a 2D array, sub-array
> access problem is occurring, inside the component method and it's
> internal method calls for parameter validation (my post on Type issue),
> and for resizing the sub-array(s) for field information (this post).
>
> <Irony on>  
> *Of course*
> </Irony off>
> the methods in the component that do type validation, and array
> resizing ALL require pointers as parameters, because these methods are
> themselves ALSO exposed as part of the Utility component package I am
> trying to create....   :)
>
> ... and now my head hurts again...

Here’s a crazy idea. Just provide 2 methods instead of 1 and skip all the parameter type validation.

Build_Table_Arrays(->$Table_Names_array;->$Table_num_array;->$Table_Pointer_array)
Build_Struct_Arrays(->$Struct_Names_array;->$Struct_num_array;->$Struct_Pointer_array)

Then there is no need to test for the array type pointer. As an intelligent programmer you will always use the correct method name depending on if you are passing a 1D array pointer or a 2D array pointer. Right? :)

Problem solved. Workaround found. Life continues on. Head will no longer hurt.

I totally understand if this has now become a quest to master a nuisance of the 4D language regarding pointers. It’s a tricky area for sure when dealing with 2D arrays. Sure it’s always best to "validate the hell out of” all parameters. But sometimes the answer is to just not ask the question. Like the old saying “Doctor it hurts when I move my arm this way.” And the doctor replies “well, don’t move your arm that way”. :)

Tim

********************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]
********************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
I understand your thinking  :)

but...
as this is going to be in a (compiled - I hope) component, I need to
validate the hell out of the parameters, ESPECIALLY, pointers; as
conceptually the component will be a black box.

Input (via method call) -> component -> result

actually the problems of Type testing the 2D array, and referencing 1
dimension of the 2D array WILL STILL exist even if I use 2 methods.

In many cases I can let 4D type manage parameters for me. If I define a
longint, or text as a parameter 4D will insure that that is what I will
get in the component. However, with a pointer, what does the pointer
point to?
an array, a text variable, (not in v13, but eventually) a C_Object, a
listbox etc...
So, type validation  of the item being pointed to is needed.


In the specific instance, I will have unto 3 pointers to either arrays
or to 2D arrays. I can test Array vs 2D Array, BUT since 4D does not
give us a Type test for 2D arrays (might be a feature request) that
still does not validate the type of the 2D array, Pointer, text,
longing, some other (completely) invalid type. I have found (just not
posted to other thread yet) that Type will indeed return the correct
value when I test the type of 1 dimension of a 2D array, even though a
pointer.

However, that does not resolve, and I will still have to deal with, the
issue of referencing a sub-array of a 2D array through a pointer (this
thread). As I will have to resize each array element of the 2D array to
match the field counts for the corresponding table.

However, as I recently posted I have found a functional workaround,
Thanks to Keisuke, COPY ARRAY.

Finally :
> I totally understand if this has now become a quest to master a nuisance of
the 4D language regarding pointers.
Yes  :)
Well not master so much as determine it is indeed a limitation of 4D.

Chip
On Fri, 02 Jun 2017 14:20:00 -0500, Tim Nevels via 4D_Tech wrote:
>
> Here’s a crazy idea. Just provide 2 methods instead of 1 and skip all
> the parameter type validation.
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Fri, Jun 2, 2017 at 12:20 PM, Tim Nevels via 4D_Tech <
[hidden email]> wrote:

> quest to master a nuisance of the 4D language regarding pointers.



"nuisance" (S/B "nuance")

Careful, there - that floor is slippery, Dr. Freud!  ;-)


--
Douglas von Roeder
949-336-2902
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list

> Le 2 juin 2017 à 20:56, Chip Scheide via 4D_Tech <[hidden email]> a écrit :
>
> [...]
> Table and Field numbers
> Table and Field pointers

Just a suggestion, a "combo" makes possible to code fields in a single longint in place of pointers or pair of numbers table+field. Nice to put a field reference in json, for example.  

• decimal offset
  $combo_l:=($tableNumber*100000)+$fieldNumber
...
  $tableNumber:=$combo_l\100000
  $fieldNumber:=$combo_l%100000

• bit offset
  $combo_l:=($tableNumber << 16) + $fieldNumber
...
  $tableNumber:=$combo_l >> 16
  $fieldNumber:=$combo_l & 0xFFFF

For my own I prefer the 1st, easier to read… and I don't feel concerned by max for table and field number - 32767  ;-)

--
Arnaud de Montard



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Greetings,

Using Get pointer is another way of doing as well.

C_LONGINT($iField;$iTable;$iColumn)
C_TEXT($t2DAName;$tWorld;$t2DAColumn)
C_POINTER($p2DA;$pCol2)

ARRAY TEXT($at2D;3;3)
ARRAY TEXT($atCol2;0)

$at2D{2}{1}:="hello"
$at2D{2}{2}:="world"
$at2D{2}{3}:="by"

$pat2D:=->$at2D

RESOLVE POINTER($pat2D;$t2DAName;$iTable;$iField)

$iColumn:=2
$t2DAColumn:=$t2DAName+"{"+String($iColumn)+"}"

$pCol2:=Get pointer($t2DAColumn)

$tWorld:=$pCol2->{2}



________________________________
From: 4D_Tech <[hidden email]> on behalf of Chip Scheide via 4D_Tech <[hidden email]>
Sent: Friday, June 2, 2017 7:55 PM
To: 4D iNug Technical
Cc: Chip Scheide; Tim Nevels
Subject: Re: syntax : pointer to an element of a sub-array of 2D array

I understand your thinking  :)

but...
as this is going to be in a (compiled - I hope) component, I need to
validate the hell out of the parameters, ESPECIALLY, pointers; as
conceptually the component will be a black box.

Input (via method call) -> component -> result

actually the problems of Type testing the 2D array, and referencing 1
dimension of the 2D array WILL STILL exist even if I use 2 methods.

In many cases I can let 4D type manage parameters for me. If I define a
longint, or text as a parameter 4D will insure that that is what I will
get in the component. However, with a pointer, what does the pointer
point to?
an array, a text variable, (not in v13, but eventually) a C_Object, a
listbox etc...
So, type validation  of the item being pointed to is needed.


In the specific instance, I will have unto 3 pointers to either arrays
or to 2D arrays. I can test Array vs 2D Array, BUT since 4D does not
give us a Type test for 2D arrays (might be a feature request) that
still does not validate the type of the 2D array, Pointer, text,
longing, some other (completely) invalid type. I have found (just not
posted to other thread yet) that Type will indeed return the correct
value when I test the type of 1 dimension of a 2D array, even though a
pointer.

However, that does not resolve, and I will still have to deal with, the
issue of referencing a sub-array of a 2D array through a pointer (this
thread). As I will have to resize each array element of the 2D array to
match the field counts for the corresponding table.

However, as I recently posted I have found a functional workaround,
Thanks to Keisuke, COPY ARRAY.

Finally :
> I totally understand if this has now become a quest to master a nuisance of
the 4D language regarding pointers.
Yes  :)
Well not master so much as determine it is indeed a limitation of 4D.

Chip
On Fri, 02 Jun 2017 14:20:00 -0500, Tim Nevels via 4D_Tech wrote:
>
> Here’s a crazy idea. Just provide 2 methods instead of 1 and skip all
> the parameter type validation.
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
lists.4d.com<http://lists.4d.com/faqnug.html>
lists.4d.com
Information about the 4D Tech Mailing List <[hidden email]>, 4D Biz Mailing List <[hidden email]>, and 4D Pub Mailing List <[hidden email] ...



Archive:  http://lists.4d.com/archives.html
4D Mailing List Archives - lists.4d.com Mailing Lists<http://lists.4d.com/archives.html>
lists.4d.com
4D Mailing List Archives. 4D has a rich history of community participation on our email lists. The email list archives provide a wealth of shared information and ...



Options: http://lists.4d.com/mailman/options/4d_tech
[http://lists.4d.com/images/mailman/gnu-head-tiny.jpg]<http://lists.4d.com/mailman/options/4d_tech>

4D_Tech list: member options login page<http://lists.4d.com/mailman/options/4d_tech>
lists.4d.com
Unsubscribe: By clicking on the Unsubscribe button, a confirmation message will be emailed to you. This message will have a link that you should click on to ...



Unsub:  mailto:[hidden email]
**********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Jun 2, 2017, at 5:24 PM,Douglas von Roeder  wrote:

> On Fri, Jun 2, 2017 at 12:20 PM, Tim Nevels via 4D_Tech <
> [hidden email]> wrote:
>
>> quest to master a nuisance of the 4D language regarding pointers.
>
> "nuisance" (S/B "nuance")
>
> Careful, there - that floor is slippery, Dr. Freud!  ;-)

I curse thee oh Steve Jobs for providing us with auto-correct to make people say more stupid things than they normally would. :)

Also a big thank you to Doug for breaking my balls on this one. :)

I hope you are planning to attend 4D Summit 2018 in Washington DC. I’ll be there.

Rumor has it that 4D v17 is going to be a game changing version.

Tim

********************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]
********************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
Tim:

Auto correct? Ah, OK, I'll give you that one. :-)


--
Douglas von Roeder
949-336-2902

On Fri, Jun 2, 2017 at 3:40 PM, Tim Nevels via 4D_Tech <[hidden email]
> wrote:

> On Jun 2, 2017, at 5:24 PM,Douglas von Roeder  wrote:
>
> > On Fri, Jun 2, 2017 at 12:20 PM, Tim Nevels via 4D_Tech <
> > [hidden email]> wrote:
> >
> >> quest to master a nuisance of the 4D language regarding pointers.
> >
> > "nuisance" (S/B "nuance")
> >
> > Careful, there - that floor is slippery, Dr. Freud!  ;-)
>
> I curse thee oh Steve Jobs for providing us with auto-correct to make
> people say more stupid things than they normally would. :)
>
> Also a big thank you to Doug for breaking my balls on this one. :)
>
> I hope you are planning to attend 4D Summit 2018 in Washington DC. I’ll be
> there.
>
> Rumor has it that 4D v17 is going to be a game changing version.
>
> Tim
>
> ********************************************
> Tim Nevels
> Innovative Solutions
> 785-749-3444
> [hidden email]
> ********************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
>
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: syntax : pointer to an element of a sub-array of 2D array

4D Tech mailing list
In reply to this post by 4D Tech mailing list

> Le 2 juin 2017 à 23:41, Garri Ogata via 4D_Tech <[hidden email]> a écrit :
>
> Greetings,
>
> Using Get pointer is another way of doing as well.


Don't be confident in this, it fails in at least 2 situations:
• compiled if the array is local
• in a host/component context if the variable belongs to "the other"

There is also "API Get Array Item Pointer" from APIpack plugin, but it does not work in component/host context too.

More generally, each time I use "Get pointer" (or "RESOLVE POINTER", similar), I feel like being using the "last chance solution". Better to ignore they exist. I recently found that in my own old code:
  for($i;1;10)
    $var:=Get pointer("myVar"+string($i))
  end for
Shame on me, that's an array.

I think there is a gap in 4D langage, I'd like 4D to fill it:
<http://forums.4d.fr/Post/FR/18376531/1/18376532#18376532>

--
Arnaud de Montard




**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************