Just as a cool point to bring up.

This is what you would consider passing by reference.

Since one object merely references something else
and does nto actually copy the data and get its
own set of data (passing by value).

So, this opens up some interesting possibilities.

Namely custom data structures among other things.

I am kind of glad allaire did this however.. I
do think it tends to confuse msot people since
I cant think of any other data type in CF that
behaves the way structures do.

CF sucks with recursion still and I would
be very afraid to use custom tags to manipulate
a custom data structure built using this
method.. (Such as a Stack of Queue) perhaps..
was there not a CFDJ article talking about this?

I cant imagine this being overly useful to your
average CF developer,
But I guess in some cases this proves to be
truly useful.



Jeremy Allen
[EMAIL PROTECTED]
Insert Quarter Here ---->[   ]<----

-----Original Message-----
From: Rick Osborne [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 01, 2000 12:56 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: StructClear


Stas-

The StructClear() function completely empties a structure; keys and
everything.  Let's extend this for a second.  Take the following situation:

   <CFSET foo=StructNew()>
   <CFSET foo.bar=1>
   <CFSET foo.quux=2>

A structure with 2 keys, right?  Now, you can clear this structure one of
two ways:

   <CFSET foo=StructNew()><!--- just start over --->
   <!--- or --->
   <CFSET StructClear(foo)><!--- just clear it out --->

There is an important distinction, however.  Remember that structures are
passed (and assigned) by reference.  So, let's assume that foo still has
some data in it, and let's add the following scenario:

   <CFSET brick=foo>

Now, whether you use StructClear() or StructNew() actually matters!  This is
because brick and foo now point to the *same data*.  Not copies of the data,
but the same data.  To show this, you could now do:

   <CFSET brick.bat=2>
   <CFOUTPUT>#foo.bat#</CFOUTPUT>

This is perfectly valid.  So, as you can see, StructClear() and StructNew()
will now do two very different things.  If you use StructClear():

   <CFSET StructClear(foo)>

Then you are acting on the reference, you will therefore be clearing out the
brick structure while you are at it:

   <CFOUTPUT>#StructCount(brick)#</CFOUTPUT>
   <!--- should show: 0 --->

But, it we back up and use StructNew() instead:

   <CFSET foo=StructNew()>

Then we are now simply overwriting foo's copy of the reference.  So foo gets
a new structure and brick stays intact:

   <CFOUTPUT>#StructCount(brick)#</CFOUTPUT>
   <!--- should show: 3 --->
   <CFOUTPUT>#StructCount(foo)#</CFOUTPUT>
   <!--- should show: 0 --->

In this way, you can see that assigning to foo does not affect brick, but
using functions that work on foo will affect brick (because the functions
take a copy of the reference, while assigning overwrites the reference with
a new one).

So, to answer your second function, you can clear a structure any way you
want:

   <!--- does not affect brick --->
   <CFSET foo="">
   <CFSET brick="">
   <!--- now the structure should be completely out of memory --->

This distinction actually has several uses, but it's a bit tricky if you
aren't wary of it.  I've helped many a CF programmer who were tearing their
hair out because they had used one instead of the other.  :)

HTH,
Rick


-----Original Message-----
From: Stas Newdel [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 31, 2000 5:45 PM
To: CFTalk
Subject: StructClear


Does StructClear reset keys in a structure to be blank, or does it remove
the keys? Also, what's a function to get rid of a structure altogether?

Thank you


----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.

----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to