I just noticed something when I stepped through one of my examples - in
this case:
$to:=New object
$from:=New object
$i:=100
$from.ptr:=->$i
$to.ptr:=->$k
$to.ptr->:=$from.ptr-> // $k = 100 at this line
The value of $k changed as soon as this line runs.

I also wondered what would happen if I initialized $to.ptr to a nil
pointer. The answer is

C_POINTER($nil)

$to.ptr:=$nil  // $to.ptr = null

Nil is regarded as null in v17.


On Thu, Feb 28, 2019 at 8:22 AM Kirk Brooks <lists.k...@gmail.com> wrote:

> Jeremy,
>
>
> On Wed, Feb 27, 2019 at 11:53 PM Jeremy Roussak via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
>
>> Objects pre-date ORDA, as you know.
>
> True. In this case what we are really talking about is 4D's object
> notation. I tend to use 'ORDA' for all the new capabilities and should be
> more specific.
>
>
>> I was simply using an object as a way of permitting a method to return
>> several values at the same time. Those values happened to be pointers to
>> variables (created by OBJECT DUPLICATE and so necessarily referenced using
>> pointers). I wanted then to copy the value in the variable pointed to by
>> one pointer into the variable pointed to by another pointer. The two
>> variables were of identical type, one having been created by duplicating
>> the other.
>>
> I find this an excellent application of using objects as containers for
> passing parameters to and retrieving values from a method.
>
> Since you mention OBJECT DUPLICATE you must be working with variables on a
> form. In that context using Form removes the need to work with pointers
> altogether.
>
>> There was therefore no reason why
>>
>> $to.ptr-> := $from.ptr->
>>
>> should have created any error at all; yet it did, and it was an error for
>> which I can find no logical explanation, particularly given that the
>> assignment did actually take place. Further, if I complicate the code by
>> writing
>>
> Perhaps you didn't create $to and $from with New object before using them?
> Try running this:
>
> C_OBJECT($to;$from;$obj)
> C_LONGINT($i;$j;$k)
>
> $to:=New object
> $from:=New object
>
> $i:=100
>
> $from.ptr:=->$i
> $to.ptr:=$from.ptr
>
> $k:=$to.ptr->  // $k = 100
>
>
> To use the code as you wrote it you must also initialize the property you
> are writing to:
>
> $from.ptr:=->$i
> $to.ptr:=->$k
>
> $to.ptr->:=$from.ptr->  // $k = 100
>
>
> But if this happens
>
> $i:=100
> $from.ptr:=->$i
> $to.ptr:=->$k
> $to.ptr->:=$from.ptr->
>
> $i:=200
>
> $k:=$from.ptr->  // $k = 200
>
>
> This was a useful exercise for me. I didn't realize you could use pointers
> this way in objects. I don't think it's a particularly good way to work
> with them but it looks like there is some fairly rigorous type checking
> going on under the hood. For example, I expected this to work:
>
> $i:=100
> $from.ptr:=->$i
> $k:=$from.ptr
>
> but it doesn't because $k isn't a pointer. However:
>
> $i:=100
> $from.ptr:=->$i
> $to:=OB Copy($from;True)
>
> $i:=200
>
> $k:=$to.ptr  //  $k = 100
>
> does work because I use the True flag to resolve the pointers to their
> values. This also points out (discovered pun) the fact that within an
> object properties are dynamically typed ($to.ptr is currently a number). OB
> Copy was a great tool in pre-ORDA days as a way to build a template of an
> object based on fields and then use it to create data objects.
>
> C_POINTER(p1; p2)
>> p1:=$from.ptr
>> p2:=$to.ptr
>> p2-> := p1->
>>
>> I get no errors, interpreted or complied.
>>
> Mixing 'classic' 4D code with 'ORDA' code is tricky. You can wind up
> spending so much time converting between the two there's just not much
> benefit. Where it excels is when you start with a new method and use ORDA
> to refactor some task in old code. Generally I will have 2/3 the code to
> accomplish the same results. Less code is better.
>
> And some things are still just faster in 'classic' 4D. Large queries for
> instance. "Large" meaning tables with millions of records or extensive
> relations. Or long loops where you are doing queries. OTOH I hear from guys
> with big applications ORDA is generally faster than SQL. In situations
> where I'm working with smaller sets (thousands or less of records) I love
> working with ORDA. And forms are just amazing using ORDA, Form, dynamic
> form variables and object notation.
>
> --
> Kirk Brooks
> San Francisco, CA
> =======================
>
> What can be said, can be said clearly,
> and what you can’t say, you should shut up about
>
> *Wittgenstein and the Computer *
>
>

-- 
Kirk Brooks
San Francisco, CA
=======================

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to