Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK Beginning Lua Programming ISBN: 978-0-470-06917-2
This is the forum to discuss the Wrox book Beginning Lua Programming by Kurt Jung, Aaron Brown; ISBN: 9780470069172
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Beginning Lua Programming ISBN: 978-0-470-06917-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 17th, 2010, 01:14 AM
Registered User
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Chapter 3, Exercise 5 confusion

I'm completely new to Lua and relatively new to programming, not having done more than BASIC, HyperCard, AppleScript, etc. I'm working my way through the book, but I'm stuck on Exercise 5 in Chapter3, page 114. Here it is:
-- Returns a function that appends N dots to its argument:
function MakeDotter(N)
  Dots = ""
  for I = 1, N do
    Dots = Dots .. "."
  return function(Str)
    return Str .. Dots
The question, of course, is What is wrong with this program? The answer the book gives is that Dots is not local. What I don't see is why. True, when you follow the book and do
you get
and when you do
you get
and then if you do
you get

But I don't see what that has to do with Dots. Because if you then do
you get
just like you should. It seems to me that the problem is with N, not Dots. After all, the value of Dots gets reset to "" --blank--every time the function is called.

Now I'm aware--after trying it with the Lua interpreter at <http://www.lua.org/cgi-bin/demo> (since there is no functional Lua interpeter for Windows Mobile), that making Dots local fixes the problem. What I don't know is WHY.

Help please?

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exercise 6 for chapter 2 scooter5 BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 3 August 27th, 2010 11:24 AM
Chapter 3 exercise 2 weekapaugh BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 March 11th, 2010 02:28 AM
Chapter 8 exercise 3 Will BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 8 March 4th, 2010 04:15 AM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 4, Exercise 3 DRAYKKO BOOK: Beginning Java 2 3 July 9th, 2004 02:34 PM

All times are GMT -4. The time now is 03:02 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.