5種你可能從未聽說過的編程語言
一起來看一看你可能最聞所未聞的5種編程語言吧。
1.Nim
我喜歡用Nim編碼,是因為它很有意思。Nim模糊了編譯和腳本語言之間的界線。下面是源代碼:
proc update(options: Options) =Downloads the package list from the specified URL.
#
If the download is successful, the global didUpdatePackages is set to
true. Otherwise an exception is raised on error.
let url = if options.action.typ == actionUpdate and options.action.optionalURL != "": options.action.optionalURL else: defaultPackageURL echo("Downloading package list from " & url) downloadFile(url, options.getNimbleDir() / "packages.json") echo("Done.")</pre>
還有長一點的:
proc parseConfig*(): Config = result = initConfig() var confFile = getConfigDir() / "nimble" / "nimble.ini"var f = newFileStream(confFile, fmRead) if f == nil:
# Try the old deprecated babel.ini confFile = getConfigDir() / "babel" / "babel.ini" f = newFileStream(confFile, fmRead) if f != nil: echo("[Warning] Using deprecated config file at ", confFile)
if f != nil: echo("Reading from config file at ", confFile) var p: CfgParser open(p, f, confFile) while true: var e = next(p) case e.kind of cfgEof: break of cfgSectionStart: discard of cfgKeyValuePair, cfgOption: case e.key.normalize of "nimbledir":
# Ensure we don't restore the deprecated nimble dir. if e.value != getHomeDir() / ".babel": result.nimbleDir = e.value of "chcp": result.chcp = parseBool(e.value) else: raise newException(NimbleError, "Unable to parse config file:" & " Unknown key: " & e.key) of cfgError: raise newException(NimbleError, "Unable to parse config file: " & e.msg) close(p)</pre> <h2> 2.Felix</h2>
Felix是獨一無二的。它是C ++、ML以及許多獨特構想的結合。下面摘自我寫的一個小型JSON解析器:
class JSON { typedef LineType = int;union Value = | Object of strdict[Value] | Array of list[Value] | String of string | Number of double | True | False | Null | Error of string * LineType ; union Token = | TString of string | TNumber of double | TLBrace // { | TRBrace // } | TLBrak // [ | TRBrak // ] | TColon // : | TTrue // true | TFalse // false | TNull // null | TEOF | TError of string * LineType ; instance Str[Token] { fun str(t: Token) => match t with | TString ?s => "TString \"" + s + "\"" | TNumber ?n => "TNumber " + n.str | TLBrace => "TLBrace" | TRBrace => "TRBrace" | TLBrak => "TLBrak" | TRBrak => "TRBrak" | TColon => "TColon" | TTrue => "TTrue" | TFalse => "TFalse" | TNull => "TNull" | TEOF => "TEOF" | TError (?s, ?i) => "error at line " + i.str + ": " + s endmatch; } proc lex(s: string, line: &LineType, outs: oschannel[Token]) = { line <- 1; proc tok(t: Token) => write $ outs, t; proc err(s: string) = { tok $ TError(s, *line); return from lex; }; var i = 0.size; while i < s.len do while s.[i].isspace do if s.[i] == "\n" do *line++; done; i++; if i >= s.len goto eof; done; // number if s.[i].isnumeric or (i+1 < s.len and s.[i] == "-" and s.[i+1].isnumeric) do d := s.[i to].double; i += d.str.len; tok $ TNumber d; // string elif s.[i] == "\"" do i++; var st = ""; while i < s.len and s.[i] != "\n" and s.[i] != "\"" do st += s.[i]; i++; done; if s.[i] != "\"" call err "unterminated string literal"; i++; tok $ TString st; // literals elif s.[i to i+4] == "true" do tok $ TTrue; i += 4.size; elif s.[i to i+5] == "false" do tok $ TFalse; i += 5.size; elif s.[i to i+4] == "null" do tok $ TNull; i += 4.size; // others else match s.[i].str with | "{" => tok TLBrace; | "}" => tok TRBrace; | "[" => tok TLBrak; | "]" => tok TRBrak; | ":" => tok TColon; | _ => err "unknown token"; endmatch; i++; done; done; eof:> tok TEOF; }
}</pre>
你也可以鑒賞一下我寫的這個JSON解析器,這是鏈接。
它有一些很不錯的功能,如schannels(一種協同程序)。 schannels就像Go的channels,不過并不是并發的。Felix還有另一個類似Go的channels,叫做fchannels,這是并發的。
Felix有一套不錯的工具(Web服務器,明白易懂的編程格式,α-品質的圖形配置工具)和尺寸剛好的標準庫。
至于缺點?文檔很少。不過,郵件討論非常活躍。
3.Myrddin
Myrddin一些功能:
- 類型推斷
- 模式匹配
- Go風格slices切片
- C風格的內存管理
舉個libbio輸入/輸出庫的例子。下面是其中的一個片段:
/* writes to as much from `src` as possible to a file, returning the number of bytes written. */ const write = {f, src std.assert(f.mode & Wr != 0, "File is not in write mode") /* Tack small writes onto the buffer end. Big ones flush the buffer and then go right to kernel. */ if src.len < (f.wbuf.len - f.wend) std.slcp(f.wbuf[f.wend:f.wend+src.len], src) f.wend += src.len -> src.len else flush(f) -> writebuf(f.fd, src) ;; }
4.K
K,連同Kona非常特別。它是將APL推進ASCII字符世界的結果。
下面是一些在Kona wiki的慣用語:
shuffle:{x@<>(#x)#1 0} / Perfect shuffle mean:{(+/x)%#x} / Arithmetic mean fac:*/1+!: / Factorial fib:{x{x,+/-2#x}/!2} / Fibonacci life:{|/(1;x)&3 4=\:+/,/2{-1 0 1!'\:x}/x} / Conway's Game of Life sort:{x@<x} / Sort list powerset:{x[&:'!2+&#x]} / Powerset
正如你所看到的,K非常簡潔,就是可能有點太過了。然而,作為數組處理語言,它功能卓越,而且快速。
5.Objeck
Objeck用起來特別給力:
class Factorial { function : native : Factorial(n : Int) ~ Int { if (n <= 1) { return n; } else { return n * Factorial(n-1); }; }function : Main(args : String[]) ~ Nil { "Number: "->Print(); number := IO.Console->ReadString()->ToInt(); if (number < 0) { "Number must be greater than 0"->PrintLine(); Runtime->Exit(1); }; Factorial(number)->PrintLine(); }
}</pre>
它的缺點是沒有真正的本地編譯器。
其他
還有我沒有提到過的ani和Alore。
Ani是一種隱含并行性和非常速度的的編程語言。而Alore是基于靜態和動態類型自由組合的編程語言。
總結
我要介紹的就到這里,希望能能你眼前一亮。
譯文鏈接:http://www.codeceo.com/article/5-programming-language-never-heard.html
英文原文:The top 5 programming languages you've never heard of
翻譯作者:碼農網 – 小峰本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!