Nemerle
编程范型 | |
---|---|
设计 | Kamil Skalski, Michał Moskal, Prof. Leszek Pacholski, Paweł Olszta 于 |
实现 | JetBrains |
发行时间 | 2003 |
| |
类型 | 类型推论, |
CLI | |
.n | |
网站 | nemerle |
Nemerle | |
启发语言 | |
C#, Lisp, ML |
Nemerle,
示 例
[编辑]Hello, World!
[编辑]class Hello { static Main () : void { System.Console.WriteLine("Hello, world!"); } }
System.Console.WriteLine("Hello, world!");
宏 的 例 子
[编辑]数 据 库访问
[编辑]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();
新 语言建 构
[编辑]macro ReverseFor(i, begin, body) syntax("ford", "(", i, ";", begin, ")", body) { <[ for($i = $begin; $i >= 0; $i--)$body ]> }
ford(i ; n)print (i);
Nemerle结合ASP.NET
[编辑]Nemerle
<%@ 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
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(); } }