Skip to content

Releases: sigmasoldi3r/charon-lang

Vector is now a list

15 Jul 19:26
Compare
Choose a tag to compare
Vector is now a list Pre-release
Pre-release
  • Added more collection checks like list/has? or list/find.
  • Added runtime type check with type function.
  • Added apply function, which takes a list as function arguments, unlike call.

Added more functions for vectors, existential check and more

12 Jul 22:15
Compare
Choose a tag to compare

Changelog:

  • Added vector/reduce-indexed, now vector/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? and not-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

12 Jul 09:39
Compare
Choose a tag to compare
Pre-release

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

11 Jul 12:09
Compare
Choose a tag to compare
Pre-release

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.

10 Jul 09:11
Compare
Choose a tag to compare

Minor fixes added to the runtime library:

  • some functions like atom/set were not returning unit explicitly.
  • some macro-like functions for comparison were lacking return! (Although they remain untested for now!!)
  • added existence checks for nothing? and unit?, 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.

10 Jul 08:19
Compare
Choose a tag to compare

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 and print are now println! and print!, 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's error.
; Before update
(def-extern error)
(if some-condition
  (error "Yo"))
; Now
(if some-condition
  (throw "Yo"))

When defaults, macro references, and fixed compiler bugs

10 Jul 07:26
Compare
Choose a tag to compare

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.

09 Jul 10:06
Compare
Choose a tag to compare

Snapshot notes:

  • Added runtime extraction option --extract-runtime, which creates a charon-runtime.lua file in your cwd.
  • 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 []) return unit 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

09 Jul 08:54
Compare
Choose a tag to compare
Pre-release

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

08 Jul 12:42
Compare
Choose a tag to compare
Pre-release

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!