For faster navigation, this Iframe is preloading the Wikiwand page for Nemerle.

Nemerle

Nemerle
编程范型多范型: 函数式, 指令式, 元编程, 面向对象
設計者Kamil Skalski, Michał Moskal, Prof. Leszek Pacholski, Paweł Olszta 于弗羅茨瓦夫大學
實作者JetBrains
发行时间2003年,​21年前​(2003
当前版本
  • 1.2.547.0 (2017年9月1日)[1]
編輯維基數據鏈接
型態系統类型推论, 名称, 静态, 强类型
系统平台CLI
文件扩展名.n
網站nemerle.org
主要實作產品
Nemerle
啟發語言
C#, Lisp, ML

Nemerle,是微軟公司提出的.NET平台上的新語言,由Wrocław大學的Kamil Skalski、Michał Moskal、Prof. Leszek Pacholski、Paweł Olszt等人發明。

範例

[编辑]

Hello, World!

[编辑]

一個傳統的"Hello World!"可以被寫成C#-like的風格:

class Hello {
  static Main () : void {
    System.Console.WriteLine("Hello, world!");
  }
}

或更簡捷:

System.Console.WriteLine("Hello, world!");

巨集的例子

[编辑]

巨集可以讓你擁有自己的模板(boilerplate),具有靜態檢查功能。

資料庫存取

[编辑]

例如,使用Nemerle macros可以將SQL可成:

ExecuteReaderLoop ("SELECT firstname, lastname FROM employee WHERE firstname = $myparm", dbcon,
{
  System.Console.WriteLine ("Name: {0} {1}", firstname, lastname) 
});

取代

string sql = "SELECT firstname, lastname FROM employee WHERE firstname = :a";
NpgsqlCommand dbcmd = new NpgsqlCommand(sql, dbcon, dbtran);
dbcmd.Parameters.Add("a", myparm);

NpgsqlReader reader = dbcmd.ExecuteReader();

while(reader.Read()) {
  string firstname = reader.GetString (0);
  string lastname = reader.GetString (1);
  System.Console.WriteLine ("Name: {0} {1}", firstname, lastname) 
}
reader.Close();
dbcmd.Dispose();

上述的程式碼不僅只是隱藏部份的動作,更可增加編譯器在查詢字串上的效率。這裡使用的變數,由資料庫回傳行資料(columns)。ExecuteReaderLoop巨集會產生一些你想要的粗略的程式碼。而且,連結資料庫並檢查SQL語法是否合法。

新語言建構

[编辑]

使用Nemerle巨集(macros)可以產生更新式的語法(syntax):

macro ReverseFor(i, begin, body) 
syntax("ford", "(", i, ";", begin, ")", body)
{
  <[ for($i = $begin; $i >= 0; $i--)$body ]>
}

定義一個巨集ford(EXPR ; EXPR)EXPR syntax可被寫成

ford(i ; n)print (i);

Nemerle結合ASP.NET

[编辑]

Nemerle可以被直接嵌入ASP.NET:

<%@ Page Language="Nemerle" %>
 <script runat="server">
 
     Page_Load(_ : object, _ : EventArgs): void {
         Message.Text = $"You last accessed this page at: $(DateTime.Now)";
     }
 
     EnterBtn_Click(_ : object, _ : EventArgs): void {
         Message.Text = $"Hi $(Name.Text), welcome to ASP.NET!";
     }
 
 </script>
 
 <html>
     <body>
         <form runat="server">
             Please enter your name: <asp:TextBox ID="Name" runat="server" />
             <asp:Button OnClick="EnterBtn_Click" Text="Enter" runat="server" />
 
             <p><asp:Label ID="Message" runat="server" /></p>
         </form>
     </body>
 </html>

...或者儲成單一檔案格式,一行完成:

<%@ Page Language="Nemerle" Src="test.n" Inherits="Test" %>

PInvoke

[编辑]

Nemerle有更多原生平台函式庫(native platform libraries)。風格非常類似C#'s和其它.NET平台上的語言。下面是最簡單的例子:

using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
    [DllImport("msvcrt.dll")]
    public extern static puts(c : string): int;
 
    [DllImport("msvcrt.dll")]
    internal extern static _flushall() : int;
    
    public static Main() : void
    {
        _ = puts("Test");
        _ = _flushall();
    }
}

外部連結

[编辑]
  1. ^ http://nemerle.org/BuildHistory?major=1&minor=2.
  2. ^ Nemerle 1.2.507.0
{{bottomLinkPreText}} {{bottomLinkText}}
Nemerle
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?