Monday, 29 December 2014

Raspberry Shoes Update

I haven't written anything about Raspberry Shoes in a while. The reason is that Raspberry Shoes still feels a long, long way away.

The route that was most attractive for me was Shoes 4 which is written for JRuby and the SWT cross-platform GUI toolkit. Last time I wrote I was quite optimistic, I had JRuby working on the Raspberry Pi. Shortly before then, the Shoes 4 team announced a pre-release Gem that would have made installing Shoes quite straightforward on Raspberry Pi. However, after installing the Gem I found that the Ruby SWT Gem upon which Shoes 4 relies only installs Intel versions of SWT. It seems there isn't an official ARM version of SWT. So, for the foreseeable future, it is unlikely that Shoes 4 will run on Raspberry Pi.

As an alternative, I installed the Green Shoes Gem. Green Shoes is a version of Shoes that uses the GTK2 GUI toolkit. It didn't work and so far I haven't spent anytime trying to figure out why. That's because Green Shoes is understandably no longer maintained in the light of Shoes 4.

One option that came to mind is that I could build Raspberry Shoes by forking Green Shoes and convert it to use GTK+3 (which, in the long term, I presume will be better supported on Raspberry Pi than GTK2). However, I very much doubt that I have the necessary skill to get it done in the time I have available. (I'm confident that I could do it if I put enough time into it.)

I even had a "if you can't beat them, join them" moment and thought that perhaps taking the easy choice, Python, would be better than trying to use Ruby. Then I saw a couple of Raspberry Pi Python code snippets. They were enough to convince me that Ruby will be much easier for a child to learn.

At the moment, I am undecided on what to do. Another language which can be even easier for beginners and in which I am more fluent than Ruby will be coming to Raspberry Pi soon. The language is Red. It is very highly influenced by Rebol. It is currently at the "alpha" stage and is expected to reach "beta" stage sometime next year. 

In the meantime, I'll try to spend a little time with Ruby and GTK+3 to see if I can come up with something for our seven year-old to follow on from Hello Ruby when it eventually arrives.

Friday, 5 September 2014

Installing JRuby on Raspberry Pi

I am persisting with my project to get Ruby Shoes 4 up and running on my Raspberry Pi. I really believe that Shoes will be a great medium for kids to learn programming. I've now completed the next step, getting JRuby up and running on Raspberry Pi.

I'm using rbenv to manage my Ruby installations on my Raspberry Pi as I explained in Installing Ruby on Raspberry Pi.

Of course, you need Java to install and run JRuby. I've found that there is a bug with the OpenJDK version of Java that stops JRuby working. So I installed the Oracle version:

sudo install oracle-java7-jdk

After installing Oracle's Java, like me, you'll probably end up with multiple versions of Java on your Raspberry Pi. Thanks to Bill Connelly for dropping a big hint on the Raspberry Pi forums, I was able to easily set Oracle's Java as the default by running the following commands and selecting the correct option:

sudo update-alternatives —config java
sudo update-alternatives —config javac

After that I simply had to use rbenv to install version 1.7.13 of JRuby:

rbenv install jruby-1.7.13

It takes quite a while and keeps the Raspberry Pi fully occupied during the installation but you can leave it running and come back later.

I installed JRuby 1.17.13 instead of the newer JRuby 1.7.14 as there was a warning on Shoes 4 GitHub that there is an issue with the newer version.

As I have Ruby 2.1.2 as the default Ruby on my Raspberry Pi, I set up a new directory, shoes, in which I set JRuby as the default. These are the commands that I used:

cd ~/raspberryruby
mkdir shoes
cd shoes
rbenv local jruby-1.17.13

Finally I launched JRuby:

~/raspberryruby/shoes$ ruby -v
jruby 1.7.13 (1.9.3p392) 2014-06-24 43f133c on Java HotSpot(TM) Client VM 1.7.0_40-b43 [linux-arm]

When you run JRuby, it takes a long time to load. I think this is not just because of the time to load the Java Virtual Machine in which JRuby runs but also due to a small bug that results in JRuby displaying the following warning:

pi@raspberrypi:~/raspberryruby/shoes$ irb
Java HotSpot(TM) Client VM warning: You have loaded library /home/pi/.rbenv/versions/jruby-1.7.13/lib/jni/x86_64 Linux/libjffi-1.2.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
irb(main):001:0> 

The warning doesn't have any adverse effect on JRuby, everything works as expected. This bug has already been reported to the JRuby team and hopefully will get fixed soon.

Now I can start on getting Shoes to run on my Raspberry Pi. 

Thursday, 24 July 2014

Using rlwrap with Ruby IRB

When you install Ruby on Raspberry Pi its interactive console, IRB, doesn't have console history. So if you enter a command incorrectly, you can't simply press the up arrow to get the old line back and change it. You have to type the whole command again.

A simple solution is to install rlwrap:

    sudo apt-get rlwrap

Then to run irb you simply do so via rlwrap:

    rlwrap irb


Ruby/GTK3 on Raspberry Pi

I've decided to give the GTK3 library a try for writing small GUI applications in Ruby on the Raspberry Pi. My two main reasons are that the Ruby GTK3 Gem was easy to install and, I believe, that GTK3 will benefit from the progressive move to Wayland in Raspian.

Installing the Ruby GTK3 Gem was simply a matter of a single command and a little patience. It took some time for all the native extensions to be built.

       gem install gtk3


Once the gem was installed, the Ruby Gnome 2 Hello World worked with the minor change of requiring gtk3 instead of gtk2.

If I have the time, I'm going to see if I can come up with a simple Domain Specific Language that would make it easier for children to write GUI programs in Ruby.

Compling JFFI on Raspberry Pi

I was trying to get JRuby working on my Raspberry Pi so that I could install Ruby Shoes 4. One problem that I came across was that JRuby won't run with the installed version of the Java Foreign Function Interface (JFFI). I found a solution in the JRuby Github Issues.

These are the commands to enter in the terminal:

cd ~
pi@raspberrypi:~$ git clone git://github.com/jnr/jffi.git jffi.git
cd jffi.git
ant jar
sudo cp libjffi-1.2.so /usr/lib
rm -r jffi.git



That got me past the JRuby issue with the JFFI, then I ran into a issue when JRuby tried to import java.lang.reflect.Modifier. It is apparent a bug in the Iced Tea Open JDK ARM builds.

I've decided to wait for a while and see if the issue get resolved before trying any other alternatives.

Monday, 14 July 2014

Installing Java, Ant and Maven on Raspberry Pi

In order to run Ruby Shoes 4 on my Raspberry Pi, I need to install JRuby. It hasn't been as straight forward as I'd like.The Raspian JRuby packages are very old and there is an issue that is stopping rbenv installing JRuby. Some of my problems could well be memory related as my Raspberry Pi is a model A.

I decided that I'd try to build JRuby from source. Building JRuby from source requires both Ant and Maven. When I went to install Maven with apt-get, the package manager also wanted to install so many other things including what seemed like three different Java runtimes.

I decided to install Ant and Maven myself. I installed Oracle's Java 1.7 Development Kit with apt-get:

    sudo apt-get install oracle-java7-jdk

I then used the instructions at the The Tao of Mac as a basis from which to directly install Ant and Maven.

The first thing to do was to set the JAVA_HOME environment variable which is required by Maven. I added the following line to my .bash_profile file in my home directory:

    JAVA_HOME="/usr/bin/java"

I downloaded the Ant 1.9.4 binary from Apache into my home directory, then deleted the manual folder using the File Manager. I then created a Java directory  in the /opt directory:

    sudo mkdir /opt/java

Next I moved Ant into that directory:

    sudo mv apache-ant-1.9.4 /opt/java

I then created a soft link to that directory to make it easier to install new versions of Ant in the future:

    cd /opt/java
    sudo ln -s apache-ant-1.9.4 ant

Next I added the ant/bin directory to the $PATH variable in my .bash_proifle:

    PATH="/home/pi/.rbenv/bin:$PATH:/opt/java/ant/bin"

The last thing with Ant was to check that it had been installed properly:

   pi@raspberrypi:/opt/java$ ant -version
   Apache Ant(TM) version 1.9.4 compiled on April 29 2014

The procedure for Maven was very similar, though this time I used wget to retrieve the Maven binary from the command line:

   cd ~
    wget http://www.apache.org/dist/maven/binaries/apache-maven-3.2.1-bin.tar.gz
    sudo tar -zxvf ~/apache-maven-3.2.1-bin.tar.gz
    sudo ln -s apache-maven-3.2.1 maven

Last thing to do was update my $PATH variable to include the Maven directory:

Of course, not installing Ant and Maven via the package manager means I will need to keep them up-to-date manually. I don't see that being a problem as I don't expect them to change that frequently or for me to make a lot of use of them.

Note: I have used my .bash_profile to store my $PATH and other environment variables. This means that I have to run a bash shell for them to come into effect. The standard Terminal on the Raspian desktop does not default to bash. The easiest way that I have found to open a terminal session on the desktop running bash is to use the "start" menu at the bottom lefthand corner of the screen and select Others-> bash. (I normally access the Raspberry Pi by using ssh from a MacBook. The terminal on the Mac loads bash by default.) 

Another thing to remember is that when changing your .bash_profile the changes don't take effect immediately. If you are using the desktop terminal, you need to close the terminal window and re-open it for the changes to take effect. If you are logged in to the shell, either directly or via ssh, you will need to logout and login again.

Wednesday, 9 July 2014

Raspberry Shoes

As far as I can tell, one of the motivations behind the development of the Raspberry Pi was the experience of actually typing code into a computer before you could play a game. The computers of those days such as the Acorn/BBC computers, the Sinclair range and others had languages with built-in access to the computers screen. There was no need to import and make calls to massive external libraries as is the case with most languages today.

There are a few exceptions  around, Rebol for instance. The stable version, Rebol 2, is not available on ARM processors. It's modern replacement, Rebol 3, which can run on ARM is still being developed, though progress is very slow. By the time it reaches version 1.0, the Red Programming Language will include easy to use access to the computer's screen.

Another alternative is Ruby/Shoes, a version of Ruby with built-in graphics. It seems to have taken a lot of inspiration from Rebol's approach. The first three versions of Shoes were written in C with a specific version of Ruby builtin. The latest version of Shoes, unsurprisingly Shoes 4, has been re-written from the ground up in Ruby. Actually it has been developed for the Java-based JRuby and uses the graphics features made available through Java.

I think I'll try to install Shoes 4 on my Raspberry Pi and see were it leads. It would be really good to have a simple way of programming graphic applications on the Raspberry Pi.

Dart Language (ECMA-408) and Unicode

I saw a Tweet about Google's Dart language specification being approved by ECMA (European Computer Manufacturers Association). It reminded me about Dart and I thought "It's a new language, I should put it through the UnicodeOutOfTheBoxTests".

I had second thoughts when I started to download Dart and noticed that it was over 100Mb. So I checked the new published ECMA-408 and found that Dart strings are UTF-16 and there appears to be no other Unicode support.

I came to the conclusion that it wasn't worth the time to write the Unicode tests in Dart as the results would be identical to JavaScript.

Tuesday, 8 July 2014

64 Bit Integer Arithmetic For Red/System

Red/System is the low-level dialect of the Red Programming Language. It is a compiled language, its datatypes and variables work like C, whereas its syntax is very similar to Red. The Red runtime is written in Red/System and the Red compiler outputs Red/System code (which is then compiled to native code).

The current version of Red/System has been written to meet those two needs and to do little more. Once Version 1.0 of Red is complete, the Red/System compiler will be re-written in Red (the current one is written in Rebol).

Using Red/System, it is very easy to write interfaces to external libraries written in C. There is a slight catch however, integers in Red/System are 32 bit integers and some libraries return 64 bit integers.

I've written a simple 64 bit integer arithmetic library for Red/System to make it easier to deal with such libraries. I expect that Red/System 2 will include built-in support for 64 bit integers so the library reflects its temporary nature.

The main functions are add, subtract, multiply, and divide. I used easy algorithms such as long multiplication and division.  There are a number of supporting functions and macros too.

You can find the library on Github.

Monday, 7 July 2014

Which Version Of Raspbian Is Installed?

This command displays which version of Raspbian is installed:

     cat /etc/*-release

It displays the following information:

    PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
    NAME="Debian GNU/Linux"
    VERSION_ID="7"
    VERSION="7 (wheezy)"
    ID=debian
    ANSI_COLOR="1;31"
    HOME_URL="http://www.debian.org/"
    SUPPORT_URL="http://www.debian.org/support/"
    BUG_REPORT_URL="http://bugs.debian.org/"

Saturday, 5 July 2014

Installing Forth on Raspberry Pi

I had a very tiring day yesterday and wanted to read something a little relaxing in the evening, definitely nothing directly related to my work. So I scanned through my growing list of eBooks, many of them still unread, and came across my copy of Starting Forth by Leo Brodie. (You can read the book online on Forth Inc's website.)

I have been helping out with the development of Red Programming Language since its early days. Red is heavily influenced by Rebol which in turn has elements of Forth in it. Even after reading the first few pages of Starting Forth, I was able to better understand part of Red's roots.

For a long time now, my approach to programming has been to build things step at a time. The Forth philosophy exemplifies this approach with the exception of automated testing. (I need to investigate unit testing in Forth).

I believe that children tend to learn in small steps, they discover something new (perhaps with the help of a teacher) and then practice and practice. When they are comfortable with what they've just learnt, they move on to learn something else. It occurred to me that Forth could be a good language for children to learn and what better computer to learn Forth on than a Raspberry Pi?

There are lots of different Forths about. I chose the open-source GForth which is readily available for Raspbian. A single terminal command:

    sudo apt-get install gforth

A few minutes later, Forth was ready to go:

GForth on Raspberry Pi
Click to Enlarge

Wednesday, 2 July 2014

Installing Ruby on Raspberry Pi

One of the reasons that I bought my Raspberry Pi was for Hannah, our seven-year old daughter, to use it to learn about computers. She's already played with Scratch on my laptop. She's tried the Python games out on the Raspberry Pi. I guess there's even a possibility that she may get some exposure to Raspberry Pi at school. Perhaps I should start referring to it as "our" Raspberry Pi rather than  "my" Raspberry Pi.

I'm really keen for her to learn more about computers than using Microsoft Office and Google Drive. When the "Hello Ruby" children's book project was launched on Kickstarter, I quickly backed the project. If the project is on schedule the book should arrive during Hannah's summer holidays.

So I thought I'd install Ruby on our Raspberry Pi before the book arrives. I know a little Ruby and quite like it. More than that I've found it very useful on a number of occasions. I don't know Python at all so I'm planning to use Ruby on  our Raspberry Pi.

Installing Ruby wasn't difficult. I followed the clear instructions relating to Ruby and rbenv at Raw Syntax. There seems to be one slight omission in the instructions, you need to add rbenv to your PATH environment variable before trying to run rbenv to install Ruby.

After installing rbenv from Github, I created a .bash_profile file in my home directory with the following contents:

    PATH="/home/pi/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"

I was then able to proceed to install the latest release of Ruby using this command:

    rbenv install 2.1.2

It takes a long time to compile Ruby on a Raspberry Pi so I left it running whilst I went for dinner. When I came back I was disappointed to find that the Ruby build had failed on the last stage - building the documentation. The error message was [rdoc] Error 137. I quickly googled the error and found a suggestion to install Ruby without its documentation. That was fine for me as when I have a question about Ruby I either look in The Pick Axe or check the online documents. This time I installed Ruby using:

    CONFIGURE_OPTS="—disable-install-doc" rbenv install 2.1.2

This time the install completed successfully and I now have Ruby installed on our Raspberry Pi


Ruby on Raspberry Pi
Click to Enlarge
Footnote: I haven't quite finished yet. Whilst I can run Ruby on our Raspberry Pi by using a terminal on my Mac, I'm having problems getting rbenv to work using LXTerminal on the Raspberry Pi. I can run Ruby by specifying the full path to the file but that defeats some of the purpose of installing rbenv. I'm pretty sure that it's something to do with LXTerminal and shells. I need to find out.

LXTerminal does not seem to run bash by default so the answer is either to select bash from the pop-up menus (Other -> Bash) or enter the following command in LXTerminal:
    
    lxterminal -e "bash -il"

Saturday, 28 June 2014

Installing Red on Raspberry Pi

The Red programming language is still in the bootstrap phase using a compiler written in Rebol 2. Rebol 2 doesn't run on ARM processors so at the moment programs for ARM computers have to be cross-compiled on an Intel computer.

The Red REPL (known as "console") is simply a Red program that sits on top of the Red runtime. The Red runtime is written in the low-level Red/System dialect and can be cross-complied for Linux running on ARM.

The source of the console program is included in the Red Github Repository. Assuming that a Rebol interpreter is available, cross-compiling the console takes a single terminal command:

     rebol -qs red.r -t Linux-ARM  runtime/console/console.red

One of the many things that I like about Red is how simple it is to compile for different targets. The output from the compiler looks like this:

-=== Red Compiler 0.4.2 ===- 

Compiling /Users/peter/VMShare/Languages/Red/runtime/console/console.red ...
...compilation time : 395 ms

Compiling to native code...
...compilation time : 20029 ms
...linking time     : 245 ms
...output file size : 618544 bytes
...output file      : /Users/peter/VMShare/Languages/Red/console

I followed the excellent advice from Milliways on the Raspberry Pi Stack Exchange and installed netatalk on my Pi. I can now connect to my Pi from my MacBook. I simply copied the compiled Red console program over to it using OS X Finder.

Red doesn't have to be installed on the Raspberry Pi, simply type its path on the command line to run it. (The Red compiler even sets the execute bit!)

Red on Raspberry Pi
Click to enlarge



Friday, 27 June 2014

3 million and nth Raspberry Pi

I made up my mind to buy a Raspberry Pi after more than 3 million have been sold. As they cost less than a decent meal in Western countries, I wouldn't be at all surprised if more than 2 million of them lay idle. Mine certainly wasn't an impulse purchase but it remains to be seen whether I'll actually make good use of it.
Raspian

At the time I ordered my Raspberry Pi, I had a choice of a Model A or waiting for more Model Bs to arrive. My impatience got the better of me. After the Raspberry Pi arrived, I went out and bought a power supply and a USB hub to go with it. I borrowed the keyboard and mouse from an old desktop computer, the TV and HDMI lead from the bedroom and the USB to Ethernet converter that I have for my laptop.

Although, the Raspberry Pi foundation recommends using a powered hub, the warnings about "back feeds" in the Raspberry Pi FAQs put me off. (I probably try to get a powered hub that has been specially designed for the Raspberry Pi later on). The power supply that I bought is rated at 1v and the Model A consumed up to half of that. There is plenty left to power the keyboard, mouse and ethernet connection. I've yet to try adding a USB memory stick but I'm hopeful there will be sufficient power for one of them too.

I bought a Noobs SD Card with the Raspberry Pi so installation was easy. I backed up the Noobs card on my laptop (which thankfully has a builtin SD card slot) and simply followed the onscreen instructions. I chose to install Raspian. My Raspberry Pi was up and running in the time it takes to enjoy a good cup of coffee.


Friday, 13 June 2014

Unicode Out of the Box tests

I've been helping out a little with the development of the Red language since the day It was announced. One of the things that I've done is to look into what supporting Unicode in Red would involve and what level of support should be provided in the binary distribution. As part of this, I wanted to understand the capabilities of other languages.

Rather than simply search the web and browse a few documents, I decided to put languages to the test. So I developed a set of tests that would give a more substantial indication of a language's Unicode ability with invaluable help from Anton of The Red Team.

The 25 tests have been completed in 15 languages written by members of the Rebol community, Anton and myself. (Red is heavily inspired by Rebol). 

Coming up with the tests took some work but it was interesting and I've learnt a lot in the process. Writing the code was fun though it was quite slow in the languages that I am not very familiar.

Why don't you take a look at the Unicode Out of the Box Tests?