Monday, December 30, 2013

Lesson 44 - Pentagram

Today we started with some math. The task was to calculate the correct angle for drawing a pentagram, where the you turn around 720 degrees, i.e. two full circles. So we calculated 360 * 2 and then divided it by 5 to factor in the 5 vertices of the pentagram. It proved non-trivial to write and read numbers in the range of 0..1000, so we did some practise on that too.

Then we wrote the program on paper first and I drew the pentagram for her there, simulating the Turtle Roy environment with pen and paper. So, here's her sketch.



She remembered that you use sequence or s to do things sequentially and that you have to put the things into a list. She didn't remember the repeat or r function that is used to repeat things. I explained her that you have to wrap the repeated things in parentheses and she drew huge parentheses around the sequence. Will she remember that later? Will see.

At first she was not very enthusiastic and was very slow and sleepy. But she picked up speed quite quickly and in the end she wrote the program to Turtle Roy all by herself, copying it from the paper sketch.

Right now she's teaching mom the same things. She really enjoys teaching people so this is good. And they both learn coding from each other. Win-win.

Using pen and paper first feels good. Will use more often.




Oh and meanwhile the younger girl had painted herself a dark brown Hitler moustache.

Saturday, December 21, 2013

Lesson 43 - Back to the Roots

It's been a while since we've done stuff on the command-line, so today it was time to get back to basics. So we wrote a birthday song for the Owl. It was fun using vim again. What we made was a simple 4-line script that recitates the Happy Birthday song. Once again, we had to set file permissions using chmod etc. She was quite proud of the result and ran the script several times. She even brought the Owl (a teddy one, made by mom) to listen to the song.

Then we made another birthday song using Scratch, featuring a rocking owl and her singing. Was fun. No time to write more.

Friday, December 13, 2013

Sudden Breakthrough

Today, while I was happily hacking some Haskell in the livingroom and assumed the girls were playing, they were actually coding. She had assembled her first Scratch script by her own, combining three elements:
  • When "green flag" is clicked
  • Wait 1 second
  • Say "Hello"
I'm quite impressed that she knew where to drag all these elements from: you have to switch to a different tab containing about a dozen different elements. Yet she had managed to do this all by herself.

So now when you click on the "green flag", Santa Claus says "Hello". Santa is a figure she drew earlierly. With a little help from me she made Santa Claus play a drum beat and the other guy sing. (you can record your singing with Scratch too). She's in fact coding right now, trying out different drum beats. Gotta go, she wants to show me something!

Lesson 42 - Answer to the Ultimate Question of Life

We had another Scratch session a couple of days ago. I forgot to blog about it and now I can only say that we made an animated crab that said "Hello" and made some awkward moves.

Sunday, December 8, 2013

Lesson 41 - Painting and animation

For the record, we did some painting and animation stuff with Scratch yesterday. Maybe we'll come up with an interactive xmas card by xmas. Maybe with something else. I'll try to sneak in as much programming as possible. 

Yesterday it was just a simple sequence of "repeat forever: wait 1 second, next costume". In scratch the different animation frames for the sprites are called costumes. Why on earth?

In general, I'm still quite impressed by Scratch. I'm sure we'll be spending countless hours hacking on it. The downside is that you don't learn typing with it, because you can just drag and drop stuff around. So, we'll keep up our other activies too. Learn typing on the command-line and geometry and math in Turtle Roy.

Monday, December 2, 2013

Reaktor Kids Kode Skool III - Scratch

Today we had our 3rd Reaktor Kids Kode Skool event at the office with 8 (or so) kids. This time we tried the Scratch learning environment. And it was great fun. With Scratch, you can assemble simple (and even complex) programs by dragging visual building blocks together. It's easy to move and animate sprites (figures), add sounds and control logic to them.

It was fun to find out that you can use similar structures as you'd use in Turtle Roy, for chaining and repeating things. But in Scratch you can compose them visually, which seems to make the program structure easier to build and understand.

I strongly recommend trying out Scratch. It took me like 30 minutes to familiarize myself with the system before the event, so that I can show it to the others. Before that I had only heard about Scratch, so you can say I started from scratch.

Here's a video depicting one of the greatest masterpieces produced by the kids. I hope you won't get an epileptic seizure from watching this.

 

Sunday, December 1, 2013

Lesson 40 - High fives, Low fives

Today we started with a discussion on typing. She often struggles with finding the letters when typing, and thus types slowly. I show her how cool touch typing is by typing everything she said while she was speaking, without looking at the keyboard. And she got interested. I was afraid her hands are too small for touch typing but in fact she was perfectly able to place the four fingers of her left and right hands on top of the letters ASDFJKLÖ. Then we pracised typing those letters without moving any fingers. Then a bit with her eyes shut. I think we might be able to learn to touch type if we just practised hard. And in fact that might pay off too. If you can type without looking at (or even thinking about) your hands, you'll free a lot of brain capacity for higher-level functions, right? Dunna.

Then we tried changing the keyboard repeat rate using System Preferences. She tried different rates and ended up with the fastest possible, of course. We practised switching windows with Cmd-Tab as well as by pointing at the windows with the trackpad cursor. I tried to convince her that Cmd-Tab is way faster but she didn't buy it.

Next up was writing a Christmas wish list with vim. First we discussed what the file should contain (a line for gifts, another for food, third for company and a fourth for songs). Then I left the room and let her work on her own. In 5 minutes she invited me back and the file was like this:

    parpi vauva kemiaa

That translates roughly to "barbie, toy baby, chemistry set". We didn't make it to the second line this time. Instead we saved the file and copied the contents to the clipboard using

    cat lahjat|pbcopy

And then sent it to mom in email.

This lesson was fun and relaxed. I pretended to fall asleep each time she did things slowly and that was fun for both. When she succeeded, we did high fives with hands and low fives with feet. That's it!

Sunday, November 24, 2013

Lesson 39 - King of Polygons

Today it was time to get back into action and actually implement the function for drawing a polygon with an arbitrary number of edges.

We started by recapping how to calculate the vertex angle:

    360 / n, where n is the number of vertices

She has indeed forgotten all about this calculation, but she remembered the number 360.

Then we started working on the actual function. After maybe 15 minutes of discussion and typing (5 mins allocated for picking a name as always) we came up with

    let polygon k=r k (s [fd 50,rt (360 /k)])

Dead simple for a coder but daunting for a 4-year old. When explained, it's not very complex yet. To draw a polygon with k number of edges, you repeat the following k times:

  1. Move forward 50 pixels
  2. Turn right (360 / k) degrees
So, it was hard but it paid off. After struggling with the first polygon as in

    polygon 6

She got crazy and drew all polygons up to 14 edges. Then they didn't fit into the Turtle Roy display anymore and we had to change her program a bit using the Turtle Roy "editor mode": we added fd 20 and lt 180 to the start so that she can squeeze in a couple more polygons. You can check out the end result here.

She was indeed so enthusiastic about polygons that she gave Mom a lesson too. Together they hacked the program so that it moves only 10 pixels at a time, so that they can draw the King of Polygons: the Hectogon. It looks like a circle, actually.

Saturday, November 23, 2013

Lesson 38 - Geometry and Math

Today she was totally against the idea of having a lesson. So we decided to discuss our goals instead. What do you want to learn to do? She drew a snowmanlike figure on the paper and told me she'd like to be able to draw the same thing with Turtle Roy. 

Then we discussed geometry. How many degrees in a circle? Agreed on 360 and that it's a big number. Practised writing it. Then discussed the priciple of drawing a circle with a computer: go forward just a notch, then turn left a notch. Repeat until done.

To my surprise she wanted her snowman to be made of hexagons instead. How to do that? What are the angles of the vertices? Back to basic arithmetics then. What if you had 4 wieners and had to split them for 2 people. She solved that just fine. Then I wrote down

    4/2

And explained that when you divide 4 by 2, you write it down like this and the computer will be able to solve the problem for you. So, if you want to know the angles in a hexagon, you're gonna have to split the full circle (360) into 6 equivalent parts. We practiced writing

    4/2
    10/3
    360/6

On the paper. Then she wanted to know the answer and "asked the computer". She was quite sure though that a decagon does not exist. I told here that anygon is in fact reality, i.e. you can draw a polygon with an arbitrary number of equivalent vertices. We agreed to create a program for drawing a polygon with any number of vertices tomorrow. That, in fact, is a great exercise in programming!

Then, on her request, we click on all of my bookmarks (we used my computer this time) and I explained what they do. Google Maps was especially interesting. We discussed continents, countries, borders and such. Now she knows that Richard is in fact from Africa, because Cameroon is a part of it. I guess she's starting to grasp the notions of country and continent.


Any Publicity is Good Publicity

I just realized that it's been more than a week since our last proper, documented Lesson.

Since our previous lesson, stuff has happened, though.

We had our 2nd Reaktor Code School on the 12th, with a room (a bit more than) full of kids and parents hacking on Turtle Roy.

Then we've had a couple of interviews with the newspapers. Mila got to demonstrate her proficiency on both Helsingin Sanomat and Hufvudstadsbladet. She had a good time talking about computers and stuff with the reporters.

But I think it's time to get back to business today. The question is though, what next?

Monday, November 11, 2013

37 - hiiri

Yesterday I told her that she can send a link to any of her Turtle Roy programs by email to her friends. She got quite excited and wanted to send links to her cousins immediately. The problem was she didn't have an email account so I promised we'll do it later.

Today I set up a Gmail account for her use and configured Apple Mail to use it.

Then we asked mom to send her an email. And so she received her first email from mom. She replied to it with ease. It seemed that the email program was quite easy to use for her. But hey, what would you expect from a vim user?

Then she wanted to send daddy a message too. I showed her how to do that and she typed my email address and all quite well. Then I explained the idea of the subject field and the message body and asked her what she wants to write. I suggested that if she doesn't have anything particular in mind, she could simply use "hello" as the subject. 

In fact she did have something particular in mind.



Just "hiiri". No questions asked.

Sunday, November 10, 2013

Lessons 35-36 - Parametericity

Yesterday we continued with our music project by defining functions taa and titi, so that we can now play an eight and quarter notes as well as a double eight-note. Like

    let ti n = play n 500
    let taa n = play n 1000
    let titi n = s [ti n, ti n]

Today we recapped on that after discussing functions, parameters and other topics. Then she suggested we define yet another function "taa-a", that would be a half-note. And when I asked whether it should have a parameter, she said yes. Did she understand the question?

Anyway, she started typing

   let taaa

Then I asked her what the parameter should be called. First she said "lintu" which means the E string of the violin, but then thought a bit and corrected: we should use n so that we can play any note. The name of the parameter doesn't matter of course, but I think she's starting to grasp the concept of functions and parameters already.

Then she implemented the rest of the function, with some tips from me:

    let taaa n=play n 2000

She remembered the function play. When I asked her which note we should play, she said n. I think that's quite incredible. She almost got the number two-thousand right, too. As in 200.

Sunday, November 3, 2013

Lesson 34 - Wheel of fortune

Am I running out of descriptive titles for posts?

Today we continued on our professional audio API project.

The goal is to create functions for playing the familiar "taa" and "ti" notes (quarter-note, eight-note) with different pitches. This requires us to write functions with parameters, which isn't actually entirely new to us. So, we want a function that can be used to play an eight-note of any pitch. For example to play C:

    ti c

The "c" here actually refers to the frequency of the C note (261.63 Hz) and is a parameter of the function "ti".

We wrote the "ti" function like

    let ti n = play n 100

This translates to "to play an eight note of frequency n, you should plan the n note for 100 milliseconds". I explained the idea of a function parameter to her so that when you call the function, the parameter n will be replaced by the note you give to the function. And used a couple of examples.

Then we tried the function like

    ti e

And it worked like a charm. Then she wrote the similar function "taa" mosly by herself. It worked too. I'm glad she used a different arbitrary name for the function parameter, to illustrate that the computer doesn't really care about the names; they are merely for us humans to care about.

Then she saved the file.

    save "nakki"

Arbitrary names seems to be the way to go. We'll continue our program next time.

Why Wheel of Fortune? It's just the movement she makes with her hand while looking up the letters on the keyboard. Circling around the keyboard like an eagle looking for prey. Not that she misses often.

Saturday, November 2, 2013

Lesson 33 - Little Star

Tonight, after her violin lesson, while eating oatmeal, I reminded her that the violin notes are indeed sequences of actions, where each note is an action. She then asked me whether she could make a "karhu titi" program in that Turtle Roy thing. She meant a program that would play two short notes using the lowest string (G) on the violin. And I was like, yes you can.

So we started by opening our previous work "kielet" in Turtle Roy:

    ls
    open "kielet"

Now we had a function named "karhu" at use. This function plays the note G. She knew that we need a sequence of two "karhus" to complete our program and she started by defining a new function "karhutiti". It, once again, took quite a while to decide on the final name of the function, but we finally settled with "kt". Actually the long discussion on naming got her to lose her focus... and she didn't remember what to do after

    let kt

So I had to remind her of the equals-sign that follows. Then it was time for function implementation. She remembered that the "s" function can be used to make a sequence, so

    let kt = s

Surprisingly she didn't remember that square brackets are used in lists. I guess she wasn't in the "zone" anymore. But after reminding her about the square brackets, she hacked the function together pretty quickly:

    let kt = s [karhu, karhu]

She tried it and it worked! After another long discussion on naming, we saved the work using

    save "sei"

I asked her are we done, and she wanted to do more. Particularly she wanted to add more pictures to her HTML scrapbook, but I refused that as a too heavy a task just before bedtime and suggested some simple drawing with Turtle Roy. 

Then she asked me what I'd like her to draw. I suggested a right angle and she started writing a new sequence of things, but we were interrupted by her baby sister who wanted to perform Twinkle Twinkle Little Star in both Finnish and English. 

That was indeed pretty cute.

Tuesday, October 29, 2013

Lesson 32 - More HTML

Today we continued our HTML scrapbook project.

This time we downloaded a picture of a motorbike and opened in vim, because she insisted on doing so. This is how it looked. Behind the vim window, there's the actual motorbike in the browser.



Then we went to edit the "kuvat.html" web page and added a new image tag, pointing to the local file we just downloaded. She writes quite well now, but insists on writing "pyärä" instead of "pyörä". It's a west coast thing.

Now there are two pictures in her scrapbook. I added some CSS to make it look a bit better. She was in a hurry to go to the kitchen to bake cookies, so I guess learning CSS will have to wait...

Thursday, October 24, 2013

Lesson 31 - HTML

Today we had a lesson again just before bedtime.

I suggested we do some music stuff with Turtle Roy but she was like "naa, I wanna do vim stuff and go command-line again, it's been a while". So there we went.

We started working on a little scrapbook HTML page. So we fired up vim again.

    vim kuvat.html

She did well. She remembered how to enter insert mode and all. The first thing we added was this:

    <img src="">

What a bunch of meaningless noise that is, isn't it?. I tried to explain that this is an HTML document where you have to have "tags". This particular one is an image tag and the src attribute is used to point the location of the image. She didn't seem to pay much attention. I'm sure she was thinking along the lines of "this markup lang involves way to much boilerplate".

The next thing was to find her first picture. After some discussion we went googling for robot pictures and found one (picking a suitable search term and selecting the picture took quite a while indeed).

The hardest thing on this lesson was copying the image URL to the clipboard (she needs both her hands to do that). And then of course the notion of clipboard was entirely new to her. She insisted on having a look at the clipboard and I tried to explain that you cannot see it because it's inside the computer. You just have to believe that the URL is now on the clipboard honey. Cannot blame her for some scepticism here. State that's hidden from the user, waddup?

Finally we got back into vim and managed to paste the image URL between the quotes in the img tag. And POW! There was our first HTML document. She was quite disappointed in not seeing the picture in vim. But hey, all the WYSIWYG editors are crap, right?

Finally we opened it in the browser from the command-line using

    open kuvat.html

That was it! I hope we'll collect more fancy robot pics in the same scrapbook later. Maybe learn more HTML too.

Wednesday, October 23, 2013

Reaktor Kids Kode Skool

Yesterday we had the first "code school" for kids at the Reaktor office in Helsinki.

There was about ten parents and even more kids of ages 4 to 10 and we mostly played around with Turtle Roy. I had a very brief intro on the projector and then the kids and the parents just started coding together.

All the kids seemed amazingly concentrated and excited about programming to my surprise. I was prepared for a 30 minute session or so, but they just kept on coding! Only after 1 and half hours the first ones started to leave.

Here are some of the works the kids saved:

Check out the concentraction here:



Most of the kids and daddies took notes too. This was one of the cutest:



That was amazing! And what's more amazing, I got volunteer daddys to organize the next meeting. Good times!

Sunday, October 20, 2013

Lesson 30 - Bear and Daddy

She's learning the violin using method called Colourstrings, where they call the four strings of the violin with names karhu, isi, äiti, lintu (bear, dad, mom, bird in English). 

Today we started teaching the computer how to make the sounds karhu, isi, äiti and lintu. We started by trying how the bear (note G) sounds.

    play g

We played that in unison a few times and it seemed to be in tune with the violin. So we declared

    let karhu = play g

Next was isi, i.e. the note D.

    play d

That also sounded alright, but it revealed to us that our karhu was actually an octave too high. So we redefined 

    let karhu = play g/2

And that sounded perfect. Then we defined

    let isi = play d

And we were done with her patience. Next up: äiti, lintu.

Friday, October 18, 2013

Lesson 29 - Sequencing sounds

She has started to play the violin and likes to sing, play, dance and compose her own songs. Today I added some music capabilities to Turtle Roy to see if we can combine music and programming in our sessions.

First we tried the new play function. The function accepts any frequency and plays it for 500 milliseconds. There are also some predefined notes (c,d,e,f,g,a,b) that can be played.

So we started with

    play c

Then, to compose a sequence of notes into a single action, we used the familiar s function, and this is her first composition on the computer:

    s [play a, play b, play c]

Simple stuff, but demonstrates how you can use the same constructs (functions, lists, sequencing action) to do different things, including speech, music and graphics.

That was enough for today for her. Not for me though. I wanted to introduce parallel execution and multiple sound channels, of course. So now you can

    par [play [c,d,e], play [e,f,g]]

This means she can compose polyphonic music using functional programming techniques. How about that?

It was also fun to discover that the verbs compose and sequence apply to both programming and music and mean closely the same thing. It also occurred to me that music notes are just programs. 

The composer is a programmer and the musicians are CPU cores.

Monday, October 14, 2013

Lessons 27-28 - Haskell and Vim

A couple of days ago we had a lesson where we integrated a bunch of skills. 

We split the iTerm2 window into two panes using cmd-D and then started working on a new program file in the left pane. The coding assignment was to write a Haskell program that asks you "who are you?", then waits for keyboard input and finally greets you like "hello, Juha". 

It is known that there are only 2 hard problems in computer science, namely cache invalidation and naming. We haven't started coding for the browser yet, so for us, there's only naming. After a long consideration, she decided to name our program "housut" (pants). Then she typed it "hosut" and refused to correct the typo. So, we started editing "hosut.hs".

We wrote a single line of code:

    ask=say "who are you"

Naturally it took us a lot of time to decide what we should name our function that asks "who are you". But hey, that's what daddy does at work too. Strugglees with several layers of caches and, of course, naming.
    

The we moved to the right-hand side iTerm2 pane and started the Haskell REPL, namely ghci. Practically that is an interactive environment for running Haskell code, typed on the command-line, or loaded from a source file. We loaded our source file in ghci and called the ask function:

    $ ghci
    Prelude> :l hosut.hs
    Prelude> ask

It worked! But that was definitely enough for that lesson. She ran away and started playing with her sister. But a while later she returned to the computer, started Turtle Roy and drew a rectangle all by herself!

Today we also had a very brief session before sauna. We added a second line to the saved program at "hosut.hs".

    hello = i >>= say

This little function gets user input using the function i and "pipes" the result to the say function, using monadic composition, i.e. the ">>=" function. So there we are, working with Haskell monads in vim. And that was it for lesson 28!

Oh btw it's a pity that people find monads hard to understand. In the example, we were chaining two IO actions together using the monadic bind (>>=). So, for IO and many other monads, the monadic interface just gives you a nice way to "pipe" actions together. An equivalent way to implement hello, using so-called do-notation would be

    hello = do
      name <- i
      say name

That's more like the BASIC programs I wrote as a kid. But why introduce the overhead? Do-notation is just syntactic sugar for monadic composition. Of course, in a more involved example, it would make more sense. Like

    hello = do
      say "what's your name"
      name <- i
      say "what's your salutation"
      salutation <- i
      say ("hello " ++ salutation ++ " " + name)

OOPS, this is starting to become a monad tutorial. ABORT!

Monday, October 7, 2013

Girl B

Today, while waiting for my older daughter to get ready for her lesson, we started a Nerd Preschool with the younger one, who's almost 2. We discovered the mouse (cursor) on the screen and practised moving it around. The target was to start Terminal and then close the window using the red circle in the corner. And that was fun. We did it many times. 

The trackpad is indeed quite hard compared to direct point-and-click of today's touchscreens. But that's using it is learnable skill, as the older one demonstrated by easily scaling the terminal window, dragging from the lower right corner.

Then we practiced typing letters with caps-lock on. She has absolutely no idea which key produces which glyph or how the glyphs are related to the sounds. Yet, it was fun. Learning will occur if repeated.

Lesson 26 - Monadic composition

Today was a day of many firsts.

I had installd iTerm2 on her machine, so that we can easily split the terminal into two panes. It was great fun splitting and closing panes, and switching between them. We will use this skill for great good on the next lesson. This time it was just to get a fun start for a heavy lesson.

Because next we went straight into the world of Haskell and GHCI.

We started by recapping how to run a sequence of actions (I still haven't come up with a good Finnish word for action) using the predefined s function. Actually the s function is a synonym for sequence and part of a set of helpers I've defined for both Haskell and Turtle Roy to make programming a bit faster.

    s [say "mila",say "elena"]

She remembered the list syntax quite well, and autonomically closed the strings and the list with quotes/brackets.

Next, we tried a new function that's also part of my "Napero" predefs for Haskell.

    i

Here i is a shorthand for getLine which reads a line of user input and returns it. The story was that now the computer is asking you a question and you should answer by writing your name. It doesn't actually do much yet. But when "piping" it to say, it's already quite cool. So

    i >>= say

Just like piping in bash, but using a monadic bind (I suppressed the urge to explain monads at this time). Then we celebrated her first Interactive Computer Program!

But that was not enough. We went for the next goal: the first parametric function. So, we wrote a new function "hello" which has a parameter "name":

    let h n = s [say "hello", say n]

Then

    h "mila"

And the computer said "hello mila". And finally

    i >>= h

BOOM! 

I kept on explaining how the parameter thing works but I'm quite sure it will take several recaps to nail it. Finally we had a little Parametericity Quiz, played a bit with iTerm splits and that was it.

Saturday, October 5, 2013

Lesson 25 - Birds in Insert Mode

Today I suggested we do some stuff with files but she wanted to use vim and create a new file containing bird species. First we had a look at the quite impressive list of files we had already created, by using ls. She wanted to see what's inside the "vkp" file and used cat to print out the file contents. She had some difficulty remembering cat, but with some tips she remembered it and was able to type it correctly. So, we saw the Finnish weekdays listed in the "vkp" file.

    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai
    maanantai tiistai keskiviikko torstai perjantai lauantai sunnuntai

Then she wanted to jump to Turtle Roy, but I insisted we make the bird file first. And so we did. Her writing is improving all the time and she typed "vim linnut" almost without errors. The double consonant nn was the only part where she needed help.

Then with some help she got into insert mode and typed, mostly unhelped the two birds that came into her mind:

    varis harakka:

Oops! She had forgot she had to exit insert mode before using :wq to exit. But the cool thing was that she noticed her error immediately, pressed esc (exit insert mode) and was starting corrective actions by herself when I interrupted her and wanted to know what she was going to do. She said 

    "I'm gonna enter insert mode and delete that colon". 

Pow! I said that's very good, but there's an even easier way to do that. Just type x to delete the character at the cursor. So she did that, then save and exit.

I suggested we have the computer speak the new file but she wanted to have it speak the "vkp" file instead. And indeed she did that. Without any help.

    cat vkp|say

That's it for today! Now, bedtime.

Monday, September 30, 2013

Lesson 24 - Accidental Arithmetics

Tonight she wanted to have a lesson just before bedtime. It's usually a bad idea, but I came around because she was so eager and didn't seem too tired.

The plan was to complete the Turtle Roy drawing from the last time, until an accident happened.

We started with turtle graphics and this time, I think, was the first time she remembered without any help that you use "fd 100" to move forward 100 pixels. She also mastered the clock trick from last time to determine whether we should turn right or left.

Then she accidentally typed just

    1

and the computer answered

    1

Then teased her to try if the computer can do 1 + 1. And then we had a lot of fun doing arithmetics. She was really excited, for example, what 77 + 77 is.


Sunday, September 29, 2013

Lesson 23 - Clock

Today we did a lot of drawing with Turtle Roy. The key thing that was learnt was that turning right is turning clockwise and vice versa. The directions left and right were pretty well learnt already but when the turtle is facing downwards, it's not trivial to say whether you should turn left or right to get to the direction you want to go. (not even for me)

So we placed a pen on the computer screen and turned it to the direction we wanted to go. Then, if it appeared to be the direction the clock always turns, it's Right.

What we actually tried to draw with Turtle Roy this time is her name. We go this far. We'll continue with that on the next lesson. It's amazing that she doesn't really care whether we should write from left to right or the other way. She chose to write the arabic way because there was "more room to the left".

She also knew exactly when we should lift the pen up and when to put it down. You have to lift the pen up to move it without drawing on the screen, you know.

This lesson was a fun and rewarding one, thanks to not having it just before bedtime. She remembered the space between the function name and the argument very well. That's because I've given her a cookie every time she remembers it. 

Bribery works. We've run out of cookies now, but we don't need them anymore either.

Thursday, September 26, 2013

Lesson 22 - Reverse

This time we started too late. She was too tired to learn. We should never do this just before bedtime...

Anyway, it was Haskell time. The idea was to teach the computer who the girls are and then turn them upside down.

So we opened ghci and started teaching. Like last time with Turtle Roy, we used let to define a new thing. I suggested the word "tytöt" (girls) but we chose to use the name "t" because it's shorter and the computer doesn't really care. So,

    > let t = ["mila", "elena"]

Then we discussed head and tail a bit and tried them

    > head t
    "mila"
    > tail t
    ["elena"]

I took a while to make a distinction between a character string and a list and that tail returns a list of strings in this case. I'm quite sure she ignored my talk. But let's see. Maybe she's a natural with types.

Next we tried reverse:

    > reverse t
    ["elena", "mila"]

And finally the funniest thing. I introduced a new function map which takes a list and another function (POW!) and performs the other function for all things on the list. So we applied reverse to all the girls:

    > map reverse t
    ["alim", "anele"]

That was fun. Then we reversed daddy too.

Tuesday, September 24, 2013

Lesson 21 - Characters

Last time we talked about getting to know all the characters that one can type using the keyboard. Today she wanted to get on with that, so we skipped the turtles and went for vim.

She typed vim merkit by herself. In vim she instantly knew she has to press i to start writing text. Then she wrote something like

    numerot 1234567890©@£$...

and so on. We went through the numbers, then numbers with the shift key, then with alt and finally with both shift and alt pressed. We discovered a host of fun characters that I had no idea were hidden behind the number keys.

Then the same excercise for all the letter keys. There was a lot of discovery and she managed to save the document after each line of text to make sure we won't lose our work if the battery goes out. That's an important lesson for you too :)

So, even though we hadn't used vim for a week, she mastered it. She also remembered that cat is used to print file contents and, with some assistance, that we can pipe it to say to have the computer speak.

All in all, I noticed she had improved writing skills and general confidence in her own abilities. And it seems that my fears about her forgetting all the learnt skills in a day were without foundation. Even though it sometimes feels that nothing seems to "stick", a lot does indeed.

Saturday, September 21, 2013

Lesson 20 - Spider

After yesterday's repetitive practise on Turle Roy basic movements, we were quite well prepared for today's lesson. We started teaching the computer immediately and wrote (again)

    let askel = s [fd 100, lt 90]

Then

    let neliö = r 4 askel

Then (the excitement thickens) we ran our neliö function and had the turtle draw a perfect square. And again. And again.

Then we set to implementing the "spiderweb" thing that I showed her earlierly. The idea is to draw a square, then turn right, say, 5 degrees, then rinse and repeat. So first we taught the computer to do the "square and then turn" thing, the naming of which was left to her. She chose to name it xz. And then we wrote

    let xz = s [neliö, lt 1]

She chose the 1-degree turn against my advice. And finally

    let spider = r 360 xz

And we got a very fancy picture. Not the spiderweb thing though, because of the 1-degree turn, but a cool thing anyway. Then we modified the program a bit to draw the actual spiderweb. We saved our work, so that you can try it out yourself.

This was a fun lesson! She would have wanted to do some keyboard practise in vim too, but we ran out of time.


Lesson 19 - Left & Right

Yesterday she announced that she wants to learn to code. So we went back to Turtle Roy to do some programming.

We started, once again, with some basic turtle graphics stuff like

    fd 100
    lt 90
    fd 100

.. and so on. I was a overly optimistic to presume she'd be able to memorize how to turn to left and right and how to move forward in a blink of the eye. In fact, it proved quite hard this time. Maybe the problem is that left and right themselves are quite tough concepts for a 4-year old. When you add that we discuss in Finnish and code in English, and that English is not written the same way it's pronounced, I can understand that it's not easy. 

So this time we spent most of our time learning turtle graphics and trying to memorize left and right. On the other hand she easily remembered how to construct lists using square brackets around them and commas between the list elements...

All in all, this lesson felt like a step backwards. Or maybe more like a reminder of the fact that she's just 4. So let's take it easy and have fun.

It is said that Logo and turtle graphics are a great way for kids to learn programming. However, I realised yesterday that teaching is usually started at age 12 or 13. Finnish children of that age can

  • speak / read / write English
  • understand numbers up to 1000 (?)
  • understand some geometry, including angles
Children at four, on the other hand, can do none of these things. So the learning curve is in fact quite steep. 

But we won't give up! 

I'm open to new ideas too. What should we do instead, or in addition to Turtle Roy?

Tuesday, September 17, 2013

Lesson 18 - IO Monad

I'm slipping. I forgot to post yesterday even though we had a lesson.

Yesterday we visited Haskell for the first time.

That was just because the "say" function in Turtle Roy didn't produce any speech though. Fortunately I had setup her GHCI so that it includes my special helper module Napero which provides easy single-letter shorthands to some common functions. For those not in the know, the Roy language used in Turtle Roy is syntactically very similar to Haskell, so we can switch between the two without struggling with different syntaxes.

The main thing of lesson 18 was the idea that you can define a list of actions and then sequence them into a single action that performs all of the actions on the list. So, in Haskell we did

    s [say "mila", say "ella"]

Where s is a shorthand for sequence and say is a wrapper for the command-line say command. Composition is a powerful tool! This is coding!

Next we started "teaching the computer". The idea was to teach the Turtle Roy to draw a rectangle, which consists of four equal parts. Each of the 4 parts proceeds 100 pixels and then turns right. We called this operation "askel" and taught the computer to do "askel" like this

    let askel = s [fd 100, rt 90]

When we had taught the computer, i.e. defined a function, we called askel 4 times and voilá, got the rectangle together!




Then we concluded that "askel" is almost like "haskell".

Next up: define the rectangle function.

The list syntax is something we'll be revisiting time after time until it feels natural to her.

Sunday, September 15, 2013

Lesson 17 - Song Finished

Today we completed the "head shoulders knees and toes" song by adding a new line "eyes and ears and mouth and nose" and yank-pasting a couple of lines to the end. It took about 15 minutes most of it we spent typing the 5-word line.

She remembered the space between words. She had more confidence with the letters G and B which we practiced quite a bit when moving around the document.

Next up: programming. I'be prepared a bunch of Haskell helpers already. Not sure whether to start Haskell next time or stick with Turtle Roy...

She taught Mom some more vim after our lesson. Mom proved to have mad unix skillz.

Thursday, September 12, 2013

Lesson 16 - Mom Learns Vim

This time we practised vim movements quite a bit


  • 0/$ - start/end of line
  • 1G - first line
  • G - last line
  • 2G -second line
  • w - forward one word
  • b - back one word
  • j/k - down/up
And that's quite enough for most of your movement needs. We'll practice those more later.

Then we did some editing, using dw to "delete word" and then i to insert new text. She remembered to exit insert mode, of course.

Then we yanked a line with yy and pasted with p. Those she remembered too. And deleted one line with dd, so that our little song goes now like

  head shoulders knees and toes
  knees and toes

  head shoulders knees and toes
  knees and toes

Then we made the computer speak this out load again with cat pää|say. She taught her mother how to do that.

Then she insisted on teach mom some vim too. And so also mom is capable of entering and exiting vim! She'll get another lesson tomorrow.


Tuesday, September 10, 2013

Lesson 15 - Gravity

Today we implemented the GOF Patterns starting from Singleton and Visitor.

Not.

We practised the most popular method of code re-use: copy-paste. In vim it's called yank-paste. First we added a new line to our song. It was easy. Now the song goes as in

  head toes and knees and toes
  knees and toes

Then I teached her how to move up and down in vim, using the j and k keys. We had an exercise where I shouted UP and DOWN randomly and she had to follow the orders with the cursor. First she tried to use the mouse but we soon established that vim doesn't obey the mouse. Soon she mastered the movevents and we were ready for copy-pasting. So, we moved to line 1 and yanked it using "yy". Then went to the end and pasted it using "p". This for both lines. She was happy to achieve so much with so little effort!

Then she told me the lyrics are all wrong. They should go like "head shoulders knees and toes" instead. Damn! We decided to fix that next time and had fun with "cat pää|say" instead. The computer was a lousy singer but we listened to it many times nevertheless. This was a fun lesson!

After the lesson I questioned her and she still remembered the movements, yanking and pasting. The hardest thing is still remembering to enter a space between words. In fact, I promised her a cookie for each space she remembers and she actually remembered on this time. The offer still stands, so let's see if she remembers better next time.

Oh, and yesterday we discussed whether people on the other side of Earth stand head-down. We discussed gravity and she drew a very nice diagram that show the force vectors for two girls on the opposite sides of the world:




Friday, September 6, 2013

Lesson 14 - Back And Forth

We started by moving the "pää" file back to the home directory. It took some time to establish that the snake-like tilde character represents the home directory and she decided to call it the "waves of the ocean" character. I think it's good to have a memorable name for that.

Then it was vim time. She knew that to edit the file, she has to use vim, and to open the file in vim she has to type "vim pää". She also types it correctly, even including the space between the words.

In vim, we practiced movements. Use 0/$ to go to the beginning/end of the line. Then we used w to go to the end of the current/next word. We moved around quite a bit, then appended the missing "the" word in the file that will eventually contain the lyrics of the "head toes knees and toes" song. She didn't remember the a/append command, but we memorized that append is a lot like "Abhem", who is one of her friends. Maybe remember next time?

We enjoyed the power of vim by repeating the previous command with "." and even tried "10." to repeat it ten times. Then u for undo. At last we had the first line of the lyrics ready!

And that was enough for here this time. Too tired to go on. Better quit while winning, right?