sigmasoldi3r / charon-lang Goto Github PK
View Code? Open in Web Editor NEWCharon is a functional, LISP flavoured language that compiles to Lua.
Home Page: https://sigmasoldi3r.github.io/charon-lang/
License: MIT License
Charon is a functional, LISP flavoured language that compiles to Lua.
Home Page: https://sigmasoldi3r.github.io/charon-lang/
License: MIT License
Refactoring of terms + module syntax #8
def
-> defn
def-impure
-> defn!
def-value
-> def
def-extern
-> declare
All this functions should be tested against their macro-counterpart and return true:
+
-
*
/
>
<
>=
<=
=
<>
An assertion test should be written.
; Example
(assert
(= (+ 1 2 3 4) (call + 1 2 3 4))
"Results should be identical")
Add anonymous self-recursion for lambdas.
#'
prime wildcard for self-recursion will be added.#
).Example:
; Example of tail-recursion
; Fibbonacci tail-rec fn
(def-value fib
(fn [n a? b?]
(let [a (or? a? 0)
b (or? b? 1)
]
(if (= n 0) a
(if (= n 1) b
(#' (- n 1) b (+ a b)))))))
(let [n 9]
(println! (str "fib(" n ") = " (fib 9))))
String split can be very handy, and while charon has list/join
, it does lack string/split
which also Lua lacks.
Instead of baking a new function in each script, we can have a custom runtime function like:
(declare string/split :pure [string by?=","] :list)
(string/split "a,b,c")
As in javascript the natural first element of an array is 0, when destructuring, the compiler will assign that index to the first element. That's not the case for Lua, hence when destructuring you must always include a nil element:
(let [[_ a b c] some-list]
...)
Tuple literal eg: '(:a 2 "b")
.
Unit could be replaced by the zero-element tuple '()
like in scheme.
Tuples should:
'(:a 5 "b")
At the moment a single pass is done for referential check.
This means that the symbol must be defined prior to the usage, although not needed, like:
(def use-some []
(some)) ; ERROR!
(def some [])
The compiler will complain abount undefined symbol some
.
Instead, you should have:
(def some [])
(def use-some []
(some)) ; OK
Which should not be needed. In order to avoid this, the symbol checker should do a single pass before to collect symbol definitions.
Right now programs can check existence (or not) of the program only through some?
(and others).
This construct is really heavily used:
(not (some? ...))
Which is tedious, we can add a macro like:
(not-some? ...)
Instead.
Currently the compiler only supports the def
global binding.
There should be added a private binding, which would not be exported by the module.
The syntax is the same as the public, with a hyphen in the name: (def- private-def 99)
.
Right now the purity check can only be done through: defn
and defn!
.
If you define a pure or impure function by value, or reference it will lose it's purity annotation:
(def is-pure
(fn [a b]
(+ a b)))
This is a pure function, but not stored as is. The same goes for other means of passing by reference.
Add to docs the definition and usage hints of the following API methods:
Users might need while loop in edge cases, which are easier to write than recursion in some cases.
This statement is presumed to produce side effects.
(while condition do-expr)
Returns, like for, unit.
Add more insight about object manipulation methods:
Allow the parser to generate expression trees from string interpolation.
Use (declare)
instead of (def-extern)
Add to documentation the following table methods, which are not mentioned:
The next update will introduce destructuring assignment in let bindings, and pattern matching for when
statements.
Also, the default value gets replaced by _
instead of #
wildcard, as the syntax will collide with future uses.
#
by _
for defaults or unmatched results.let
destructuring when the left-hand element is a list.[_ 5 _]
)--extract-runtime --global-export
--global-export
(module module-name)
--no-runtime-require
Flag | Alias |
---|---|
--global-export |
-g |
--no-runtime-require |
-q |
Module exporting is a hassle, when imported anonymously is fine. But some systems (Specially embed ones) do not allow traditional require
syntax.
To solve this, the modules might be exposed globally, and the name of the module can be given by a (module)
call:
(module my-mod
[:import [a b c] :from "other-lib"]
[:import "more-libs"])
; Import vector is optional and can be added any number of them.
; Equivalent to call (import x :from "...")
Anonymous modules will emit a warning, and if the option --global-export
is present,
Each type annotation should have it's own type check function, so instead of doing every time:
(= (type my-value) :string) ; For example...
You just:
(string? my-value)
string?
number?
table?
object?
list?
boolean?
Nothing and unit checks are already implemented by https://github.com/sigmasoldi3r/charon-lang/releases/tag/v0.5.1-rc.1
nothing?
unit?
Now charon is lacking cast functions such as Lua's tonumber
Document atom manipulation methods.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.