All Projects → pen-lang → pen

pen-lang / pen

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
The parallel, concurrent, and functional programming language for scalable software development

Programming Languages

rust
11053 projects
Gherkin
971 projects

Projects that are alternatives of or similar to pen

Asyncninja
A complete set of primitives for concurrency and reactive programming on Swift
Stars: ✭ 146 (-62.94%)
Mutual labels:  functional, concurrency
Phobos
The standard library of the D programming language
Stars: ✭ 1,038 (+163.45%)
Mutual labels:  functional, concurrency
concurrent-ll
concurrent linked list implementation
Stars: ✭ 66 (-83.25%)
Mutual labels:  concurrency
hawkweed
Yet another implementation of missing functions for Python
Stars: ✭ 20 (-94.92%)
Mutual labels:  functional
archery
Abstract over the atomicity of reference-counting pointers in rust
Stars: ✭ 107 (-72.84%)
Mutual labels:  concurrency
when-switch
JavaScript functional implementation of switch/case
Stars: ✭ 20 (-94.92%)
Mutual labels:  functional
frontend-clean-architecture
React + TypeScript app built using the clean architecture principles in a more functional way · 🧼 🏛 🍪
Stars: ✭ 1,816 (+360.91%)
Mutual labels:  functional
pythonic
Python like utility functions for JavaScript: range, enumerate, zip and items.
Stars: ✭ 28 (-92.89%)
Mutual labels:  functional
fn
Functional library for PHP with proper currying
Stars: ✭ 22 (-94.42%)
Mutual labels:  functional
pocketlang
A lightweight, fast embeddable scripting language.
Stars: ✭ 1,412 (+258.38%)
Mutual labels:  functional
nested scheduler
Shard for creating separate groups of fibers in a hierarchical way and to collect results and errors in a structured way.
Stars: ✭ 20 (-94.92%)
Mutual labels:  concurrency
haskell-simple-concurrency
Small examples of concurrency in Haskell.
Stars: ✭ 75 (-80.96%)
Mutual labels:  concurrency
js-data-structures
🌿 Data structures for JavaScript
Stars: ✭ 56 (-85.79%)
Mutual labels:  functional
rockgo
A developing game server framework,based on Entity Component System(ECS).
Stars: ✭ 617 (+56.6%)
Mutual labels:  concurrency
swift-declarative-configuration
Declarative configuration for your objects
Stars: ✭ 46 (-88.32%)
Mutual labels:  functional
batching-toposort
Efficiently sort interdependent tasks into a sequence of concurrently-executable batches
Stars: ✭ 21 (-94.67%)
Mutual labels:  concurrency
dart-more
More Dart — Literally.
Stars: ✭ 81 (-79.44%)
Mutual labels:  functional
p-ratelimit
Promise-based utility to make sure you don’t call rate-limited APIs too quickly.
Stars: ✭ 49 (-87.56%)
Mutual labels:  concurrency
ObservableComputations
Cross-platform .NET library for computations whose arguments and results are objects that implement INotifyPropertyChanged and INotifyCollectionChanged (ObservableCollection) interfaces.
Stars: ✭ 94 (-76.14%)
Mutual labels:  functional
lunala
💎│ The official Lunala's source code! Yet a modern space exploration bot.
Stars: ✭ 24 (-93.91%)
Mutual labels:  functional

Pen programming language

GitHub Action License Twitter

Pen is the parallel, concurrent, and functional programming language focused on application programming following Go's philosophy. It aims for further simplicity, testability, and portability to empower team (v. individual) and/or long-term (v. short-term) productivity.

Its syntax, type system, effect system, and module system are fashioned to achieve those goals being simple and easy to grasp for both newcomers and experts. One of the biggest differences from the other functional languages is polymorphism without generics.

Pen provides the two built-in functions of go and race to represent many concurrent/parallel computation patterns. Thanks to its syntax, type system, and the state-of-the-art reference counting garbage collection, programs are always memory safe and data-race free.

System libraries and runtime in Pen are detachable from applications. Thanks to this, Pen can compile the same applications even for WebAssembly and WASI. Pen also provides Rust/C FFI to reuse existing libraries written in those languages.

import Core'Number
import Os'File

# The `\` prefix for λ denotes a function.
findAnswer = \(kind string) number {
  # Secret source...

  21
}

main = \(ctx context) none {
  # The `go` function runs a given function in parallel.
  # `x` is a future for the computed value.
  x = go(\() number { findAnswer("humanity") })
  y = findAnswer("dolphins")

  _ = File'Write(ctx, File'StdOut(), Number'String(x() + y))

  none
}

Install

Pen is available via Homebrew.

brew install pen-lang/pen/pen

For more information, see Install.

Examples

See the examples directory.

Documentation

Comparison with Go

Overview

Pen Go
Domain Application programming System programming
Paradigm Functional Imperative / object-oriented
Memory management Reference counting Concurrent mark-and-sweep
System library Your choice! Built-in
Values Immutable Mutable

Runtime

Pen Go
Context switch Continuations Platform dependent
Concurrent computation Built-in functions go expression
Synchronization Futures, lazy lists Channels, concurrent data structures
Data race prevention Built into GC Dynamic analysis
Resource management Built into GC defer statement
Error handling error type, ? operator error type, multi-value return
Exception None panic and recover functions

Types

Pen Go
Number number (IEEE 754) int, float64, ...
Sequence [number] (lazy list) []int (array or slice)
Map {string: number} map[string]int
Optional value none, union types null pointer (or zero value)
Function \(number, boolean) string func(int, bool) string
Union number | string Interface
Top type any any (interface{})
Interface Records Interface
Futures Functions (thunks) None
Concurrent queue [number], built-in functions chan int

The \ (lambda, λ) notation in function types and literals originates from other functional programming languages like Haskell.

Technical design

Polymorphism without generics

Pen explicitly omit generics (or specifically parametric polymorphism for user-defined functions and types) from its language features as well as the original Go. It is one of the biggest experiments in the language as most of existing functional languages have generics as their primary features.

Instead, we explore polymorphism with other language features, such as generic constructs (e.g. list comprehension and pattern matches,) subtyping, top types, reflection, code generation, and so on. A belief behind this decision is that Pen can achieve the same flexibility as other languages reducing complexity of the language itself. For the same reason, we don't adopt macros as we believe they are too powerful for humanity to handle.

Dynamic effect system

Pen does not adopt any formal effect system of algebraic effects or monads. Instead, Pen rather uses a simple rule to manage side effects: all effects are passed down from the main functions to child functions. So unless we pass those impure functions to other functions explicitly, they are always pure. As such, Pen is an impure functional programming language although all runtime values are immutable. However, it still provides many of the same benefits purely functional languages do, such as determinicity and testability.

The reason we do not adopt any formal and statically provable effect system is to keep the language and its type system simple and lean for the purpose of improving developer productivity and software development scalability; we want to make Pen accessible and easy to learn for both newbie and expert programmers.

Context switch

Like Go, every function in Pen is suspendable and can be called asynchronously. This is realized by intermediate representation compiled into Continuation Passing Style (CPS) which also enables proper tail calls. Thus, Pen implements context switch without any platform-dependent codes for slight sacrifice of performance while Go requires logic written in assembly languages.

Currently, Pen does not use delimited continuations for the following reasons.

  • Traditional continuations are sufficient for our use cases, such as asynchronous programming.
  • Delimited continuations require heap allocations although the second-class continuations do not.

Reference counting GC

Pen implements the Perceus reference counting as its GC. Thanks to the state-of-the-art ownership-based RC algorithm, programs written in Pen performs much less than traditional RC where every data transfer or mutation requires counting operations. In addition, the algorithm reduces heap allocations significantly for records behind unique references, which brings practical performance without introducing unsafe mutability.

See also How to Implement the Perceus Reference Counting Garbage Collection.

Inductive values

TBD

Stackful coroutines

TBD

Contributing

Pen is under heavy development. Feel free to post Issues and Discussions!

Workflows

Installing from source

See Install.

Building crates

tools/build.sh

Running unit tests

tools/unit_test.sh

Running integration tests

tools/build.sh
tools/integration_test.sh

Running benchmarks

Those benchmarks include ones written in both Pen and Rust.

tools/benchmark.sh

Linting crates

tools/lint.sh

Formatting crates

tools/format.sh

Directory structure

  • cmd: Commands
    • pen: pen command
  • lib: Libraries for compiler, formatter, documentation generator, etc.
    • app: Platform-agnostic application logic for pen command
    • infra: Platform-dependent logic for pen command
    • ast: Abstract Syntax Tree (AST) types
    • hir: High-level Intermediate Representation (HIR) types and semantics
    • mir: Mid-level Intermediate Representation (MIR)
    • ast-hir: AST to HIR compiler
    • hir-mir: HIR to MIR compiler
    • mir-fmm: MIR to F-- compiler
  • packages: Packages written in Pen
    • core: Package for platform-independent algorithms and data structures
    • os: Package for a common OS interface
  • tools: Developer and CI tools
  • doc: Documentation at pen-lang.org

License

Pen is dual-licensed under MIT and Apache 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].