Options for languages to use on the Pi


27 posts   Page 1 of 2   1, 2
by thedo » Wed Jun 06, 2012 7:47 am
By day I'm a professional C#/F# developer, and an ex Pascal/C/C++ dev.

I've got my Pi set up and I'm thinking it might be fun to learn a new language - here are some options I'm thinking of.......

1: Erlang - seems like a perfect fit for the Pi in many ways. Given the scalability factor of Erlang, and the potential to grab a load of Pis (in the future), kinda feels like we can start tackling some really nice problems on the cheap.

2: Clojure - of all the LISPs out there this currently seems the cool cat on the block. Not sure about availability on the Pi?

3: Scala - Given my preference for functional languages these days the JVM equivalent to F# could be interesting. Again, not sure about availability on the Pi?

4: C - I feel like I've forgotten more than I should about C. Time to go back to basics? Comes pre-installed on Debian Squeeze for Pi, so the barrier for entry seems nice and low.

5: ARM Assembler - many many moons ago I could have told you all kinds of weird things about x86 ASM, but like my C/C++ knowledge its long gone. Might be fun to try this on the Pi, but tutorials seem thin on the ground.

6: Any other suggestions?

Can anyone help clarify availability of some of the above languages, or point me in the direction of a nice simple getting started tutorial (particularly ASM)?
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm
by tufty » Wed Jun 06, 2012 8:17 am
Clojure and Scala are going to require the JVM, and that's gonna hammer performance. For Scala, you're gonna have to live with it, though.

For a "lisp", I'd probably recommend Ypsilon Scheme (which is a pretty damned fast r6rs scheme). NewLISP (http://www.newlisp.org/) might be worth a shot, too, although I've never done much with it.

Haskell is already on the Pi. That's worth learning, too.

Simon
Posts: 1371
Joined: Sun Sep 11, 2011 2:32 pm
by andyl » Wed Jun 06, 2012 8:54 am
Other suggestions.

a) Javascript
You might know this, but do you know it properly. Hacking stuff on node.js is pretty cool.

b) Io - http://iolanguage.com/
A pure prototype based language. Very interesting. You will need to compile this up yourself - I don't think there is a Debian package.

c) Haskell - http://www.haskell.org/haskellwiki/Haskell
Purely functional. Static typing.

d) Go.
One of Google's languages. Not played with it.

e) Factor - http://factorcode.org/
A concatenative stack-based language. Has a lot of Forth in its ancestry. Another one you will have to compile yourself.

f) Newspeak - http://newspeaklanguage.org/
A mix of ideas from Self / Smalltalk / and a few other languages. I've not looked at it yet. It is very early on in its life. It runs as a Squeak image - so may be a bit too slow and heavy for the pi.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by thedo » Wed Jun 06, 2012 9:32 am
So suggestion wise Haskell seems to come pretty high. I've had a tiny bit of exposure to Haskell from colleagues at work, but am largely in the dark. Definitely worth a look for me. Maybe I'll finally understand type classes and monads (and why their more powerful in Haskell than computation expressions in F# (apparently))

What is the current state of Erlang on the Pi? I did a sudo apt-get install erlang on debian squeeze and all seemed to be going well, but then after a while there was an ugly error and I was unable to update my package repository at all. Zoinks!
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm
by andyl » Wed Jun 06, 2012 9:43 am
thedo wrote:What is the current state of Erlang on the Pi? I did a sudo apt-get install erlang on debian squeeze and all seemed to be going well, but then after a while there was an ugly error and I was unable to update my package repository at all. Zoinks!


Well I haven't tried installing it. I'm busy for the next few days (and evenings) so probably aren't going to get a chance to try it soon. What error did you get?
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by thedo » Wed Jun 06, 2012 9:57 am
I'll try it again and report back the full error. It was a 100% fresh debian squeeze image on an 8GB SD card.

IIRC it was complaining that it was out of disk space, but I'll double check tonight.
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm
by Bakul Shah » Wed Jun 06, 2012 4:12 pm
tufty wrote:For a "lisp", I'd probably recommend Ypsilon Scheme (which is a pretty damned fast r6rs scheme).

Simon, have you ported it to RasPi? The last time I tried it didn't build (I didn't investigate further).

I know there are a bunch of Scheme interpreter ports (gauche etc.) in the debian repo. Gauche has opengl support but not sure about GLES (probably non-existant). s9fes (Scheme 9 from Empty Space) compiles and works fine. It has help built in (Type ,? at the prompt) so it may be easier for newbies. My fork of s9fes: https://bitbucket.org/bakul/s9fes

Another language suggestion: k, an array programming language. See https://github.com/kevinlawler/kona. Not sure if j (another apl) works. There is an A+ debian port + KAPL fonts if you like APL.
Posts: 293
Joined: Sun Sep 25, 2011 1:25 am
by antiloquax » Wed Jun 06, 2012 6:32 pm
I've been gathering a few languages on my Pi.

I've got Common Lisp, and I'm hoping to learn some of that. I hadn't heard of Clojure. Not really considered Scheme, but I am curious (been watching some of (Stanford) Prof. Jerry Cain's YouTube Videos on C (Programming Paradigms) ) - he gets on to Scheme later in the course.

I also want to learn Arm Assembly code.
The code on this page is helpful, I've found.

I've just bought Donald Knuth's TAOCP vol. I. Planning to learn some MIXAL.

And I am thinking of doing a bit of brainf*ck, just for the hell of it!
mark
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
by andyl » Wed Jun 06, 2012 6:49 pm
antiloquax wrote:I've been gathering a few languages on my Pi.

I've got Common Lisp, and I'm hoping to learn some of that. I hadn't heard of Clojure. Not really considered Scheme, but I am curious (been watching some of (Stanford) Prof. Jerry Cain's YouTube Videos on C (Programming Paradigms) ) - he gets on to Scheme later in the course.

I also want to learn Arm Assembly code.
The code on this page is helpful, I've found.

I've just bought Donald Knuth's TAOCP vol. I. Planning to learn some MIXAL.


If you are already doing real assembly language then I don't think Mixal will add anything.

If you are looking at Scheme - then I would recommend The Little Schemer to help get you thinking the right way (there are another two books in the series Seasoned Schemer and Reasoned Schemer). The original book was The Little Lisper and it will help with getting Common Lisp as well.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by tufty » Wed Jun 06, 2012 8:06 pm
Bakul Shah wrote:
tufty wrote:For a "lisp", I'd probably recommend Ypsilon Scheme (which is a pretty damned fast r6rs scheme).

Simon, have you ported it to RasPi? The last time I tried it didn't build (I didn't investigate further).

Nope. Haven't tried compiling it for ARM. I was using bits of it as the underlying interpreter for LambdaPi but I'm going along a slightly different path now.

Simon
Posts: 1371
Joined: Sun Sep 11, 2011 2:32 pm
by antiloquax » Thu Jun 07, 2012 2:57 am
andyl wrote:
If you are already doing real assembly language then I don't think Mixal will add anything.

If you are looking at Scheme - then I would recommend The Little Schemer to help get you thinking the right way (there are another two books in the series Seasoned Schemer and Reasoned Schemer). The original book was The Little Lisper and it will help with getting Common Lisp as well.


Thanks for the advice, andyl.
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
by shirro » Thu Jun 07, 2012 3:10 am
c and Lua. They work nicely together. Neither will have performance issues on the Pi. Lua can do just about anything Javascript or Scheme can do and it is tiny.
Posts: 248
Joined: Tue Jan 24, 2012 4:54 am
by Bakul Shah » Thu Jun 07, 2012 8:01 am
shirro wrote:c and Lua. They work nicely together. Neither will have performance issues on the Pi. Lua can do just about anything Javascript or Scheme can do and it is tiny.

Not quite! No macros or bignums or lazy evaluation in Lua.

Code: Select all
$ s9
Scheme 9 from Empty Space
> (define-syntax swap!
    (syntax-rules ()
      ((swap! a b) (let ((t a)) (set! a b) (set! b t)))))
> (define a 1)
> (define b 2)
> (swap! a b)
> a
2
> b
1
> (expt 2 100)
1267650600228229401496703205376


As far the language goes, Scheme is one of the smallest languages. As for interpreters, some are bigger, some smaller. One of the reasons I like s9 is because it is so small.

Code: Select all
$ cd ../lua-5.1.4
$ wc *.[ch] | grep total
   16959   58571  447254 total

$ cd ../s9fes
$ wc s9-real.c s9.c s9.h s9.scm | grep total
  7588  23040 168257 total


And some scheme implementations are certainly faster than Lua (and some slower). Not sure where s9 is.

Finally, here is a quick-n-dirty implementation of "infinite lists" (or streams) in Scheme, with enough functions to allow defining an infinite list of primes (given enough time and memory!)
Code: Select all
(define-syntax scons
  (syntax-rules () ((scons h t) (cons h (delay t)))))
(define (scar st)
  (car st))
(define (scdr st)
  (force (cdr st)))

(define (take n s)
  (cond ((<= n 0) '())
        (else (scons (scar s) (take (- n 1) (scdr s))))))

(define LP "(")     ;) (  <== added to keep the posting software happy
(define RP ")")

(define (sdisplay s)
  (do ((xs s (scdr xs)) (sep LP " "))
      ((null? xs) (display RP) "")
      (display sep)
      (display (scar xs))))

(define (iterate f start)
  (letrec ((ls (scons start (iterate f (f start))))) ls))

(define (filter f xs)
  (cond ((null? xs) '())
        ((f (scar xs)) (scons (scar xs) (filter f (scdr xs))))
        (else (filter f (scdr xs)))))

(define (sieve xs)
  (scons (scar xs)
         (sieve (filter (lambda (x) (> (modulo x (scar xs)) 0)) (scdr xs)))))

(define (from n)
  (iterate 1+ n))

(define (1+ x) (+ 1 x))

(define primes (sieve (from 2)))

(sdisplay (take 100 primes))


It will take a while to print the first 100 primes but if you repeat the operation, it will be fairly quick as previously computed values are saved.
Posts: 293
Joined: Sun Sep 25, 2011 1:25 am
by neoneo2074 » Thu Jun 07, 2012 9:38 am
I have installed the erlang virtual machine to O2 Joggler running in linux.
In the day I receive the Raspbarry Pi, I tried to install the erlang virtual machine to it.
It didn't run. I didn't take more time on it. I guess it was due to some setting reasons.

I think Raspberry Pi should be good at working with erlang.
I'm planing to make the O2 Joggler and the Pi work together to share load in my small erlang project.

If it's successful (it should be), I want to buy more Pis to build up server group to improve my erlang project.

I will feedback my result. ^_^
Posts: 2
Joined: Thu Jun 07, 2012 9:19 am
by tufty » Thu Jun 07, 2012 10:07 am
Please do. Erlang is interesting.
Posts: 1371
Joined: Sun Sep 11, 2011 2:32 pm
by jecxjo » Thu Jun 07, 2012 3:45 pm
First language I got installed on my board was Common Lisp via Embedded Common Lisp (ecl). Works like a charm.
IRC (w/ SSL Support): jecxjo.mdns.org
Blog: http://jecxjo.motd.org/code
ProjectEuler Friend: 79556084281370_44d12dd95e92b1d9453aba2bdc94101b
User avatar
Posts: 157
Joined: Sat May 19, 2012 5:22 pm
Location: Ames, IA (USA)
by yeahbox » Thu Jun 07, 2012 7:04 pm
thedo wrote:6: Any other suggestions?


Since no one else mentioned it: How about giving Python a (proper) chance? (yes, this is the "Other languages" forum, I know...) :)
Posts: 36
Joined: Sun May 27, 2012 10:35 pm
Location: Manchester, UK
by jsz » Thu Jun 07, 2012 10:25 pm
andyl wrote: Hacking stuff on node.js is pretty cool.


No, it's not. It's slow and JS is a pretty ugly language.
http://github.com/jsz
Posts: 1
Joined: Thu Jun 07, 2012 10:23 pm
by andyl » Fri Jun 08, 2012 3:17 pm
jsz wrote:
andyl wrote: Hacking stuff on node.js is pretty cool.


No, it's not. It's slow and JS is a pretty ugly language.


Except you are wrong of course. On both counts.

V8 is pretty damn fast. Quite a bit faster than PHP, Python, Perl or Ruby for many things. At least an order of magnitude for some things.

Ugly is rather in the eye of the beholder, but from my point of view that apart from a few warts (and most languages have them) js is pretty good. And I like to think I have a pretty wide-ranging experience of languages both as a hobbyist and a professional.

Maybe you can give us some details of your hypothesis, so that they can be addressed sensibly. If you just wanted to thread-crap then please go elsewhere that behaviour isn't tolerated all that well here.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by neoneo2074 » Sat Jun 09, 2012 1:34 pm
I use 'apt-get' to install erlang-base.
It works. --Don't install all of erlang components. Install all of erlangs will take more space.

I run my program in PI.
After a simple performance test, the PI will take 3 times than O2 Joggler.
O2 Joggler is Intel Atom Z520 1.33GHz , dual-core,512M memory.
Erlang will use both cores by mutiple-process.
O2 has 2.6GHz CPU, and PI has 0.7 GHz.
Consider the memory difference, ARM's performance is like ATOM in same Hz in my test.

I think as server, it's better to add more cores in PI. and remove the GPU in same time.
Maybe the cost is not changed and improve the potential of PI in server field.
Posts: 2
Joined: Thu Jun 07, 2012 9:19 am
by djhuk » Sat Jun 16, 2012 9:02 pm
Can anyone tell me what version of GHC (haskell compiler) is on the debian image?

On Arch Linux the only available binary is version 6.12.3 which is really, really old (the lastest version is 7.4.2)
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by andyl » Sun Jun 17, 2012 6:58 pm
djhuk wrote:Can anyone tell me what version of GHC (haskell compiler) is on the debian image?

On Arch Linux the only available binary is version 6.12.3 which is really, really old (the lastest version is 7.4.2)


If you want to be on the cutting edge then Debian stable isn't for you. It is a distro that prizes stability and good transitioning from old versions to new and on multiple platforms.

The latest ghc is 6.12.1-13 on Debian squeeze.
The latest ghc is 7.4.1-3 on Debian wheezy.

So you can either put your entire system on to wheezy (which is the test release).

Or possibly if you are brave (and willing to spend time messing about) you can try pinning ghc to the wheezy release and keep everything else on squeeze. I've done this in the past for small packages not for something the size of ghc with all of its dependencies.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by djhuk » Mon Jun 18, 2012 9:05 pm
andyl wrote:
djhuk wrote:Can anyone tell me what version of GHC (haskell compiler) is on the debian image?

On Arch Linux the only available binary is version 6.12.3 which is really, really old (the lastest version is 7.4.2)


If you want to be on the cutting edge then Debian stable isn't for you. It is a distro that prizes stability and good transitioning from old versions to new and on multiple platforms.

The latest ghc is 6.12.1-13 on Debian squeeze.
The latest ghc is 7.4.1-3 on Debian wheezy.

So you can either put your entire system on to wheezy (which is the test release).

Or possibly if you are brave (and willing to spend time messing about) you can try pinning ghc to the wheezy release and keep everything else on squeeze. I've done this in the past for small packages not for something the size of ghc with all of its dependencies.


Ah excellent, I've just run the debian image through QEMU and I can confirm that 7.4.1 installs fine through wheezy.

The only issue I have with this is I'm running Arch on my 'Pi as its footprint is a lot smaller than Debian.

But to see GHC 7.4.x working on the ARM gives me great hope that an Arch binary is just around the corner!
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by MrTAToad2 » Mon Jun 18, 2012 11:14 pm
Hello

Just to let you know that GLBasic can run on a Raspberry Pi (if you compile for the Caanoo). This does currently impose a few limitations (there is no keyboard support as the Caanoo doesn't have one, for example), but a proper Pi native update will be available in the near future...
Posts: 6
Joined: Mon May 28, 2012 10:43 am
by Respectech » Tue Mar 05, 2013 1:48 am
Rebol3 and Red/System (a compiled Rebol-like language) both run on the Raspberry Pi. With the GDK bindings available on red-lang.org, Red/System can also easily create graphical interfaces, and is very efficient.

Get Rebol3 for ARM Linux (should work with Raspbian, but works for sure on Arch) at rebolsource.net .
Get Red/System at https://github.com/dockimbel/Red/tree/master/red-system .
Red/System bindings for things like GTK+, Webkit GTK+, ImageMagick, OpenCV, and more can be found at http://www.red-lang.org/p/contributions_20.html .
Posts: 40
Joined: Sat Sep 29, 2012 12:27 am