5 Replies - 7443 Views - Last Post: 02 February 2011 - 08:50 PM

#1 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,479
  • Joined: 27-December 08

Week #50- Nemerle

Post icon  Posted 29 December 2010 - 09:23 PM

This week's challenge is Nemerle. Thanks to AdamSpeight2008 for creating this challenge!

Warning!
Spoiler




Nemerle

Nemerle.org said:

Nemerle is a high-level statically-typed programming language for the .NET platform. It offers
functional, object-oriented and imperative features. It has a simple C#-like syntax and a powerful meta-programming system.




Download & Resources
Nemerle on Google Code
Nemerle .org (many of the links no longer work.)

Example of Nemerle SourceCode.
I've chosed the 99 Bottle of Beer example because it demonstrates and utilises, the syntax of
#pragma indent
using System;
using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using System.Collections.Generic;
using System.Console;
using System.Linq;

module Program
{
  Main() : void
  {
 	def capitalize=(str)=>{ Char.ToUpper(str[0]).ToString() + str.Substring(1);}
  def beers(n){
            | 0 => "no more bottles of beer"
            | 1 => "1 more bottle of beer"
            | _ => $"$n bottles of beer"}
  def passAround(n){
                 | 0 => $"Go to the store and buy some more, $(beers(99)) on the wall.\n"
                 | _ => $"Take one down and pass it around, $(beers(n-1)) on the wall.\n" }
 def onTheWall = n => $"$(beers(n)) on the wall, $(beers(n)).\n";
 
  $[99, 98 .. 0].Iter(n => Console.WriteLine(capitalize(onTheWall(n)) + passAround(n)));
  _ = System.Console.ReadKey(true);
  }
}



It first glance it looks a lot like C#, it is but with a cut and trim.

Quick overview.
In Nemerle all methods are Functions, which makes it like a Functional language like OCaml.
This means there are no subroutines. The value return by a method is the last expression on the stack before it exits. To simulate a subroutine you can return the void literal.

def beers(n)
          | 0 => "no more bottles of beer"
          | 1 => "1 more bottle of beer"
          | _ => $"$n bottles of beer"

Think of this as a Select Case ... End Select on steroids.
1st option is when n == 1
2nd option is when n == 0
3rd option is the wild card / default.
but cases don't have to be simple values, they can be nearly any expression.

It also use C# style strings, plus it has version that allows you the embedded the value of expressions inside them. Eg
$"$(beers(n)) on the wall, $(beers(n)).\n" outputs (lets say n=12
"10 bottles of beer on the wall, 10 bottles of beer.


In Nemerle all methods are Functions, which makes it like a Functional language like OCaml.

passAround(n)
  | 0 => $"Go to the store and buy some more, $(beers(99)) on the wall.\n"
  | _ => $"Take one down and pass it around, $(beers(n-1)) on the wall.\n"



Some of the more advance things to Nemerle can do. Do to it having a meta-programming system is that the syntax, grammar and operators of Nemerle, can be user defined just by writing Nemerle code.

Nemerle is partly written in Nemerle.

Is This A Good Question/Topic? 0
  • +

Replies To: Week #50- Nemerle

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,023
  • Joined: 15-July 08

Re: Week #50- Nemerle

Posted 29 December 2010 - 10:13 PM

Looks like an interesting mix. I'm learning Haskell at the moment and so much of that looks very, very familiar. I like how it can be truly functional, but yet also be truly imperitive or OO. Will give this a look.
Was This Post Helpful? 0
  • +
  • -

#3 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Week #50- Nemerle

Posted 30 December 2010 - 09:22 AM

I was under the impression that Nemerle was a dead language. For a long time, it was utterly stagnant.

Nonetheless, Nermele has been doomed from the moment F# came out, supported by Microsoft. At least, I'll be surprised if it makes an honest comeback.

The thing that interests me the most about the language is the syntax. Rarely do you see functional languages take on a curly-bracket syntax like C#. Scala is one that comes to mind. I have to say though, I think Nemerle's syntax is a bit messier than Scala's.

In any case, it's certainly an interesting language and definitely worthy of a challenge.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,418
  • Joined: 29-May 08

Re: Week #50- Nemerle

Posted 30 December 2010 - 10:58 AM

I think Nemerle is in "Goldilocks Zone", doesn't look too functional to scare away people and looks similar enough to c# entice them. And that coming from a vb guy, I like that fact it has macros on custom operators (ie. it not restricted to the traditional mathematical overload-able symbols)

The last update was about Dec 28th 2010.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Vlad*


Reputation:

Re: Week #50- Nemerle

Posted 30 December 2010 - 12:12 PM

View Postmacosxnerd101, on 29 December 2010 - 08:23 PM, said:

Nemerle is partly written in Nemerle.


Nemerle completely written on himself (using bootstrapping).
Was This Post Helpful? 0

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,418
  • Joined: 29-May 08

Re: Week #50- Nemerle

Posted 02 February 2011 - 08:50 PM

Nemerle Studio
To install you install the VS2008 isolated shell.
The install Latest Candidate Release.

This post has been edited by AdamSpeight2008: 02 February 2011 - 08:55 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1