Advertisement
Guest User

nemerle

a guest
Feb 13th, 2011
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.97 KB | None | 0 0
  1. <!-- Please do not remove or change this AfD message until the issue is settled -->
  2. {{Article for deletion/dated|page=Nemerle|timestamp=20110205203949|year=2011|month=February|day=5|substed=yes|help=off}}
  3. <!-- For administrator use only: {{Old AfD multi|page=Nemerle|date=5 February 2011|result='''keep'''}} -->
  4. <!-- End of AfD message, feel free to edit beyond this point -->
  5. {{Notability|date=April 2009}}
  6. {{expert-subject-multiple|.NET|Programming Languages|type=article|date=September 2009}}
  7.  
  8. {{Infobox programming language
  9. |name = Nemerle
  10. |logo =
  11. |paradigm = [[multi-paradigm programming language|multi-paradigm]]: [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[imperative programming|imperative]]
  12. |year =
  13. |designer = [[Kamil Skalski]], [[Michał Moskal]], Prof. [[Leszek Pacholski]] and [[Paweł Olszta]] at [[Wrocław University]]
  14. |developer =
  15. |latest release version = 1.0.0 Beta 2 Update
  16. |latest release date = {{start date|2010|09|24}}
  17. |typing = [[static typing|static]], [[strong typing|strong]], [[inferred typing|inferred]]
  18. |implementations = Nemerle
  19. |dialects =
  20. |influenced_by = [[C Sharp (programming language)|C#]], [[ML (programming language)|ML]], [[Lisp (programming language)|Lisp]]
  21. |influenced =
  22. |platform = [[Common Language Runtime|CLR]]
  23. |website = http://nemerle.org/Main_Page}}
  24.  
  25. '''Nemerle''' is a [[high level language|high-level]] [[static typing|statically typed]] [[programming language]] for the [[Microsoft .NET|.NET]] (see also [[Mono (software)|Mono]]) platform. It offers [[functional programming|functional]], [[object-oriented]] and [[imperative programming|imperative]] features. It has a simple [[C Sharp (programming language)|C#]]-like syntax and a powerful [[metaprogramming]] system.
  26.  
  27. It has been named after the archmage Nemmerle from "[[A Wizard of Earthsea]]" by [[Ursula K. Le Guin]] (spelling with a single ''m'' is a design decision).
  28.  
  29. ==Features==
  30. Probably the most important feature of Nemerle is the ability to mix [[object oriented]] and [[functional programming]] styles. The top-level program structure is object oriented, while in the body of methods one can (but is not forced to) use functional style. This is very handy in some programming problems. The feature set includes [[Delegates (programming)|functional values]], [[algebraic data types|variants]] and [[pattern matching]].
  31.  
  32. Another very important feature is taking a [[high level language|high-level]] approach in all aspects of the language—trying to lift as much of the burden from the programmer as possible. Features like [[metaprogramming|macros]] and [[type inference]] fit here.
  33.  
  34. Features that come from the functional land are [[algebraic data types|variants]] (aka algebraic data types), [[pattern matching]], [[type inference]] and [[generic programming|parameter polymorphism]] (aka generics). The [[metaprogramming]] system allows great [[compiler]] extensibility, embedding [[domain specific languages]], [[partial evaluation]] and [[aspect oriented programming|aspect-oriented]] programming.
  35.  
  36. Last but not least, the usage of more mundane library functionality from [[Microsoft .NET|.NET]] is as easy as in C#.
  37.  
  38. ===Type inference===
  39. <source lang="csharp">
  40. def x = 1; // int
  41. def myList = List(); // generic List[T], type T is deduced from the usage in the next line
  42. myList.Add(x); // compiler deduces type of T as int making myList type of List[int]
  43. </source>
  44. ===Everything is an expression===
  45. <source lang="csharp">
  46. def x =
  47. { // similar to x = 3
  48. def y = 1;
  49. def z = 2;
  50. y + z // this last statement is a block return value
  51. }
  52.  
  53. def x =
  54. if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) // if, using, try are also expressions
  55. "Monday"
  56. else
  57. "other day";
  58.  
  59. def x = try
  60. {
  61. Int32.Parse(someString)
  62. }
  63. catch
  64. {
  65. | FormatException() => 0;
  66. }
  67. </source>
  68. ===Tuples===
  69. <source lang="csharp">
  70. def k = (1, "one"); // k : (int * string)
  71. def (a, b) = k; // a = 1, b = "one"
  72. </source>
  73. ===Pattern matching===
  74. <source lang="csharp">
  75. def result = match (number)
  76. {
  77. | 0 => "zero"
  78. | 1 => "one"
  79. | x when x < 0 => "negative"
  80. | _ => "more than one"
  81. }
  82. </source>
  83. ===Functional types and local functions===
  84. <source lang="csharp">
  85. def next(x) { x + 1 };
  86.  
  87. def mult(x, y) { x * y }
  88.  
  89. def fibbonacci(i)
  90. {
  91. | 0 => 0
  92. | 1 => 1
  93. | other => other + fibbonacci(i - 1)
  94. }
  95.  
  96. Console.WriteLine(next(9)); // 10
  97. Console.WriteLine(mult(2, 2)); // 4
  98. Console.WriteLine(fibbonacci(10)); // 55
  99. </source>
  100. ===Metaprogramming===
  101. Nemerle allows to create, analyze and modify code of a program during a compilation process using a powerfull macro system. Macros can be used in a form of a method call or even a new language construction. Most of the Nemerle language constructions are macros (if, for, foreach, while, using etc.).
  102.  
  103. "if" macro example:
  104. <source lang="csharp">
  105. macro @if (cond, e1, e2)
  106. syntax ("if", "(", cond, ")", e1, Optional (";"), "else", e2)
  107. {
  108. /*
  109. <[ ]> defines an area of quasi-quotation, the Nemerle compiler transforms a code in a such block
  110. to an AST tree, such transformations are somewhat similar to an Expression compiling in C#
  111. */
  112. <[
  113. match ($cond : bool)
  114. {
  115. | true => $e1
  116. | _ => $e2
  117. }
  118. ]>
  119. }
  120.  
  121. // now we can use this macro in our code:
  122. def max = if (a > b) a else b;
  123. // during a compile time the upper line will be transformed to the following:
  124. def max = match (a > b)
  125. {
  126. | true => a
  127. | _ => b
  128. }
  129. </source>
  130.  
  131. == IDE ==
  132. Nemerle can be integrated into [[Visual Studio 2008]]. Also it has a completely free IDE based on [[Visual Studio 2008|Visual Studio 2008 Shell]] (like [[Visual Studio Express Edition]]s) and [[SharpDevelop]] ([http://code.google.com/p/nemerle/source/browse/#svn%2Fnemerle%2Ftrunk%2Fsnippets%2Fsharpdevelop link to plugin source code]).
  133.  
  134. ==Examples==
  135. ===Hello, World!===
  136. The traditional [[Hello world program|"Hello World!"]] can be implemented in a more C#-like fashion:
  137.  
  138. <source lang="csharp">
  139. class Hello {
  140. static Main () : void {
  141. System.Console.WriteLine ("Hello, world!");
  142. }
  143. }
  144. </source>
  145.  
  146. or more simply:
  147.  
  148. <source lang="csharp">
  149. System.Console.WriteLine("Hello, world!");
  150. </source>
  151.  
  152. ===Examples of macros===
  153. Macros allow you to have boilerplate code generated for you under the hood, with additional static checks performed by the compiler. They give you the power to programatically generate code.
  154.  
  155. ====Database accessibility====
  156. For example, using Nemerle macros for [[SQL]] you can write:
  157.  
  158. <source lang="csharp">
  159. ExecuteReaderLoop (
  160. "SELECT firstname, lastname FROM employee WHERE firstname = $myparm",
  161. dbcon,
  162. {
  163. System.Console.WriteLine ($"Name: $firstname $lastname")
  164. });
  165. </source>
  166.  
  167. instead of
  168.  
  169. <source lang="csharp">
  170. string sql = "SELECT firstname, lastname FROM employee WHERE firstname = :a";
  171. NpgsqlCommand dbcmd = new NpgsqlCommand (sql, dbcon, dbtran);
  172. dbcmd.Parameters.Add("a", myparm);
  173.  
  174. NpgsqlReader reader = dbcmd.ExecuteReader();
  175.  
  176. while(reader.Read()) {
  177. string firstname = reader.GetString (0);
  178. string lastname = reader.GetString (1);
  179. System.Console.WriteLine ("Name: {0} {1}", firstname, lastname)
  180. }
  181. reader.Close();
  182. dbcmd.Dispose();
  183. </source>
  184.  
  185. and this is not just hiding some operations in a library, but additional work performed by the compiler to understand the query string, the variables used there, and the columns returned from the database. The ExecuteReaderLoop macro will generate code roughly equivalent to what you would have to type manually. Moreover, it connects to the database at compilation time to check that your SQL query really makes sense.
  186.  
  187. ====New language constructs====
  188. With Nemerle macros you can also introduce some new syntax into the language:
  189.  
  190. macro ReverseFor (i, begin, body)
  191. syntax ("ford", "(", i, ";", begin, ")", body)
  192. {
  193. <[ for ($i = $begin; $i >= 0; $i--) $body ]>
  194. }
  195.  
  196. defines a macro introducing the ford (EXPR ; EXPR) EXPR syntax and can be used like
  197.  
  198. ford (i ; n) print (i);
  199.  
  200. ===Nemerle with ASP.NET===
  201. Nemerle can be either embedded directly into [[ASP.NET]]:
  202. <source lang="html4strict">
  203. <%@ Page Language="Nemerle" %>
  204. <script runat="server">
  205.  
  206. Page_Load(_ : object, _ : EventArgs) : void {
  207. Message.Text = $"You last accessed this page at: $(DateTime.Now)";
  208. }
  209.  
  210. EnterBtn_Click(_ : object, _ : EventArgs) : void {
  211. Message.Text = $"Hi $(Name.Text), welcome to ASP.NET!";
  212. }
  213.  
  214. </script>
  215.  
  216. <html>
  217. <body>
  218. <form runat="server">
  219. Please enter your name: <asp:TextBox ID="Name" runat="server" />
  220. <asp:Button OnClick="EnterBtn_Click" Text="Enter" runat="server" />
  221.  
  222. <p><asp:Label ID="Message" runat="server" /></p>
  223. </form>
  224. </body>
  225. </html>
  226. </source>
  227. ...Or stored in a separate file and entered with a single line:
  228. <source lang="html4strict">
  229. <%@ Page Language="Nemerle" Src="test.n" Inherits="Test" %>
  230. </source>
  231.  
  232. ===PInvoke===
  233. Nemerle can take advantage of native platform libraries. The syntax is very similar to C#'s and other [[Microsoft .NET|.NET]] languages. Here is the simplest example:
  234.  
  235. <source lang="csharp">
  236. using System;
  237. using System.Runtime.InteropServices;
  238.  
  239. class PlatformInvokeTest
  240. {
  241. [DllImport("msvcrt.dll")]
  242. public extern static puts(c : string) : int;
  243.  
  244. [DllImport("msvcrt.dll")]
  245. internal extern static _flushall() : int;
  246.  
  247. public static Main() : void
  248. {
  249. _ = puts("Test");
  250. _ = _flushall();
  251. }
  252. }
  253. </source>
  254.  
  255. ==External links==
  256. *[http://rsdn.ru/summary/3766.xml Publications about Nemerle in RSDN Magazine, russian official science magazine]
  257. *[http://research.microsoft.com/en-us/um/people/moskal/pdf/msc.pdf Type Inference with Deferral, Michał Moskal]
  258. *[http://research.microsoft.com/en-us/events/sscli2005/pacholski-moskal.pdf Nemerle presentation on Microsoft Research SSCLI RFP II Capstone 2005 workshop]
  259. *[http://nemerle.org/ Language Homepage]
  260. *[http://code.google.com/p/nemerle/ Project Hosting on Google Code]
  261. *[http://nemerle.org/Documentation#Language_documentation The official documentation]
  262. *[http://groups.google.com/group/nemerle-en Nemerle Forum]
  263. *[http://www.99-bottles-of-beer.net/language-nemerle-869.html Nemerle at 99 Bottles of Beer]
  264. *[http://d.hatena.ne.jp/akiramei/searchdiary?word=%2a%5bNemerle%5d Interesting entries about Nemerle from akiramei's diary (in Japanese)]
  265.  
  266. ==Books about Nemerle==
  267. * {{cite book
  268. | editor1-last = Timpledon
  269. | editor1-first = Lambert M.
  270. | editor2-last = Markeseken
  271. | editor2-first = Miriam T.
  272. | editor3-last = Surhone
  273. | editor3-first = Susan F.
  274. | title = Nemerle
  275. | publisher = [[Betascript Publishing]]
  276. | year = 2010
  277. | pages = 192
  278. | isbn = 9786130909895
  279. | url = http://search.barnesandnoble.com/Nemerle/Lambert-M-Surhone/e/9786130909895
  280. | accessdate = 2011-02-11
  281. }} The contents of this book are from Wikipedia and other free online sources.<ref>
  282. {{Cite web
  283. | title = Nemerle, Lambert M. Surhone, (9786130909895) Paperback - Barnes & Noble
  284. | publisher = [[Barnes & Noble]]
  285. | url = http://search.barnesandnoble.com/Nemerle/Lambert-M-Surhone/e/9786130909895
  286. | accessdate = 2011-02-11 }}
  287. </ref>
  288.  
  289. * {{cite book
  290. | editor = [[Books LLC]]
  291. | title = Ml Programming Language Family: Ml, Standard Ml, Objective Caml, Mythryl, F Sharp, Nemerle, Alice, Standard Ml of New Jersey, Concurrent Ml
  292. | publisher = [[Books LLC]]
  293. | year = 2010
  294. | month = July
  295. | pages = 100
  296. | isbn = 9781155461298
  297. | url = http://search.barnesandnoble.com/Ml-Programming-Language-Family/Books-LLC/e/9781155461298
  298. | accessdate = 2011-02-11
  299. }}
  300.  
  301. ==References==
  302. <references/>
  303.  
  304. {{DotNET}}
  305.  
  306. [[Category:Procedural programming languages]]
  307. [[Category:.NET programming languages]]
  308. [[Category:Object-oriented programming languages]]
  309. [[Category:ML programming language family]]
  310. [[Category:Programming languages created in 2003]]
  311.  
  312. [[ja:Nemerle]]
  313. [[pl:Nemerle]]
  314. [[ru:Nemerle]]
  315. [[fi:Nemerle]]
  316. [[tg:Nemerle]]
  317. [[uk:Nemerle]]
  318. [[zh:Nemerle]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement