Releases: sigmasoldi3r/charon-lang
Vector is now a list
- Added more collection checks like
list/has?
orlist/find
. - Added runtime type check with
type
function. - Added
apply
function, which takes a list as function arguments, unlikecall
.
Added more functions for vectors, existential check and more
Changelog:
- Added
vector/reduce-indexed
, nowvector/reduce
does not pass the index. This was a problem
when using references to n-ary functions like+
, because:
(vector/reduce [1 2 3 4] +)
Would end up summing all plus their indexes. Now is corrected and can be used as shown.
- Added multiple application macro for
->>
and<<-
. They will pass the first item to the rest of
the calls and store the results in a vector:
(->> 1 (+ 2) (- 2) (* 2)) ; Translates to:
[(+ 1 2) (- 1 2) (* 1 2)]
- Added more existential checks for negated versions of unit and nothing:
not-unit?
andnot-nothing?
. - Added iterable object lookup operator
in?
which returns true if any argument passed is found by
equality check (Lua's==
) within the first object. The passed object can be a Lua object, a table or a vector. - Added bindings for
assert
function. Takes a boolean and will throw an error with the second argument on false. - Better error reporting, specially when the error comes from the parsing stage.
Added binary-like operators guards
Now passing a BOP only one or zero arguments will throw a syntax error.
After that patch, doing like (= 5)
would be translated to ()
which is not valid in Lua.
Example:
spelunker.crn:140:29
] (or (= "Y" i) (= "y" ) (= "N" i) (= "
^^^^^^^^
Error: Operator #eq needs at least two arguments!
Self recursion trait added
Now you can define anonymous functions via (fn [])
that can call themselves without having a name.
Example:
; 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))))
You could use this operator even when using def, although not mandatory:
(def-impure count! [n]
(println! "n =" n)
(if (= n 0) unit
(#' (- n 1))))
(count! 5)
Minor fixes on runtime api, added two functions.
Minor fixes added to the runtime library:
- some functions like
atom/set
were not returningunit
explicitly. - some macro-like functions for comparison were lacking return! (Although they remain untested for now!!)
- added existence checks for
nothing?
andunit?
, now you can differentiate a non-existent value from a unit value.
; Example, suppose a table:
(def-value tbl
{ :a-key "Hey"
:another unit
})
; Here some? returns false for both ":another" and anything not contained:
(some? (:another tbl)) ; False
(some? (:unknown tbl)) ; False also
; Now you can do:
(nothing? (:unknown tbl)) ; True
(nothing? (:another tbl)) ; False
Also you can use (unit? val)
which is exactly the same as doing (= val unit)
.
Negative numbers, throw expression and print/ln name changes.
Fixed a major bug that prevented negative numbers from being seen as is. They were parsed like names, for example -1
would be a name instead of a number. This is because -
is a valid name token, and numbers are allowed before letters and symbols.
Example: a-1
would be a valid name.
- Fixed
-1
issue. println
andprint
are nowprintln!
andprint!
, because they're impure functions and that makes it clearer.- Added
throw
expression. Before that the only way of rising an error was to define externally Lua'serror
.
; Before update
(def-extern error)
(if some-condition
(error "Yo"))
; Now
(if some-condition
(throw "Yo"))
When defaults, macro references, and fixed compiler bugs
Changelog:
- Fixed a bug that made
(let [] )
binding not be able to be used as an expression. - Macro-like functions like
+
,-
,*
... can be referenced by name now like(atom/apply! my-atom + 1)
. Before they could be used only as function calls like(+ 1 2 3)
. - When now has a default case using the symbol
#
, this feature is under test, future proposals might change what symbols are used, and how the default case is handled.
Example of usage from this draft:
(when some-var
:some-case "case result"
"some other" "other case"
# "default case")
For loops, guarded empty functions and runtime extraction.
Snapshot notes:
- Added runtime extraction option
--extract-runtime
, which creates acharon-runtime.lua
file in yourcwd
. - For loops, presumably for side effects.
- Numeric-ranged loop is optimized away as a numeric for.
- value-key paired fors are translated as
pairs()
, including range if needed.
- Empty functions such as
(def e [])
returnunit
instead of nothing now. - Attempting to invoke
unit
gives a clearer runtime error message now.
Example of for loop usage:
; For loop, for side-effects (Sometimes you need 'em).
; Numeric for like this one is optimized away as a normal for
(for [i (range 0 10)]
(println (str "i = " i)))
; Other sources of iterable components are transformed to pairs:
(for [v [1 2 3 4]]
(println (str "v = " v)))
; If you put two names, the for will always run in pairs:
; Being the second the "index" or the "key" depending on what you're iterating.
(for [v i (range 10 20)]
(println (str i " = " v)))
Note: Using shared runtime will make your files much more small! Consider using if not a standalone package.
Added when expression + docs
Added the API documentation at docs.md page (Still in progress).
Major change:
Charon now supports when
expressions, although does not have a default case for not matching case (Future snapshot).
Example of when expression (Used in sample.crn)
(def-val val
(when *some-input*
:opt-a 5
:opt-b "Hello"
:etc { :dunno "What else?" }))
Second draft including two bugs
This draft includes two bugfixes:
table/get
order was swapped, now the first argument is the key and the second the table.
; Example of usage
(def-value my-val
(table/get :some-key from-my-table))
- The operator
>>=
for dynamic function composition was missing in the runtime and bindings, added now. Only supports binary composition at the moment, not nary composition.
That's it. More patches will be uploaded whenever a bug is fixed!