npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redshiftlang

v0.5.2

Published

[![CircleCI](https://circleci.com/gh/kkalamarski/redshift/tree/master.svg?style=svg)](https://circleci.com/gh/kkalamarski/redshift/tree/master) Redshift is a functional programming language compiled to Javascript. It implements syntax similiar to Elixir.

Downloads

7

Readme

Redshift - functional programming language

CircleCI Redshift is a functional programming language compiled to Javascript. It implements syntax similiar to Elixir. It is created as a part of learning how do compilers work, and it's mostly just proof of concept.

Key concepts

  • no mutations
  • no classes, no this
  • all functions must return

Getting Started

Installation

Install compiler via npm:

npm install -g redshiftlang

Generating project files

Redshift provides CLI that helps with scaffolding code.

redshift create <project_name>
cd <project_name>

Once generated you can yse npm scripts to run your application.

One time build

redshift build <path_to_file>.rh

Watching for changes

redshift watch <path_to_file>.rh

Both options accept optional output argument (it defaults to ./bin/bundle.js):

redshift build path/to/file.red -o dist/directory/build.js

Syntax

Function declaration

Functions are defined by use of def/do/end keywords. The last expression will be returned.

def sum(a, b) do
  a + b
end

Redshift takes note of the arity of the function (number of arguments), so it is possible to declare functions with same name, but different arity. For example following code is valid

def sum(a) do
  a + a
end

def sum(a, b) do
  a + b
end

Pattern matching

Redshift lets you use pattern matching in function declarations.

def error("syntax") do
  IO.puts("You used wrong syntax!")
end

def error("type") do
  IO.puts("Trying to assign different type")
end

def error("range") do
  IO.puts("Given value is out of range")
end

def error(type) do
  IO.puts(type <> " error occured!")
end

error("syntax") # You used wrong syntax!
error("Unknown") # Unknown error occured!

Function expressions

Redshift lets you define function expressions by using fn/->/end syntax.

double = fn(a) -> a * 2 end

Function expressions do not support pattern matching. To pass them as an argument to another function, they must be first stored in a variable. This is by design and improves code readability.

say_hello = fn(name) -> "Hello " <> name end

List.map(names, say_hello)

Constants

Because of lack of mutations, redshift supports constants only. Constants are block scoped.

test_constant = 2
result = 2 * 3

Constants can also be used inside functions

def func() do
  a = 40
  b = 100

  a + b
end

Imports

There are three types of imports.

System Imports

Load built-in libraries like Math or IO

import Math
import IO

Node Modules Imports

Load javascript module from node_modules directory

import "lodash" as _
import "ramda" as R

Internal file imports

Load modules from another files (either .rh or .js) File extension is required.

import "./lib/Auth.rh" as Auth
import "./js/User.js" as User

String literals

String literals are declared using double quotes ".

hello_world = "Hello world!"

To concat two strings use concatenation operator <>.

str1 = "Hello "
str2 = "world!"

result = str1 <> str2

List Literals

Lists are declared using square parentheses [].

names = ["tom", "mark", "andrew"]

To concat two lists use concatenation operator ++.

names = ["tom", "mark", "adam"]
other_names = ["anna", "kasia", "ewelina"]

all = names ++ other_names

To perform more advanced operations like mapping, reducing, filtering and searching use List module

import List

numbers = [1, 2, 3]
double = fn(num) -> num * 2 end

doubled = List.map(numbers, double)

## Head | Tail
head = List.head(numbers) # 1
tail = List.tail(numbers) # [2, 3]

Modules

Module is a namespace for the functions serving similiar purpose. Examples of built-in modules are:

Math - contianing functions for arythmetic operations

IO - containig functions for managind input and output

To decalre custom module defmodule / end notation is used.

defmodule User do

  def get_user() do
    # some logic
  end

  def delete_user() do
    # some logic
  end
end

Module is always 'default' exported. That is why it is only possible to have one module per file.