Lua: Day 1

The Call to Adventure

So, it’s good I played a little with Lua as I was installing it, because the first day’s material is just not that inspiring. The big problem presented is that CSV files have some problems. Specifically, there’s no way in CSV to indicate constraints or collections. Okay, fine. That’s not really what CSV is all about. But apparently this should be enough to motivate me to keep going. Meh. It’s good I was motivated to begin with. (Like, what about XML?)

The description of Lua as a table-based language that can easily adjust to different paradigms holds lots of promise. That one of these paradigms can be the prototype paradigm is even more interesting. In Seven Languages, the only prototype language was Io and it’s fallen from popularity. When I last taught it, students poked around and realized there had been no activity on the Io community for months. (JavaScript is also a prototype language, but there’s a lot of other baggage with JavaScript.) The book doesn’t get to tables until the second day though, so enough said, for now.

From the first day, the most I can say is that Lua is a fairly typical scripting language so far. The REPL (Read-Eval-Print Loop) is a bit unusual in that you can’t just type:


and get the result


Instead, you need to explicitly indicate you want Lua to evaluate an expression, as in:


or you need to indicate you want that value to be returned, as in:

return 2015

I’ve also been doing a lot of Python recently, so the fact that Lua is not at all line-based is a nice change. You want to enter two commands over three lines like:

"Hello" print
" world"

Yeah, sure, go for it.

Lua is implemented using a “strict subset of ANSI C” (umm, quotes, yeah, they come from “Seven More Languages in Seven Weeks” unless otherwise indicated). It just uses floating point for all numbers, but does allow for the % operator. And it does something sorta reasonable when you use % and floating point numbers. 13.2 % 4 is 1.2 and 14 % 3.3 is 0.8 . (Let’s not think about negative numbers now, okay?)

There’s also exponentiation and it uses the correct precedence: 2 ^ 3 ^ 2 is 512, not 64. Expressions are otherwise unremarkable.

Booleans have the literals true and false and use real words instead of symbols (and, or, not). As I fussed about before, not equals is ~= . Only numbers and strings can be compared (and strings can only be compared to strings, numbers to numbers, not of this 42 < “43” stuff.) Strings can use single or double quotes. Use # before a string (or variable containing a string) to get its length. Use .. for concatenation. (And no, you can’t get the length of a number; I tried.)

Lua’s quite laid back about uninitialized variables and parameters. Try to print a variable that has no value and you get nil. Of course, it’s pickier if you try to use uninitialized variables in expressions. Combining this with multiple assignment leads to some interesting results:

x, y, z = 1, 2, 3

behaves as expected (if you expect x to get 1, y to get 2, and z to get 3). And

x, y, z = 1, 2

doesn’t complain, just sets z to nil (even if it had a value before). Finally,

x, y, z = 1, 2, 3, 4

just ignores that pesky extra 4 at the end.

Control structures are also fairly routine. They’re ended with end, so there’s no problem with dangling elses. The for loop makes the Pascal programmer in me happy:

for i = 1, 5 do
   print("i = " ..i)

And the loop control variable behaves nicely–it is reset to the “correct” value at the beginning of each loop. You can change it, but it gets changed back:

for i = 1, 5 do
   print("Before increment, i = " ..i)
   i = i + 1
   print("After increment, i = " ..i)

results in:

Before increment, i = 1
After increment, i = 2
Before increment, i = 2
After increment, i = 3
Before increment, i = 3
After increment, i = 4
Before increment, i = 4
After increment, i = 5
Before increment, i = 5
After increment, i = 6


And i is nil after the loop. (Since I want to practice more with GitHub, I’ll be putting programs in the repository . This is the first one out there.)

There’s also while and repeat loops (yes, repeat, like Wirth and God intended it, none of this do silliness!).

The author tosses off what I think is an important feature: Lua optimizes tail recursion. Now, tail recursion optimization was covered in detail in Seven Languages in Prolog, Clojure, Erlang, and Haskell, so maybe it’s just not that exciting. Maybe I’m prejudiced since I remember how hard it was for students to understand the benefits of tail recursion removal. But since I want to play with functions more before going on, especially since they’re first-class values and I’ve only recently grokked closure, and this has gotten long enough, so let’s hold that off until the next posting.


Leave a Comment

Installing Lua

Before ever starting, y’all can hate me because I installed Lua for Windows. From a binary. Yes, I should build it for myself. And my computer does dual boot into Linux. Well, tough. That’s not what we’re here to do today. (Maybe when there’s “Seven Operating Systems in Seven Weeks?”)

(For those who don’t automatically think a binary build of Lua for Windows is a bad idea, you can find it at .)

One nice thing about Lua for Windows is it comes with a really quick “tutorial.” Okay, it’s more like a bunch of examples, but it’s a fast way to see what Lua looks like.

Anyway, there are (at least) three syntax things that drive me crazy about programming languages:

  • how to mark comments
  • how to indicate “not equal”
  • how to handle else if

So far, Lua does not disappoint. It does have single line double hyphen comments. Good, fine, I’ve seen those before in Ada. But ah, the multiline comment is a thing of Lua beauty.

Here's that multiline comment,
folks! ]]

Yeah. Hyphen, hyphen, square bracket, square bracket. Ended of course with two close square brackets. And no hyphens.

And the not equal is almost as much fun.

a ~= b

Tilde! And it doesn’t mean match. Dammit.

It makes the else if, elseif, downright disappointing.

But if I’d wanted more of the C/C++/Java/C# family, I wouldn’t be working through this book!

Along with the Seven More Languages book, the first edition of Programming in Lua is available on line (at, so I figured I’d read that as well. There’s a sample factorial program in the first chapter:

-- defines a factorial function
function fact (n)
   if n == 0 then
      return 1
      return n * fact(n-1)

print("enter a number:")
a ="*number") -- read a number

I figured I’d try it out, so I entered it (okay, cut and pasted it) and ran it from the iExecutor that comes with the Windows version of Lua. And it failed. Damn, had the language changed so much since the first edition that this program no longer worked?

Poking around a bit, I realized that the problem was that the input line was not working. My first impulse was there had to be a typo. a ="*number") ? Really? Surely the quotes didn’t belong there; it should be more C scanf-ish line:*number) and then we’ll use number in the next line.

Wrongo. The input line is in fact correct (and I realized again that Lua is going to be fun). The problem was iExecutor. While it did run code with no input just fine, there seem to be problems in reading input. As soon as I ran the program from the command line, it was just fine. Fortunately, Notepad++ does recognize Lua and it’s easy to run programs edited in Notepad++, so all is well.

I guess I should read more about iExecutor. But Lua seems like more fun for now.

Leave a Comment

Seven Languages, More or Less (Okay, More)

or Laurie Lists Lotsa Languages Like Lua

So, when faced with a book like “Seven More Languages,” an obvious first question is “What are the seven more languages?” I was dismayed or delighted to realize I had no idea what any of them were:

  • Lua
  • Factor
  • Elm
  • Elixir
  • Julia
  • miniKanren
  • Idris

This promises to be a fun adventure.

Of course, knowing a little about a language doesn’t take all of the adventure out of it. The first “Seven Languages” used the languages:

  • Ruby
  • Io
  • Prolog
  • Scala
  • Erlang
  • Clojure
  • Haskell

At least there I had taught both Lisp (aka Clojure) and Prolog in AI classes, had taught lots of Java, so some of Scala wasn’t foreign, and had played with Ruby and Rails. Yeah, Io was, and remains, highly esoteric, but I’d heard of Haskell and Erlang and knew they’d be worth playing with. There is plenty of adventure to be had in these languages and the More Languages promises even more adventure.

There’s something in me that likes lists (Lisp and I are about the same age). So, I figured I’d pause before jumping into to Lua to make a couple more lists. Let’s start with the languages I learned first, as embarrassing as that may be since it starts with BASIC (and none of that Visual stuff either).

  • BASIC, FORTRAN, and COBOL as an undergraduate
  • Pascal in night school while in the Army (as a purely theoretical exercise, since the instructor never figured out the compiler for the TRS 80)
  • IBM 380 Assembly, Lisp, Ada, and Modula-2 in grad school

Then I started teaching and added:

  • C++
  • 68000 Assembly
  • Java
  • Visual Basic
  • C#
  • Perl
  • Python
  • Tcl/Tk

Presenting in GDG meetings added

  • Go
  • Dart
  • JavaScript and HTML

Working with K12 programs included

  • Greenfoot
  • Jeroo (a personal favorite)
  • Scratch and Squeak (and BYOB, Snap, and Blockly)
  • Alice
  • Karel
  • Lightbot
  • Robocode
  • Pivot
  • Processing

I did a little Smalltalk with the programming contest one year and some R as part of exploring big data. Should I count things like Bash, Awk, SQL, etc.? Nope, I don’t think so.

Yes, C is missing. I can probably fake my way through C, but I decided it was too ugly to learn in my grad school programming language survey class. There were a bunch of us who each had a language and during a typical class, we’d hear from the C guy, the COBOL guy, the Pascal guy, the PL/I professor and the Ada gal. That was enough C for me. (But after teaching “C++” for engineering freshmen, I’d be hard pressed to tell you why I wasn’t teaching C.) I had a friend who majored in comparative lit in college and he decided to never read Hamlet. I’ve used him as inspiration any time I’ve thought I should know more C.

Instead, I should learn Lua, I do believe.

Leave a Comment

Time for Seven More Languages

So, five years ago (really! that long ago?), I got tired of teaching the Programming Languages class out of Sebesta and decided to try something new. So, I used the book “Seven Languages in Seven Weeks” ( as the course text.

It was, well, an experience.

Nevermind that the book that was due to be published on August 15 finally showed up in November. In fact, I counted that as a positive (in an “if life gives you lemons” way) since students got to experience how many professionals get their books on new topics with programs like Beta books, Early Release, and MEAPs. And we all liked the much lower price than traditional text books and PDF version that students could carry around easily.

But for years, I’ve been lectured about how lecture is the wrong way to teach classes (trust me, the irony was not lost on my, but seemed to be on the people lecturing me on not lecturing). You should be “the guide on the side” not the “sage on the stage.” And, despite my desire to learn as much as I could about these languages, all seven of them, I soon realized that the student questions and errors would far outstrip my knowledge of the languages. So, I really did become the guide and soon added an assignment where the class would get points for figuring out things I couldn’t. That made us all happy too–they got points and I didn’t have to figure things out.

What was particularly great about the book is that the languages were not your typically Java, C++, C#, C, blah, blah, but included some that really required new ways of thinking. Yes, some students still growl at me about Prolog 5 years later, but once you get it, Prolog is a bunch of fun. Really. Trust me.

And even better, the book didn’t just do “Hello World” in each of the languages. It focused on examples that demonstrated the different features of each language. When we were adding functions to the built in integer class in Ruby in the first week, students knew to hold on tight, it was gonna be an interesting ride. (Especially when you consider most of the class had never had any experience with scripting languages, so just simple Ruby and the REPL was a bit of a shock to the system.)

It was much like a white water rafting trip. I felt battered at the end, they were certainly battered, but if you like that kind of thing, it was a lot of fun. Still I rushed back to the safety (and cruise ship stability) of Sebesta the next year. Turns out, I shouldn’t have rushed for safety quite so fast.

In listening to the students who took the course at their exit interview much later, it was a great experience and the favorite class in the curriculum for a lot of them. They really appreciated the skills they developed in the class and the exposure to so many new ideas. They realized it would be sorta useful in their futures. (It doesn’t hurt that I had some fabulous students in that class either-yes, you Travis and Levi! And yes, you others who don’t live within 10 miles of me.) So I did it again (with a bit more guidance) in 2013 and had planned on doing it with the follow-up book (titled, duh, “Seven More Languages in Seven Weeks”, While I may have fooled some students into thinking working with a language that was not supported was a way to appreciate the support languages other than Io received, it was time to try something new.

But instead of teaching this fall, I’ll be doing something else. (Please don’t ask what or why without planning on offering a job interview or adult beverages.) And one of the many things I’ll miss is not having the chance to do seven more languages.

Still, as I was teaching from Seven Languages, I found the experience of others who blogged it) to be very useful. The work of Yevgeniy Brikman at was especially useful. And since I still haven’t figured out what something else is going to be, it seemed like a good time for me to work through Seven More Languages on my own and record the experience here. It won’t be as useful an experience without students to ask questions I never would think of, but I do still carry a lot of student questions with me, so we’ll see what kind of trouble I can get into on my own.

Leave a Comment

Social Media Overload

So, I’m at Pycon. I figure I should report back, mostly to the GDG Academy people, since Python is a big deal in K12 education.

But there’s the rub. Where do I post? Since GDG Academy is on Google+, that seems obvious. But in the community page? On my page? Probably not, since I don’t “own” those spaces. So my own blog makes sense. Then post to Google+ (both home and the academy?) or send email to the GDG list or Tweet?

Damn. Let’s see how it goes. At least I’m pretty sure I won’t need to post to Ravelry.

Comments (1)

For now

My father died yesterday morning.

And since then, I’ve needed to write something about it. After all, one of my favorite quotes is from Anne Morrow Lindberg:

I must write it all out, at any cost. Writing is thinking. It is more than living, for it is being conscious of living.

But Dad’s been sick for a long time. Since his Parkinson’s came with dementia, he’s been gone in many ways for years. (Parkinson’s is ugly. Thanks Sergey Brin for what you’re doing to stop it.) When I called on Christmas 2009, it was clear the phone confused him too much, so I stopped calling after that. I last visited in June and while there was some time when he knew who I was, just being there exhausted him out as he strained to figure out who I was and how to entertain me.

But now he’s really gone.

For real.

For good.


But that little Christian voice is reminding me “For now.”

Comments (1)

Consolidation Time

So, I’ve been keeping blog entries on the Mercer Rescue Walk site ( — a pretty cool site for those who will take any encouragement to walk a few extra steps a day) and at Ravelry (for Sock Madness 2011) and since the walkertracker site has been reset once already and I’ve lost everything, I figure it’s time to get things back where they belong.  I think I can backdate posts, so this might appear after I move the ones over from those other places.  We shall see.

Comments (1)

Where the Good Stuff Went

Steps Walked: 30,294 (23,952 at moderate pace)

Inside the British Museum

Yes, I suppose walking over the Thames (4 times) might be more impressive to a walking audience, but you can only get shots like this (inside the British Museum) on foot.  We did a walking tour of the museum, which was more listening than walking, but, on reflection, it did hit all the tour book sites, including the Rosetta Stone, Elgin Marbles (they don’t like to call them that though!), and much nicer pieces of the Mausoleum than are left in Turkey.

Really.  The Mausoleum is basically just a large lot with a bunch of chunks of marble:

Shot of The Mausoleum Ruins

Bodrum, Turkey

The British Museum has some of the statues that were at the top of the building:

From the British Museum

It does lead to the question of who really should have these antiquities.  When we were in Athens, they made a strong argument that the Elgin Marbles were looted, but in London, there’s a completely different story.  I figure it’s a good thing I don’t have to be the one to make the decision.

Another walking tour around Parliament at night really added steps.  Along with seeing the big fancy lit buildings and Lambeth Palace, we got to wander through alleys still lit with gas lights.  The walking company we used (London Walks: was suggested by someone I worked with and was a great way to get us out and somewhere…otherwise, there’s so much to see and do, it’s hard to figure out where to get started.

Pret a Manger is also a good thing.  There’s one right outside the hotel (okay, in London, there’s one outside just about everyplace) and they can always be counted on for good basic affordable food.

Comments (1)

London, Day 1

Steps Walked: 21,170 (15,535 at moderate pace)

Big Ben, London

A Shot From Today's Walk

So, we took a red eye to London and got almost no sleep, but it’s London, so we literally walked ’til we dropped.  It “helped” that the hotel didn’t have a room ready until mid afternoon.  The hotel is wonderfully positioned.  We’re right across from Trafalgar Square and just down the street from Parliament.  We walked there easily, even as tired as we were.

But how else except by walking do you get this close to Big Ben?

Or see signs like this one?

Fortunately, there’s a well-reviewed pub right next to the hotel, so once we woke up again, we didn’t have far to go for dinner.  Surprisingly, there are traces of blue laws there (or maybe it’s just being in an urban setting) so it was closed.  Good thing there was a Thai place even closer that served us before we fell back to sleep.

Leave a Comment

Taking Heart

Since I haven’t been to Pennsylvania to see my father since I started working at Info Tech in September and since plane tickets were cheap and snow wasn’t in the forecast, we flew up to Williamsport yesterday.  Dad looks good, all things considered (growing old in not a task for the weak or cowardly).  We had a good visit and two more days here.

But that’s not the point of this post.

We flew out of Gainesville despite all the problems we had there when we came back from Greece.  Please don’t take this as any sort of endorsement of Gainesville Regional Airport because it really is a po-dunk one-horse place.  But maybe because it is a po-dunk one-horse place, the flight crews that come into it are, shall we say, more relaxed at times.  Every time I fly, I remember the flight announcements from an Eastern flight a million years ago, just as Eastern was failing.  The crew knew they were all losing their jobs soon and decided to go out with a smile:  “Okay, if you’ve been living in a cave for the last 20 years, I’m going to show you how to use your seat belt.”

Delta’s Connection isn’t going under quite as soon (probably) so the crew was a bit more circumspect.  Still, the flight attendant included prayer as one of the things to do as you were putting on your oxygen mask and even included it as she acted out how to don the mask.  But more interestingly was the announcement from the pilot that we would be given priority into Hartsfield because we were carrying a heart.

Okay, so there were 53 other hearts on board, but those were in bodies, not in coolers.  And, since I wasn’t sure quite what I’d see in Williamsport, I welcomed the opportunity to think about what having a heart on board meant (beside landing with no circling and getting a gate with no waiting).

Two families were dealing with significant emotions…one at the loss, probably sudden, of a loved and the other at the chance for new life (and you just  know the phrase “Christmas miracle” was bandied around that hospital waiting room more than once yesterday).  Hey, it helped to know there were people who were bigger emotional basket cases than I was.

But then I started to wonder, is it really the case that the loss was sudden?  Who are these heart donors anyway?

The Internet is an amazing place and has all the answers, some of them a bit surprising.

There were 6,011 heart donors last year.  The largest number of them died of stroke (2,471), but a lot (2,340) died of blunt injury (only 942 of these were motor vehicle accidents though).  There were 539 gun shot wound caused deaths.

What I find peculiar is there were 736 who died of cardiovascular causes.  So, the heart didn’t work in one person, let’s try it in someone else?  And there were 243 deaths caused by drug intoxication.  I guess the  drugs caused fatal damage to something other than the heart.

One thing that did come out is that almost all donors died of something sudden.  And getting into Atlanta so quickly was no fluke.  The shelf life of a heart is only about 5 hours.  You have to figure it was still in the guy’s chest when we left for the airport at 4:30 AM, since we didn’t get to Atlanta until a little after 7:00 AM.  What with rush hour traffic, surgical prep, etc. they didn’t have much time.  (That may explain why gate checked baggage took a while to come off the plane.)

And so ends today’s distracting thought.

Comments (1)

« Newer Posts · Older Posts »