Giter VIP home page Giter VIP logo

charon-lang's People

Contributors

dependabot[bot] avatar sigmasoldi3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

charon-lang's Issues

[Proposal draft] Recrusive call operator #'

Add anonymous self-recursion for lambdas.

  • New operator: #' prime wildcard for self-recursion will be added.
  • Wildcard parsing is now more flexible (Instead of just #).

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))))

Add string/split function

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")

Destructuring starts at 0

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]
  ...)

[Proposal draft] Tuple literal

Tuple literal eg: '(:a 2 "b").
Unit could be replaced by the zero-element tuple '() like in scheme.

Tuples should:

  • Have a fixed cardinality.
  • Immutable.
  • Strict dynamic types, this means that types are asserted at runtime for type equality by using the type operator.
'(:a 5 "b")

Hoist symbol definitions

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.

Add not-version of some?

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.

Create private global bindings

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).

Enhance symbol definition

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.

Document list methods

Add to docs the definition and usage hints of the following API methods:

  • list/map
  • list/each
  • list/get
  • list/filter
  • list/merge
  • list/append
  • list/prepend
  • list/drop
  • list/drop-left
  • list/len
  • list/has?
  • list/find
  • list/reduce
  • list/reduce-indexed

Add a while loop

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.

Document table methods

Add to documentation the following table methods, which are not mentioned:

  • table/get
  • table/get?
  • table/remove
  • table/merge

Destructuring assignment and pattern matching

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.

  • Replace wildcard # by _ for defaults or unmatched results.
  • let destructuring when the left-hand element is a list.
  • When pattern matching with lists (eg: [_ 5 _])
  • Deep equality check for list metatable.

Add export options plus module definition [language proposal]

  • Add the option to expose charon runtime globally with --extract-runtime --global-export
  • Add the option to export the module globally under it's name with --global-export
  • Module naming expression (module module-name)
  • Prevent requiring the runtime with --no-runtime-require
Flag Alias
--global-export -g
--no-runtime-require -q

Proposal

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,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.