GIMP# and Nemerle

November 25, 2007 at 3:58 pm | Posted in C#, GIMP, Programming | 2 Comments

Yet another language joins the long list of GIMP programming languages. This time it’s Nemerle. I can’t say I have studied the ins and outs of this language yet, but the syntax seems to be very close to C#. It didn’t take me very long to create a GIMP# plug-in written in Nemerle. This very basic plug-in computes the average color of all pixels of an image and fills the image with that color. What surprised me most is that the plug-in written in Nemerle was almost exactly as fast as a similar plug-in written in C#. A few months back I already reported that the same plug-in written in IronPython is 4 times slower.

Hopefully I can soon report on how well IronRuby is doing.

2 Comments »

RSS feed for comments on this post. TrackBack URI

  1. I completely share your enthusiasm. I was baffled at the expressiveness of Nemerle when I encountered it a month ago. To me there is the following relation:

    Nemerle > Boo > IronPython

    Unfortunately, I feel that the semblance to C#/Python (in indent mode) is being used as a bit of an excuse to avoid proper documentation. Also, all the nifty syntax has shifted quite a bit in the past. I personally don’t think it should ever be warranted to change syntax in a ‘public’ language. To me it effectively reduces Nemerle to a ‘pet project’.

    I still use it to write up small toy projects or powerful logic scripts:

    public class IsThisLanguageAnyGood
    public static Main () : void
    def enc = UTF8Encoding();
    def crypt = MD5CryptoServiceProvider();

    def tohex(bytes)
    $[b|b in bytes].FoldLeft("", {(val,acc) => acc + val.ToString("X2") });

    foreach(tuple in passwords.Map({pwd=>(pwd, crypt.ComputeHash(enc.GetBytes(pwd)))}))
    | (pwd,hash) => WriteLine($ "$pwd $(tohex(hash))");

    public static passwords : list[string]
    get
    $[$ "$(g)r$(a1)$(a2)fl$(a3)n$(d)" |
    g in ["g","G"],
    a1 in ["a","@"],
    a2 in ["a","@"],
    a3 in ["a","@"],
    d in ["d","D"]];

    is pretty amazing (Boo can do the same)


    public static Exercise() : void
    def R = Random();
    def problem = $[0..9].Map({_i => R.Next(100)-50});

    WriteLine($ "$problem quicksorts as $(qsort(problem, _ _))");

    static qsort[_T](l:list[_T], less:(_T*_T->bool)) : list[_T]
    match(l) {
    | [] => [];
    | head :: tail =>
    def (pre,post) = tail.Partition(less(_,head));
    qsort(pre,less) + (head :: qsort(post,less));
    }

    As far as I remember, Boo lacks the ‘match’ facility that really sells Nemerle for me (like Ocaml) in that it allows me to specify a ‘case’ or ‘strategy’ in ‘thought or logic’ form, and just let the compiler *figure out* how to translate this into imperatives.

    No more ‘if (insuree.Count==2) amount = Insuree[2].Insurance.NetPremium’ before you can even start working with the amount, no more (let* ((hughe list)) … ) as seems to be the running idiom in any modern Scheme/Lisp:


    (let* ((previous current)
    (first (car area))
    (last (cadr area)))
    (set! current (+ last 1))
    (append accum (cons (sehe:skip-ab previous first)
    (map (lambda(n) (make-music 'SequentialMusic 'elements
    (case n
    ((1) (list #{ r2 #}))
    ((2) (list #{ r2 \drummode { bda4*2/1 } #}))
    (else (list #{ r2 \drummode { bda4*2/1 } #} (sehe:rest (- n 2))))
    )
    ))
    (maattabel 'flat-range first (+ last 1)))
    ))
    )

    I think I’ call it quits because (a) I don’t have time to illustrate the alternative in Nemerle (believe it will make your mouth water with it’s elegance) nor have I got an idea how thses snippets will show up in your blog.

    Time to find out
    Cheers

  2. Hi Seth, I don’t think until now I got a comment with that much information on my blog😉

    Yesterday I almost finished my first Boo plug-in as well and hopefully I can do some performance tests this week. It’s always fun to play around with ‘little’ languages like these.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: