Git Product home page Git Product logo

candy's Introduction

šŸ­ Candy

šŸš§ Work in Progress!

Candy is still in its early stages. We are actively working on it, but it's not ready for production use yet. If you want to help, please join our Discord server. See also: The current state.

A sweet, functional programming language that is robust, minimalistic, and expressive.

Many programming languages have a strict separation between compile-time and runtime errors. Sometimes, this border can seem arbitrary: Dividing by a string fails during compilation with a type error, while dividing by zero only fails during runtime. In the mathematical sense, there's no fundamental difference between these casesā€Æā€“ā€‰division is only defined for divisors that are non-zero numbers. That's why we eliminate the border between compile-time and runtime errorsā€Æā€“ā€‰all errors are runtime errors. By crafting high-quality tooling with dynamic analyses such as fuzzing, we try to still be able to show most errors while you're editing the code. In fact, we try to show more errors than typical statically typed languages.

Candy in VS Code

Quick introduction

  • Values are at the center of your computations. Only a handful of predefined types of values exist:

    3                   # int
    "Candy"             # text
    Green               # tag (uppercase)
    Error ListIsEmpty   # tag with a value
    (Foo, Bar)          # list
    [Name: "Candy"]     # struct
    { it -> add it 2 }  # function
    
  • Minimalistic syntax. Defining variables and functions works without braces or keywords cluttering up your code. The syntax is indentation-aware.

    # I'm a comment
    foo = 42                # variable (lowercase)
    println message =       # function
      print message         # function call
      print "\n"
    println "Hello, world!"
    
  • Extensive compile-time evaluation. Many values can already be computed at compile-time. In your editor, you'll see the results on the right side:

    foo = double 2  # foo = 4
    
  • Fuzzing instead of traditional types. In Candy, functions have to specify their needs exactly. As you type, the tooling automatically tests your code with many inputs to see if one breaks the code:

    foo a =             # If you pass a = 0,
      needs (isInt a)
      math.logarithm a  # then this panics: The `input` must be a positive number.
    
    efficientTextReverse text =
      needs (isText text)
      needs (isPalindrome text) "Only palindromes can be efficiently reversed."
      text
    
    greetBackwards name =                   # If you pass name = "Test",
      "Hello, {efficientTextReverse name}"  # then this panics: Only palindromes can be efficiently reversed.
    

For more info, read:

The current state

We are currently implementing a first version of Candy in Rust. We already have a CLI, language server, and Visual Studio Code extension that provide some tooling.

The language is still in its early stages, and we are actively working on it. There are still compiler bugs and performance improvements that need work before this language is ready for production use.

Discussion

Join our Discord server.

How to use Candy

  1. Install Ā Rust: rust-lang.org/tools/install (use Rustup since we use nightly features).
    • Alternatively, use the provided Ā Nix flake to install all required dependencies.
  2. Clone this repo.

Then, you can use Candy in two ways:

Use the VS Code Extension

  1. Install Ā Visual Studio Code (VS Code): code.visualstudio.com/download.
  2. Open the workspace (compiler.code-workspace) in VSĀ Code.
  3. Install the recommended VS Code extensions.
  4. Run npm install inside vscode_extension/.
  5. Run the launch config ā€œRun Extension (VSĀ Code Extension)ā€.
  6. In the new VSĀ Code window that opens, you can enjoy šŸ­Ā Candy :)

If you are working on the Rust code itself, you might want to disable release mode for quicker compilation: In packages/candy.code-workspace, in the candy.languageServerCommand setting, remove --release. (But don't commit that change.)

Use the CLI

From the root of this repository, you can run the Candy CLI by starting the Candy commands with cargo run --release --:

# Run a Candy file:
cargo run --release -- run ./packages/Examples/helloWorld.candy

# View all available commands:
cargo run --release -- help

(Everything after -- is passed to Candy, everything before it to Cargo.)

Environment Variables for Debugging the Compiler

# Don't normalize IDs (number them sequentially) after optimizing the MIR.
CANDY_MIR_NORMALIZE_IDS=false

# Generate a _large_ Markdown file that lists every single optimization step
# performed on the MIR.
CANDY_MIR_OPTIMIZATION_LOG=target/optimization-log.md

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.