Snapshot của be5invis/PatEL: 57★ · JavaScript. The Patrisika Example Language
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
PatEL's syntax is based on Lisp's S-expression but with two significant changes:
Supports infix operators, like (1 + 2).
Use indents to avoid too-deep nests.
There are three fundamental constructions in PatEL:
Invocation: [a b c]
Infix: (x + y)
Struct: {a b c} and {.a 1 .b 2}
For invocations you can replace [a b [c d [e f g]]] with [a b : c d : e f g] to eliminate deep nests.
Invocations and Infixes can be written in line-level like this:
f2 a b c : x y z
d e f
g h i
j + k
This is identical to the form [f2 a b c [x y z [d e f] [g h i] (j + k)]], but much clearer.
Primitive Semantics
[if testconsequentalternate]
Evaluate test, then when it is true, evaluate and return consequent, otherwise evaluate and return alternate.
[if testconsequent]
Evaluate test, then when it is true, evaluate and return consequent, otherwise return nothing.
[piecewise [condition1consequent1] [condition2consequent2] ...]
Evaluate condition1, when it is true, evaluate and return consequent1; otherwise, evaluate the rest condition-consequent pairs in the same manner. When all conditions are all false, return nothing.
[match term [pattern1consequent1] [pattern2consequent2] ... ]
Evaluate term, and test whether it matches pattern1. When it matches, extract the parts mentioned in the pattern, evaluate and return consequent1. Otherwise, evaluate the rest pattern-consequent pairs in the same manner. When all patterns mismatch, return nothing.
Sample:
define [sum list] : match list
{} 0 # empty
{head :: rear} : head + [sum rear] # cons
otherwise : throw : new Error "Input is not a list." # everything else
[while testbody]
Assign temporary variable t to nothing.
Evaluate test, then when it is true, evaluate body and set t to the value of body, then loop; otherwise return t.
[return e]
Evaluate e, and immediately return the current function valued e.
[throw e]
Evaluate e, and throw an exception valued e.
[yield e]
Mark the current function as Generator Function.
Evaluate and yield e.
Sample:
define [endless] : begin
local x 0
while true : begin
yield x
set x : x + 1
define g : endless
console.log [g.next].value # 0
console.log [g.next].value # 1
[foreach [erange] body]
Enumerate items in range using standard ES6 semantics, assign the current item to e and evaluate body.
[define evalue]
Define a local constant e and set its value to value.
[local evalue]
Define a local variable e and set its value to value.
[local x]
Declare a local variable x and set it to nothing.
[define [fabc] body]
Define a local constant f, and set it to a function takes parameters a, b and c, and returns body.
[local [fabc] body]
Define a local variable f, and set it to a function takes parameters a, b and c, and returns body.
[define patternvalue]
Assign value to pattern, and declare all variables occurred in pattern as local constant. Function call patterns are not supported here. Function call patterns are not directly supported here, but can be used as sub-pattern.
[local patternvalue]
Assign value to pattern, and declare all variables occurred in pattern as local variable. Function call patterns are not directly supported here, but can be used as sub-pattern.
[lambda [abc] body]
Returns a function which takes parameters a, b and c, and returns body.
[set patternvalue]: Set pattern value to value. Function call patterns are not directly supported here, but can be used as sub-pattern.
[begin ab ... z]: Evaluate a, b, ..., z in order and return z's value.
Có — be5invis/PatEL phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/be5invis/PatEL.
be5invis/PatEL là gì?
be5invis/PatEL (be5invis/PatEL) là dự án JavaScript trên GitHub. Theo mô tả gốc: The Patrisika Example Language
Đọc thêm về be5invis/PatEL ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/be5invis/PatEL là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
PatEL có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về PatEL.