Convert Figma logo to code with AI

wren-lang logowren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.

6,868
552
6,868
240

Top Related Projects

Repository for the book "Crafting Interpreters"

63,003

The Python programming language

22,033

The Ruby Programming Language

8,391

A copy of the Lua development repository, as seen by the Lua team. Mirrored irregularly. Please DO NOT send pull requests or any other stuff. All communication should be through the Lua mailing list https://www.lua.org/lua-l.html

48,780

The Kotlin Programming Language.

123,517

The Go programming language

Quick Overview

Wren is a small, fast, class-based concurrent scripting language. It aims to be simple but expressive, combining the performance of a low-level language with the ease of use of a high-level scripting language. Wren is designed to be embedded in applications, providing a powerful and efficient scripting solution.

Pros

  • Fast execution speed due to its bytecode virtual machine
  • Simple and clean syntax, easy to learn and use
  • Supports classes and objects with a familiar object-oriented model
  • Lightweight and easily embeddable in host applications

Cons

  • Relatively small community compared to more established languages
  • Limited ecosystem and third-party libraries
  • Not as feature-rich as some larger, more mature languages
  • Documentation could be more comprehensive for advanced topics

Code Examples

  1. Hello World example:
System.print("Hello, World!")
  1. Defining a class and creating an instance:
class Person {
  construct new(name) {
    _name = name
  }

  name { _name }
  
  greet() {
    System.print("Hello, I'm %(name)!")
  }
}

var person = Person.new("Alice")
person.greet() // Outputs: Hello, I'm Alice!
  1. Using Wren's fiber (coroutine) system:
var fiber = Fiber.new {
  System.print("Started fiber")
  Fiber.yield("Hello from fiber")
  System.print("Resumed fiber")
}

System.print(fiber.call()) // Outputs: Started fiber \n Hello from fiber
fiber.call() // Outputs: Resumed fiber

Getting Started

To get started with Wren, follow these steps:

  1. Download the Wren source code from the GitHub repository.
  2. Build Wren using the provided build instructions for your platform.
  3. Create a new file with a .wren extension, e.g., example.wren.
  4. Write your Wren code in the file:
System.print("Hello from Wren!")

class Example {
  static sayHello(name) {
    System.print("Hello, %(name)!")
  }
}

Example.sayHello("World")
  1. Run the script using the Wren CLI:
wren example.wren

This will execute your Wren script and display the output.

Competitor Comparisons

Repository for the book "Crafting Interpreters"

Pros of Crafting Interpreters

  • Comprehensive educational resource for learning interpreter and compiler design
  • Implements multiple languages (Lox) in different programming languages (Java, C)
  • Detailed explanations and step-by-step implementation guide

Cons of Crafting Interpreters

  • Not intended for production use, primarily an educational project
  • Lacks advanced language features and optimizations found in Wren
  • Slower execution compared to Wren's optimized implementation

Code Comparison

Wren (class definition):

class Bird {
  fly() {
    System.print("The bird is flying!")
  }
}

Crafting Interpreters (Lox class definition):

class Bird {
  fly() {
    print "The bird is flying!";
  }
}

Summary

Crafting Interpreters is an excellent resource for learning about language implementation, offering detailed explanations and multiple implementations. However, it's primarily educational and lacks the performance optimizations and production-ready features found in Wren. Wren, on the other hand, is designed for practical use with a focus on efficiency and a more extensive feature set. The code comparison shows similarities in syntax between Wren and Lox (the language implemented in Crafting Interpreters), but Wren's implementation is more optimized for real-world applications.

63,003

The Python programming language

Pros of CPython

  • Extensive standard library and vast ecosystem of third-party packages
  • Widely adopted in various domains, including web development, data science, and AI
  • Comprehensive documentation and large community support

Cons of CPython

  • Slower execution speed compared to Wren's lightweight VM
  • Larger memory footprint and longer startup time
  • More complex codebase, making it harder to understand and contribute to

Code Comparison

Wren

class Greeter {
  construct new(name) {
    _name = name
  }
  
  greet() {
    System.print("Hello, %(_name)!")
  }
}

var greeter = Greeter.new("World")
greeter.greet()

CPython

class Greeter:
    def __init__(self, name):
        self._name = name
    
    def greet(self):
        print(f"Hello, {self._name}!")

greeter = Greeter("World")
greeter.greet()

Both examples demonstrate similar object-oriented concepts, but Wren's syntax is more concise and uses System.print instead of Python's built-in print function. CPython offers more flexibility in string formatting with f-strings, while Wren uses string interpolation with parentheses.

22,033

The Ruby Programming Language

Pros of Ruby

  • Extensive standard library and ecosystem with a vast collection of gems
  • Mature language with robust documentation and community support
  • Flexible syntax and powerful metaprogramming capabilities

Cons of Ruby

  • Slower execution speed compared to Wren's lightweight VM
  • Higher memory usage and longer startup times
  • More complex language with a steeper learning curve

Code Comparison

Ruby:

class Greeter
  def initialize(name)
    @name = name
  end

  def greet
    puts "Hello, #{@name}!"
  end
end

Greeter.new("World").greet

Wren:

class Greeter {
  construct new(name) {
    _name = name
  }

  greet() {
    System.print("Hello, %(_name)!")
  }
}

Greeter.new("World").greet()

Both languages showcase object-oriented programming with similar syntax for class definition and method calls. Ruby's syntax is slightly more concise, while Wren's is more explicit in some areas, such as the construct new for the constructor. Ruby uses string interpolation with #{}, whereas Wren uses %(). The overall structure and readability are comparable, demonstrating the influence of Ruby on Wren's design.

8,391

A copy of the Lua development repository, as seen by the Lua team. Mirrored irregularly. Please DO NOT send pull requests or any other stuff. All communication should be through the Lua mailing list https://www.lua.org/lua-l.html

Pros of Lua

  • Widely adopted and battle-tested in various industries
  • Extensive ecosystem with numerous libraries and frameworks
  • Efficient integration with C/C++ through its C API

Cons of Lua

  • Lacks built-in object-oriented programming features
  • 1-based indexing can be confusing for developers from other languages
  • Limited standard library compared to more modern languages

Code Comparison

Lua:

function factorial(n)
    if n == 0 then return 1 end
    return n * factorial(n - 1)
end
print(factorial(5))

Wren:

class Math {
  static factorial(n) {
    if (n == 0) return 1
    return n * factorial(n - 1)
  }
}
System.print(Math.factorial(5))

Key Differences

  • Wren has built-in class-based object-oriented programming
  • Lua uses tables for data structures, while Wren has more traditional classes and objects
  • Wren's syntax is more similar to modern languages like JavaScript or Ruby
  • Lua has a larger community and more extensive third-party libraries
  • Wren aims for simplicity and a smaller language core, while Lua offers more flexibility

Both languages are designed to be embedded in host applications, but Lua has a longer history and wider adoption in this area. Wren, being newer, incorporates more modern language features and aims for a cleaner syntax.

48,780

The Kotlin Programming Language.

Pros of Kotlin

  • Extensive ecosystem and industry adoption, especially for Android development
  • Robust tooling support, including IntelliJ IDEA integration
  • Interoperability with Java, allowing seamless use of existing Java libraries

Cons of Kotlin

  • Larger language complexity compared to Wren's simplicity
  • Slower compilation times, especially for large projects
  • Steeper learning curve for beginners due to more advanced features

Code Comparison

Wren:

class Greeter {
  construct new(name) {
    _name = name
  }
  
  sayHello() {
    System.print("Hello, " + _name + "!")
  }
}

Kotlin:

class Greeter(private val name: String) {
    fun sayHello() {
        println("Hello, $name!")
    }
}

Summary

Wren is a lightweight, simple language focused on embedding in applications, while Kotlin is a more comprehensive, industry-standard language with extensive tooling and ecosystem support. Wren's simplicity may appeal to those seeking a minimalist approach, whereas Kotlin's robustness and interoperability make it suitable for large-scale projects and Android development.

123,517

The Go programming language

Pros of Go

  • Larger ecosystem and community support
  • Better performance and scalability for large applications
  • Extensive standard library and built-in concurrency features

Cons of Go

  • More verbose syntax compared to Wren's concise style
  • Steeper learning curve for beginners
  • Longer compilation times, especially for large projects

Code Comparison

Wren:

class Greeter {
  construct new(name) {
    _name = name
  }
  
  sayHello() {
    System.print("Hello, %(_name)!")
  }
}

var greeter = Greeter.new("World")
greeter.sayHello()

Go:

package main

import "fmt"

type Greeter struct {
    name string
}

func (g Greeter) sayHello() {
    fmt.Printf("Hello, %s!\n", g.name)
}

func main() {
    greeter := Greeter{name: "World"}
    greeter.sayHello()
}

The Wren code is more concise and uses a class-based approach, while Go uses a struct with a method. Go's syntax is more explicit, requiring type declarations and a separate main function.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Wren is a small, fast, class-based concurrent scripting language

Think Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a familiar, modern syntax.

System.print("Hello, world!")

class Wren {
  flyTo(city) {
    System.print("Flying to %(city)")
  }
}

var adjectives = Fiber.new {
  ["small", "clean", "fast"].each {|word| Fiber.yield(word) }
}

while (!adjectives.isDone) System.print(adjectives.call())
  • Wren is small. The VM implementation is under 4,000 semicolons. You can skim the whole thing in an afternoon. It's small, but not dense. It is readable and lovingly-commented.

  • Wren is fast. A fast single-pass compiler to tight bytecode, and a compact object representation help Wren compete with other dynamic languages.

  • Wren is class-based. There are lots of scripting languages out there, but many have unusual or non-existent object models. Wren places classes front and center.

  • Wren is concurrent. Lightweight fibers are core to the execution model and let you organize your program into an army of communicating coroutines.

  • Wren is a scripting language. Wren is intended for embedding in applications. It has no dependencies, a small standard library, and an easy-to-use C API. It compiles cleanly as C99, C++98 or anything later.

If you like the sound of this, let's get started. You can even try it in your browser! Excited? Well, come on and get involved!

Build Status