Motivation of ASSOCIATE Construct

  • Follow


Hi,
I am just curious, what is the motivation of introducing 
ASSOCIATE construct in F2003 ? 
Is there anything (e.g. optimization, etc) beyond just providing 
a nice way to shortcut thing (e.g. long expressions, etc) ?

Thanks

0
Reply reubendb (33) 2/24/2012 4:20:08 PM

On 2/24/12 10:20 AM, Reuben Budiardja wrote:
> Hi,
> I am just curious, what is the motivation of introducing
> ASSOCIATE construct in F2003 ?
> Is there anything (e.g. optimization, etc) beyond just providing
> a nice way to shortcut thing (e.g. long expressions, etc) ?
>
> Thanks
>
I think the major motivation was to provide a shorthand name for long 
derived type names.  You can do more or less the same thing by pointing 
to the structure element.  But, pointers are frequently inefficient and 
it's certainly confusing to have a bunch of pointers that don't have 
much reason for existence.

A minor advantage to the associate construct is that it adds another 
block like construct which, if used well, can make programs easier to 
follow and understand.  Within a block, you don't have to wonder how you 
got there.

That's all I can remember about "motivation."

Dick Hendrickson
0
Reply dick.hendrickson (1286) 2/24/2012 4:40:15 PM


Yes.  I think of it as a saner version of the JavaScript with() statement.

Note that depending on the compiler implementation, ASSOCIATE might use 
pointers.  If the selector is not modifiable, the compiler can implement 
ASSOCIATE without using a pointer.  But if the selector is a variable like:

ASSOCIATE(x => y%a%b)
  x = 3  ! This sets y%a%b to 3 as well
END ASSOCIATE
end

the compiler will have to either use a pointer, do some lexical replacement 
of all instances of x into y inside the block, or turn the ASSOCIATE into a 
procedure and pass the selector as the actual argument:

call my_associate(x = y%a%b)
contains
  subroutine my_associate(x)
    integer x
    x = 3
  end subroutine
end

So the shorthand has a (small) performance cost.  But it has another 
advantage: It protects you from repeating side effects.  For example:

ASSOCIATE(x => y(foo(3))%a)
  ...
END ASSOCIATE

will evaluate the selector, y(foo(3)%a, only once even if the associate name 
appears several times inside the construct.  The lexical replacement method 
fails in this case since it would repeat the side effects.

Regards

Rafik

"Dick Hendrickson" <dick.hendrickson@att.net> wrote in message 
news:9qpsrfFfvlU1@mid.individual.net...
> On 2/24/12 10:20 AM, Reuben Budiardja wrote:
>> Hi,
>> I am just curious, what is the motivation of introducing
>> ASSOCIATE construct in F2003 ?
>> Is there anything (e.g. optimization, etc) beyond just providing
>> a nice way to shortcut thing (e.g. long expressions, etc) ?
>>
>> Thanks
>>
> I think the major motivation was to provide a shorthand name for long 
> derived type names.  You can do more or less the same thing by pointing to 
> the structure element.  But, pointers are frequently inefficient and it's 
> certainly confusing to have a bunch of pointers that don't have much 
> reason for existence.
>
> A minor advantage to the associate construct is that it adds another block 
> like construct which, if used well, can make programs easier to follow and 
> understand.  Within a block, you don't have to wonder how you got there.
>
> That's all I can remember about "motivation."
>
> Dick Hendrickson
> 


0
Reply nospam95 (822) 3/1/2012 8:15:18 AM

On Mar 1, 12:15=A0am, "Rafik Zurob" <nos...@hotmail.com> wrote:

> Yes. =A0I think of it as a saner version of the JavaScript with() stateme=
nt.

It is closer to a Lisp let expression.

Bob Corbett
0
Reply robert.corbett (96) 3/1/2012 9:34:17 AM

3 Replies
46 Views

(page loaded in 0.076 seconds)


Reply: