News for hackers. Stuff that matters.
Re:Mono 3.2.7 is out by yawgmoth on Wednesday February 26, 2014 @02:20PM (#7306957)
On [1], what does the underscore mean?

public SampleModule() { Get["/"] = _ => "Hello World!"; }

[1] http://nancyfx.org/

Re:Mono 3.2.7 is out by damianh on Wednesday February 26, 2014 @02:25PM (#7307003)
It's the 'Dynamic Dictionary' [0]. It's usually called 'parameters' but it's idiomatic in dotnet to name lambda input parameter '_' if don't use it in your expression.

[0] https://github.com/NancyFx/Nancy/wiki/Taking-a-look-at-the-D...

Re:Mono 3.2.7 is out by JohnBooty on Wednesday February 26, 2014 @04:28PM (#7307994)
As others have said, it's idiomatic to name a lambda param "_" if you're not using it.

To perhaps clarify a bit, here's what the Hello World example would look like if we added a second route that uses the lambda parameter, and a third route that does something else, and a fourth route that renders a view template.

  public SampleModule() { 
    Get["/"] = _ => "Hello World!"; 

    Get["/hello/{name}"] = p => ("Hello, " + p.name + "!");

    Get["/something-complicated"] = _ => {
      // complicated stuff happens here
      return "OK... we're all done";
    };

    // A variety of template engines are supported
    Get["/my-resume"] = _ => View["resume.cshtml"];
   
  }
Re:Mono 3.2.7 is out by ntnj on Wednesday February 26, 2014 @02:22PM (#7306986)
Unused parameter for lambda function.
Re:Mono 3.2.7 is out by SideburnsOfDoom on Wednesday February 26, 2014 @02:40PM (#7307110)
This is the most accurate reply. The expression

    Get["/"] = _ => "Hello World!";
is actually of the form a = b;

Where "a", i.e. "Get["/"]" is an array-like property (http://msdn.microsoft.com/en-us/library/2549tw02.aspx ) and the "b" value assigned to it is an anonymous function with one parameter, i.e.

    _ => "Hello World!"
In Nancy these handlers are of the type Func<dynamic, dynamic> ( http://msdn.microsoft.com/en-us/library/bb549151(v=vs.110).a... ) The parameter could be given any legal name, but an underscore is a convention meaning "I am not using this param".
Re:Mono 3.2.7 is out by romanovcode on Wednesday February 26, 2014 @02:29PM (#7307032)
It's dynamic path element.

    public SampleModule()
    {
        Get["/{id:int}"] = _ =>
        {
            int id = _.id;
            return "Parameter ID is: " + id.ToString();
        };
    }