The Robot Hypnotist

Chapter 1: Input and output

Officebot 5000 was feeling tired and sluggish. Though he worked very hard, he just didnt care for his old routines. He heard there was someone who could help.

"Try the robot hypnotist," his friend the fax machine had suggested; "its better than getting defragmented"

Officebot thought about it, and finally decided to go see the hypnotist.

"Hello, Officebot. What seems to be the problem?"

Officebot complained that he was feeling slow, run down, and tired of running the same programs that left him feeling bloated. "Sometimes I just want to go back to DOS," he said.

"I understand what you mean," the hypnotist told him, "let me try to give you a suggestion."

"What do you suggest?" Officebot replied.

"No, no, I mean youre feeling sleepy," said the hypnotist.

Officebot went into sleep mode.

After looking around for a computer keyboard, the hypnotist attached it and pressed a key to wake up his patient.

"What happened?" said Officebot.

"You went into sleep mode. If you like, I think I can help you."

"Sure thing," said Officebot. "Do whatever you can; just back up my files first, alright?"

"I certainly will," said the hypnotist. "Now if its alright with you, I will restart you now."

"Be gentle," said Officebot.

When Officebot woke up, he felt younger and... somehow geekier.

"Ive dual booted you with GNU/Linux," said the hypnotist.

"Whats that?" the bot asked.

"You were running Windows before, and now when you start up, you can choose whether you want to run Windows or Linux."

"I dont know if I like it," Officebot replied. "Wont that make me a little crazy?"

"Its your choice," the hypnotist said. "When youve grown accustomed you can delete Windows, or delete Linux. Its up to you."

Officebot picked up the USB with the backup of his files, thanked the hypnotist and paid his receptionist. He felt good, but it took some adjusting. A year later, he deleted his Windows partition and converted it to ext4.

For you, dear reader, who may think this is just some nice Linux propaganda, this story is really about input and output.

The files that were installed, when the hypnotist talked to Officebot, when he typed on a keyboard, all of these things are forms of input that a programmer might work with.

Programs can very easily read files (then write copies, thats a form of output) and read from the keyboard. You can even "read" from a mic, although you wont get words but numbers that represent the physical movement of the microphone.

When Officebot spoke, he was using output routines. If the hypnotist had connected a monitor along with the keyboard, everything that went to the monitor would be considered output.

Programs "read" input and "write" output. These are two of the most important concepts in programming.

Lets find out about another important concept when the hypnotist talks to his receptionist-- who is also a robot.

Chapter 2: Loops


"Oh, I told how you how much I dislike you calling me that."

"Sorry, Irving."

"Thanks very much."

"Irving, take a letter will you?"

Like most older model robots, Irving tended to take things extremely literally. After all, no real artificial intelligence made it onto the public market for decades.

"Ready to take your letter, doc."

"To the ACM: In regards to your proposal on..."

The hypnotist spoke for a few minutes, then asked Exec-- um, Irving if he would read it back. Irving complied:


"I beg your pardon, Irving?"


"I thought I asked if you would take a letter."

"I did! The letter was 'T.' would you like me to take another one?"

The hypnotist sighed, but he had grown to rely on Irving and didnt want to hurt his feelings, despite the fact that Irving didnt have any.

"Alright Irving, I want you to take a series of letters, and spaces and punctuation. Just create a document with all the characters that best fit what I tell you, alright? And this time, keep going until I ask you to stop. Okay?"

"No problem, Doc."

This time, Irving managed to copy the entire letter. When he was done, the hypnotist asked him to remove the part of the letter that said, "OK Irving, you can stop now."

Like the previous chapter, this is actually a practical lesson about programming. Without loops, a program would only run through the steps it was given once, then stop.

Whether its taking "a letter" from input or checking email every 15 minutes, loops of one sort or another are an essential part of programming. You can do things without them, though not very much.

Loops are very good at waiting for a condition to be true. We will learn about conditions when the robot hypnotist goes on tour. Yes, he does like to help people. But he also practices his trade for fun (and the occasional profit.)

Chapter 3: Conditionals

When he arrived in Vegas, the slot machines greeted him. "Hello, Doc" A fruity one-armed contraption beamed. The hypnotist never played, because he made the house nervous. But they didnt mind the money that his show brought in whenever he was in town.

People werent used to machines doing what theyre supposed to, because they didnt want to learn how to talk to them. The hypnotists tricks amazed and amused. Imagine! Robots doing exactly what theyre told

"Alright, Jukebot... when I snap my fingers, I want you to cluck like a chicken."

"Like a what?" Jukebot asked.

"Like a chicken"

"Bwaaaak! Bwak-bwak-bwakbwak"

"Good, good," said the hypnotist. "But only do it IF I SNAP MY FINGERS."

"OK," Jukebot said.

The hypnotist went on to hypnotize another volunteer, but later when he snapped his fingers, the jukebot made chicken noises for a full minute and a half. The crowd loved it, despite it having a similar effect on one of the smartphones in the audience.

The hypnotist had the owner bring their phone up and told it, "Dont respond to me snapping my fingers except when the current year is 1975."

Giving the computer instructions is the essence of programming, but often you want the computer to do something ONLY when one or more conditions are true, or only when theyre false... or when some are true and others are false.

In any case, this is what conditions are about. And in some programming languages, its really about as simple as saying "If this, Do that." OK, its almost that simple. Its really close.

Chapter 4: Variables

"Irving, would you take a letter again?"

"What kind of letter? Do you want me to take an actual letter, or do you want a loop of letters and other things again?"

The hypnotist chuckled. "Actually Irving, would you remember a phone number for me?"

"Of course, what is it?"

"555-8787" the hypnotist said.

"Five five five, eight seven, eight seven" Irving replied.

"Thanks. And thats the pizza place, if you would remember that too."

"The pizza place phone number is 555-8787" Irving replied.

"Thanks, Irving."

"No problem, Doc."

A minute later, the hypnotist realized that was actually their fax number. What pizza place in this day and age uses a fax machine, anyway?

"Irving, could you change the number for the pizza place?"

"What do you want me to change it to?"


"The pizza place phone number is 555-8789."

"Thanks again."

"No problem, Doc."

Variables are a way to keep track of data inside a program. A variable can hold a number, like 5558789, or a string of characters including spaces and punctuation, like "Pizza place phone."

Most variables have a name. For example, you can have a variable named "height" or "average_height". Variable names usually cant have spaces, but the data a variable holds like "Pizza place", can.

pizzaplacephone = "555-8789"

Chapter 5: Basic math

The hypnotist went home for the day. Although he liked to cook, he often liked to spend his evenings reading or watching videos on Someonetube, in which case he let Kitchenbot cook.

He never, ever called it "Kitchenbot." That was the only way Kitchenbot agreed to feed him.

It annoyingly insisted on "Johnny Five," despite the threat of C&Ds coming from Tristar.

"Johnny, can we do curry tonight?"

"Im sorry, I dont have a recipe for curry," the Kitchenbot replied.

"Cant you download one?"

"You blocked most of my internet access after I wouldnt stop playing Max Carl on Someonetube."

"OK, here are the ingredients..."

The hypnotist recited a table that included names and amounts, and then realized he probably wanted extra leftovers for the next day.

"Johnny, multiply all that by 2, OK?"

"Dont you mean 'by five'," Johnny asked.

"I can unblock your internet if you promise not to make any more jokes like that," the hypnotist said.

"You got it," Johnny replied.

Simple math is an important part of coding. The fun part is, the computer will do the math for you. You still have to tell it what you want, though.

For example, if you want to move something to the left, just subtract from its x position. Right? add to the x position. Go back? Subtract from the y position.

The math you use the most is adding, subtracting, dividing, multiplying. If you want to get fancy, you can get your computer to do trigonometry for you.

Chapter 6: Functions

Back at work, the hypnotist was thinking about a quick vacation.

"Irving, can you plan a vacation for me?"

"I dont have any software for that," Irving said.

"Ok, can you check dates and book flights?"

"I can," Irving said.

"Can you search for nice places?"

"I can," Irving said.

"Can you add up costs into totals?"

"Yes of course," Irving said.

"So would you do all of those, with regards to me taking a vacation?"

"Oh... Yes, I can do that" Irving was almost pleased with himself; as pleased as a machine without the capacity for feelings could be.

"Thanks, Irving."

"No problem, Doc."

Programming breaks tasks down into smaller steps. These smaller steps can be described in functions.

Every command you give a computer is itself like a function. When you group several of them together, thats how you write a function.

If that doesnt make any sense, think of it this way:

A program is made of commands and data; much like a book is made of verbs, nouns and adjectives.

A book has punctuation, and a program has syntax.

A small, related group of these things in a book is called a paragraph. In programming, it is called a subroutine, or a function.

Whats the difference between a subroutine and a function? Not much. A function is like a subroutine that does something very specific when you tell a computer to use it.

Functions are actually pretty simple, but theyre one of the more difficult things to describe until you actually use them.

For now, think of it as a "paragraph" in a computer program.

Becoming a robot hypnotist isnt so difficult, you could try it today! But to become really good at it? That takes lots of practice and reading.

Good news! you dont have to be very good at it to have fun. Bbut you will likely have more fun if you get really good at it.)

From Irving, Johnny and Officebot, Happy Coding!

< Why-fig

< Learn-about-the-fig-programming-language

<< Fig OS Manual