Submit A Challenge

  • (8 Pages)
  • +
  • « First
  • 6
  • 7
  • 8

107 Replies - 44434 Views - Last Post: 12 January 2011 - 11:35 AM

#106 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,434
  • Joined: 29-May 08

Re: Submit A Challenge

Posted 29 December 2010 - 07:14 AM

Week#xx: Nemerle

Week: xx Nemerle
written by AdamSpeight2008

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.
Was This Post Helpful? 1
  • +
  • -

#107 xVengeance  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 12-March 09

Re: Submit A Challenge

Posted 11 January 2011 - 08:49 PM

I challenge you to create a new "52 Weeks of Code" for the 2011 year and archive the one for the 2010 year!
Was This Post Helpful? 0
  • +
  • -

#108 Fungle  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 256
  • View blog
  • Posts: 337
  • Joined: 06-March 10

Re: Submit A Challenge

Posted 12 January 2011 - 11:35 AM

This is sort of a suggestion but, A week where the objective is to make a program in the worst way possible would be a good idea, much like this thread: http://www.dreaminco...31-hello-world/

Would make a nice change to see how badly someone can achieve a goal ^^
Was This Post Helpful? 0
  • +
  • -

  • (8 Pages)
  • +
  • « First
  • 6
  • 7
  • 8