珍妮特(Janet)是一種用於系統腳本,表達自動化的編程語言,並擴展了用用戶腳本功能編寫的C ++編寫的程序。
珍妮特(Janet)製作了一個良好的系統腳本語言,或者是一種嵌入其他程序的語言。在這方面,就像Lua和Gnu Guile一樣。它比LUA具有更多的內置功能和更豐富的核心語言,但比GNU Guile或Python小。但是,嵌入和端口比Python或Guile容易得多。
嘗試使用該語言以及運行腳本文件的能力有一個重複。該客戶端程序與核心運行時分開,因此Janet可以嵌入其他程序中。在https://janet-lang.org上嘗試在瀏覽器中嘗試Janet。
有關所有提供的示例程序,請參見示例目錄。
# John Conway's Game of Life
( def- window
( seq [ x :range [ -1 2 ]
y :range [ -1 2 ]
:when ( not ( and ( zero? x ) ( zero? y )))]
[ x y ]))
( defn- neighbors
[[ x y ]]
( map ( fn [[ x1 y1 ]] [( + x x1 ) ( + y y1 )]) window ))
( defn tick
" Get the next state in the Game Of Life. "
[ state ]
( def cell-set ( frequencies state ))
( def neighbor-set ( frequencies ( mapcat neighbors state )))
( seq [ coord :keys neighbor-set
:let [ count ( get neighbor-set coord )]
:when ( or ( = count 3 ) ( and ( get cell-set coord ) ( = count 2 )))]
coord ))
( defn draw
" Draw cells in the game of life from (x1, y1) to (x2, y2) "
[ state x1 y1 x2 y2 ]
( def cellset @{})
( each cell state ( put cellset cell true ))
( loop [ x :range [ x1 ( + 1 x2 )]
:after ( print )
y :range [ y1 ( + 1 y2 )]]
( file/write stdout ( if ( get cellset [ x y ]) " X " " . " )))
( print ))
# Print the first 20 generations of a glider
( var *state* '[( 0 0 ) ( -1 0 ) ( 1 0 ) ( 1 1 ) ( 0 2 )])
( for i 0 20
( print " generation " i )
( draw *state* -7 -7 7 7 )
( set *state* ( tick *state* ))) # A simple TCP echo server using the built-in socket networking and event loop.
( defn handler
" Simple handler for connections. "
[ stream ]
( defer ( :close stream )
( def id ( gensym ))
( def b @" " )
( print " Connection " id " ! " )
( while ( :read stream 1024 b )
( printf " %v -> %v " id b )
( :write stream b )
( buffer/clear b ))
( printf " Done %v! " id )
( ev/sleep 0.5 )))
( net/server " 127.0.0.1 " " 8000 " handler ) # Use the FFI to popup a Windows message box - no C required
( ffi/context " user32.dll " )
( ffi/defbind MessageBoxA :int
[ w :ptr text :string cap :string typ :int ])
( MessageBoxA nil " Hello, World! " " Test " 0 )文檔也可以在REPL中本地提供。使用(doc symbol-name)宏獲取核心庫中符號的API文檔。例如,
(doc apply)
顯示apply功能的文檔。
要獲取默認環境中所有綁定的列表,請使用(all-bindings)函數。如果您在臥室中顯示綁定的符號,則也可以使用(doc)宏沒有參數。
您可以在github或sourcehut上獲取源。雖然GitHub存儲庫是官方存儲庫,但SourceHut Mirror得到了積極的維護。
Makefile是不可存儲的,需要GNU味的品牌。
cd somewhere/my/projects/janet
make
make test
make repl
make install
make install-jpm-git通過運行make help以了解有關可用製造目標的更多信息。
32位Haiku構建說明與類似於Unix的構建說明相同,但是您需要指定替代編譯器,例如gcc-x86 。
cd somewhere/my/projects/janet
make CC=gcc-x86
make test
make repl
make install
make install-jpm-git FreeBSD構建說明與類似Unix的構建說明相同,但是您需要gmake進行編譯。或者,使用pkg install lang/janet直接安裝軟件包。
cd somewhere/my/projects/janet
gmake
gmake test
gmake repl
gmake install
gmake install-jpm-git NetBSD構建說明與FreeBSD構建說明相同。或者,使用pkgin install janet直接安裝軟件包。
cl.exe和link.exe需要在您的路徑上),並使用Janet cd目錄。build_win進行編譯Janet。build_win test以確保一切正常。要構建.msi安裝程序可執行文件,除上述步驟外,您還必須:
build_win dist 。現在您應該有一個.msi 。您可以運行build_win install以安裝.msi或執行文件本身。
珍妮特(Janet)還為跨平台構建系統梅森(Meson)提供了一個構建文件。儘管Meson具有Python的依賴性,但Meson是一個非常完整的構建系統,可能更方便和靈活地集成到現有管道中。 Meson還提供了比製造或批處理文件更好的IDE集成,以及對交叉補償的支持。
對於不耐煩的人來說,使用介子建造如下。在下面提供的meson setup的選項模仿Janet的Makefile。
git clone https://github.com/janet-lang/janet.git
cd janet
meson setup build
--buildtype release
--optimization 2
--libdir /usr/local/lib
-Dgit_hash= $( git log --pretty=format: ' %h ' -n 1 )
ninja -C build
# Run the binary
build/janet
# Installation
ninja -C build install珍妮特(Janet)幾乎可以在您喜歡的任何環境中被黑客入侵,但是對於IDE愛好者來說,Gnome Builder可能是最好的選擇,因為它具有出色的梅森集成。它還可以為Janet的C API提供代碼完成,這對於探索非常有用。 vscode,vim,emacs和atom都有珍妮特語言的語法包。
如果您只想嘗試該語言,則無需安裝任何內容。在這種情況下,您還可以在系統上想要的任何地方移動janet可執行文件並運行它。但是,要進行完整的設置,請參閱介紹以獲取更多詳細信息。
當二進制援引沒有參數的情況下,將啟動一個臥式。傳遞-h標誌以顯示使用信息。可以使用./janet myscript.janet運行單個腳本。
如果您想探索,則可以通過將命令(all-bindings)輸入REPP來打印所有可用宏,功能和常數的列表。
$ janet
Janet 1.7.1-dev-951e10f Copyright (C) 2017-2020 Calvin Rose
janet:1:> (+ 1 2 3)
6
janet:2:> (print "Hello, World!")
Hello, World!
nil
janet:3:> (os/exit)
$ janet -h
usage: janet [options] script args...
Options are:
-h : Show this help
-v : Print the version string
-s : Use raw stdin instead of getline like functionality
-e code : Execute a string of janet
-E code arguments... : Evaluate an expression as a short-fn with arguments
-d : Set the debug flag in the REPL
-r : Enter the REPL after running all scripts
-R : Disables loading profile.janet when JANET_PROFILE is present
-p : Keep on executing if there is a top-level error (persistent)
-q : Hide logo (quiet)
-k : Compile scripts but do not execute (flycheck)
-m syspath : Set system path for loading global modules
-c source output : Compile janet source code into an image
-i : Load the script argument as an image file instead of source code
-n : Disable ANSI color output in the REPL
-l lib : Use a module before processing more arguments
-w level : Set the lint warning level - default is "normal"
-x level : Set the lint error level - default is "none"
-- : Stop handling options
如果安裝,您還可以運行man janet以獲取使用信息。
Janet可以很容易地嵌入到主機程序中。普通構建將創建一個文件build/janet.c ,它是一個包含所有源到janet的單個C文件。該文件以及src/include/janet.h和src/conf/janetconf.h可以拖動到任何C項目中並將其編譯到其中。 Janet應在大多數編譯器上使用-std=c99編譯,並且需要鏈接到數學庫-lm和動態鏈接器-ldl ,如果一個人希望能夠加載動態模塊。如果不需要動態模塊,請在編譯器選項中添加定義-DJANET_NO_DYNAMIC_MODULES 。
有關更多信息,請參見網站上的嵌入部分。
隨時提出問題並加入Janet Zulip實例的討論
它與沒有JIT編譯器的大多數解釋語言的速度大致相同。緊密,關鍵的迴路可能應該用C或C ++寫。由於抑制了慢速面向對象的抽象,並明確使後期結合後,程序往往比使用Python這樣的語言要快一點。所有值默認情況下以8字節表示,並在堆上分配,除了數字,尼爾和布爾值外。 PEG引擎是可以有效處理字符串和緩衝數據的專業解釋器。
GC很簡單且停止世界,但是GC旋鈕在核心庫中暴露在外,單獨的線程具有孤立的堆和垃圾收集器。線程之間共享的數據是參考計數。
YMMV。
它可能存在,可能不存在。如果您想提出一項主要語言功能,請繼續並打開一個問題,但由於“不會實施”,它可能會關閉。通常,這樣的功能使一個用戶酶變得更簡單,以使語言更複雜,以犧牲5個用戶為代價。
目前,除了https://janet-lang.org上的文檔外,當前沒有規格。
沒有。這裡沒有缺點細胞。
否。這與Clojure上的表面相似,因為我喜歡Lisps,並且喜歡美學。在內部,珍妮特根本不像克洛傑爾,方案或普通lisp那樣。
不。它們是不可變的陣列和散佈桌。不要嘗試像Clojure的向量和地圖一樣使用它們,而是它們可以作為桌子鍵或其他標識符工作。
在某種程度上,是的。但是,這不是推薦的抽象方法,並且性能可能會受到影響。也就是說,表可以用來用遺傳和多態性製作可變的對象,其中用關鍵字實現對象方法。
( def Car @{ :honk ( fn [self msg] ( print " car " self " goes " msg)) })
( def my-car ( table/setproto @{} Car))
( :honk my-car " Beep! " )通常,有幾個原因之一:
可能,如果該語言與C具有良好的界面。但是程序員可能需要做一些額外的工作來將Janet的內部內存模型映射到綁定語言的內存模型。珍妮特還使用setjmp / longjmp進行內部非本地回報。現在,這種方法與許多程序員不滿意,並且並不總是在其他具有例外或堆棧不伴隨的語言中發揮作用。
確保您的終端支持ANSI逃生代碼。大多數現代終端都會支持這些,但是一些較舊的終端,Windows控制台或嵌入式終端不會。如果您的終端不支持ANSI逃生代碼,請用-n標誌運行REPL,從而禁用顏色輸出。如果隨之而來的是進一步的問題,您也可以嘗試-s標誌。
珍妮特(Janet)以幾乎無所不知且友好的人為的位置命名。