Version 0 of Daddy, how does a computer work

Updated 2003-06-25 08:50:46

Arjen Markus (25 june 2003) My elder daughter (6 and a half now, and very keen to learn new things) regularly asks me to explain how the magical device called computer works. So, invariably I tell her that you tell the computer to do this and that. Wrong metaphor! I then have to explain that a computer can not really hear and understand me. And that usually ends the explanation's main course.

So, why not use Tcl and the package I use for Geometrical constructions? This is the result - okay, I immediately admit that the drawing of the archetypical desktop computer is very boring - but simply run it and see the "story" unfold.


 # howcomputer.tcl --
 #    A small story: how does a computer work - for a 6-years' old child
 #    Source into "constructions.tcl"
 #

 mode cartesian
 moveto 0 5.5
 textcolour black
 textfont "times 18"
 draw text "How does a computer work?"

 #
 # Draw a "computer"
 #
 moveto 2 2
 draw line   2   2    2   5
 draw line   2   5    5   5
 draw line   5   5    5   2
 draw line   5   2    2   2
 draw line   2   2  1.8   2
 draw line 1.8   2  1.8 1.5 
 draw line 1.8 1.5  5.2 1.5
 draw line 5.2 1.5  5.2   2
 draw line 5.2   2    5   2
 moveto 3.5 4.5
 textfont "times 10"
 draw text "Type command: _"
 #
 # Show the user typing a command
 #
 moveto -4 1
 draw text "I type:"
 textcolour blue
 moveto -4 0
 set string {}
 foreach letter [split "print \"Hello!\"" {}] {
    append string $letter
    set tobj [draw text $string]
    erase $tobj
 }
 draw text $string

 #
 # The computer reacts "instantaneously"
 #
 moveto 3.5 4
 draw text $string
 moveto -2 -1
 draw text "The computer answers:"
 textfont "helvetica 18 bold"
 moveto 0 -2
 draw text "Hello!"