Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
ourdog is Greyhound, Staffie and Ginger Cake

It was the fact that the cake wrapper was on the bed, and not on the bedside table that was the clue that triggered me to realizing that something wasn't quite where I had left it. And examining the wrapper and finding it empty and clear, I realised that something else - the remaining slice of cake - was missing completely.

Which is why in my Lua coding example today I wrote that gypsy comprises Greyhound, Staffordshire Bull Terrier, and Ginger Cake.


gypsy = {"Greyhound","Staffordshire Bull Terrier","Ginger Cake"}

But that was yesterday and - well - she's our dog, so Lisa gave her some dogfood and the gravy she loves this morning:

ourdog = gypsy
ourdog[3] = "dogfood and gravy"


Now it appears that I have just changed the copy that I made of the table called "gypsy", doesn't it? And that if I were to print out the original table, it would still contain the Ginger Cake? Well - that turns out not to be the case:

print (table.concat(gypsy," and "))

gave me:

Greyhound and Staffordshire Bull Terrier and dogfood and gravy

and looking at the two tables:

print (gypsy, ourdog)

tells me that they're one and the same:

table: 0x9e34fd8 table: 0x9e34fd8

In Lua, when you copy a table, you're really just copying the reference - in other words you're giving it another name. And if you then alter it under one name, you'll alter it under the second name too.

As a second example, I asked one of my delegates today what he called his mother. "Mum" he replied. And I asked him what his father called his mother. "Margaret" he replied (not really, I'm protecting names). "Now - if your father poured a tin of pink paint over Margaret, would you say 'Mum, you're pink'" I asked. "Yes" he replied ...




Python behaves in the same way as Lua, as does version 5 of PHP ... version 4 of PHP and Perl both replicate the whole of a list / array, and you would still have seen the ginger cake when you printed out what Gypsy's made of! The Lua / Python / PHP5 behavior also has its equivalent in C with the copying of a pointer.
(written 2009-11-09, updated 2009-11-10)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Z203 - Cat and Dog
  [62] Technical Open House - (2004-09-25)
  [96] Variable Scope - (2004-10-22)
  [547] Taking the dog for a walk - (2005-12-29)
  [744] We can offer a room, but we can't operate on a dog - (2006-06-05)
  [771] From cat breeder to Cobol to Perl - (2006-06-21)
  [2029] Also for the eyes of the cat - (2009-02-07)
  [2132] Learning about Lurchers - (2009-04-18)
  [2138] Ski bore ... train bore ... dog bore - (2009-04-24)
  [2140] Beware - giving copyright away when you upload a picture - Dogs Trust - (2009-04-25)
  [2167] Watching the tele - (2009-05-10)
  [2252] Leaping dog, Leaping horse, copyright of old masters - (2009-06-20)
  [2271] Dogs Trust, Dog Show, Newbury - (2009-07-06)
  [2295] The dog is not in trouble - (2009-07-17)
  [2450] Family Gathering at 404, The Spa - (2009-10-11)
  [2451] Gypsy says - (2009-10-12)
  [2456] Bright Eyes - (2009-10-16)
  [2496] A better design of mouth - (2009-11-07)
  [2555] Bookkeeping - (2009-12-29)
  [2689] Can my dog eat potatoes? Doggie Dietary Research, and political sleaze! - (2010-03-23)
  [2787] Sleeping in on Sunday - (2010-05-30)
  [2897] The Land of the Black Labrador - (2010-08-01)
  [3096] Contrast in pictures - (2010-12-20)
  [3324] Rabbit Shelter - (2011-06-12)
  [3338] Return trip - Dogs Trust, Newbury - (2011-06-27)
  [3530] A typical weekend?? - (2011-11-28)
  [3533] No message - just doggy pictures of the new doggy - (2011-11-30)
  [3537] Letting the foster parents know ... too little or too much? - (2011-12-04)
  [3541] I loves Melksham - (2011-12-06)
  [3553] Changes to morning routines - (2011-12-16)
  [3561] Happy Christmas ... a Christmas morning walk in Melksham - (2011-12-25)
  [3606] Gypsy and Billy enjoy the snow - (2012-02-10)
  [3625] An update on Billy the Greyhound and Gypsy the Lurcher - (2012-02-25)
  [3674] Off to walk the dogs - (2012-03-30)
  [3675] Spring 2012 - (2012-03-30)
  [3737] Postcards from Barmouth - (2012-05-20)
  [3906] Taking the lead, not the dog, for a walk. - (2012-10-28)
  [3908] Black dogs at Halloween - (2012-10-31)
  [3920] Challenge for a photographer - (2012-11-10)
  [3936] Lisa is home today ... - (2012-11-26)
  [3943] With us for a year already! - (2012-12-03)
  [4016] Red, yellow, green or pink dog? Yellow Dog Project - (2013-02-23)
  [4130] Soft furnishings up a Welsh Mountain - (2013-07-03)
  [4180] Exceptionally, I sign a petition - on a life and death issue for Irish dogs - (2013-09-20)
  [4189] Who are we - Lisa, Graham, Gypsy and Billy - (2013-10-07)
  [4316] Too many Staffies, too many lurchers - (2014-11-16)
  [4333] Misty Melksham Morning - (2014-11-30)
  [4417] Crisp morning, fast run - (2015-02-06)
  [4433] Different views of a Welsh Valley - but headed home - (2015-02-20)
  [4507] In favour of adoption rather than puppy purchase - dogs! - (2015-06-07)
  [4517] Black dog day - and Bobby still seeks his new home - (2015-09-26)
  [4526] Day trip to Lancaster - (2015-10-10)
  [4666] Spring at Well House Manor - (2016-03-27)

U105 - Lua - Tables and the table library.
  [1697] Sorting in lua - specifying your own sort routine - (2008-07-05)
  [1742] Lua - Table elements v table as a whole - (2008-08-07)
  [2346] The indexed and hashed parts of a Lua table - (2009-08-10)
  [2699] Lua tables - they are everything - (2010-03-30)
  [2703] Lua Metatables - (2010-04-02)
  [3694] Special __ methods you can use in Lua metatables - (2012-04-12)
  [3725] Lua Tables - (2012-05-10)
  [4248] Metatables, Metamethods, classes and objects in Lua - (2014-03-18)
  [4273] Dot or Colon separator between table name and member in Lua - what is the difference? - (2014-05-06)
  [4571] Lua - using modules to add your own utilities - (2015-11-04)


Back to
Remembrance Sunday 2009, Melksham
Previous and next
or
Horse's mouth home
Forward to
Dynamically formatting your results (Lua)
Some other Articles
Melksham manslaughter case concludes - sort of
Monday night, Tuesday night
Simples
Dynamically formatting your results (Lua)
ourdog is Greyhound, Staffie and Ginger Cake
Remembrance Sunday 2009, Melksham
Brown horses in Melksham
Planning the future of Wiltshire
Making Linux Politically correct
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2499_our ... -Cake.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb