Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Mock wavebeem

View GitHub Profile
View current.sqg.rb
### Imports
let {JSON, document, console} = global
### Basic data
let namedConstants = [true, false, null, undefined]
let numbers = [1, 2, 1_000, 3.14, NaN, -Infinity]
let strings = ["hello,\n", "\u{20}", "\"world\"\u{2757}"]
let arrays = [[], [1, 2], [3, [[4]], [5]]]
@wavebeem
wavebeem / current.sqg.rb
Last active Dec 2, 2015
This Gist shows the current syntax of the Squiggle programming language, along with other ideas about how the syntax could look.
View current.sqg.rb
### Imports
let {JSON, document, console} = global
### Basic data
let namedConstants = [true, false, null, undefined]
let numbers = [1, 2, 1_000, 3.14, NaN, -Infinity]
let strings = ["hello,\n", "\u{20}", "\"world\"\u{2757}"]
let arrays = [[], [1, 2], [3, [[4]], [5]]]
View foo-shorter.js
render([
[{path: "/", component: App},
[{path: "about", component: About}],
[{path: "users", component: Users},
[{path: "/user/:userId", component: User}]
],
[{path: "*", component: NoMatch}]
]
], document.body);
@wavebeem
wavebeem / foo.js
Created Nov 13, 2015
ES6 modules export bindings, not values.
View foo.js
export let x = 1;
export function inc() {
x++;
};
View redcarpet_codemirror.rb
require 'cgi'
require 'jekyll'
require 'redcarpet'
class RedcarpetCodeMirror < Redcarpet::Render::HTML
def initialize
super
@total = 0
end
View foo.scala
# Good use of match
def compile(node) =
match node
case {type: "Add", a, b} =>
["+", compile(a), compile(b)]
case {type: "If", condition, result, alternative} =>
["if", compile(condition), compile(result), compile(alternative)]
# Bad use of match
def greet(person) =
View main1.squiggle
def start() =
let body = document.body
let root = React.createElement(GameView)
let container = document.getElementById("react-container")
let thing = React.render(root, container)
in do
set(app, "root", thing);
body.addEventListener("click", focusClickhole);
tick();
end
@wavebeem
wavebeem / parsefun.js
Created Oct 6, 2015
This does not actually generate the correct AST because I was using arrays and dang does that get confusing over time, but this helped me figure out how to parse my binary operators correctly while also including unary operators at the right precedence level and make foo.bar foo[bar] and foo(bar) all chain together correctly.
View parsefun.js
"use strict";
const util = require("util");
const P = require("parsimmon");
console.log(Date() + "\n");
const _ = P.optWhitespace;
const tag = name => rest =>
View blap.js
// squiggle> :set f = fn(n) match (n) { case 0 => 1 case x => x * f(x - 1) }
(function () {
'use strict';
return (false || eval)('this')['f'] = sqgl$$freeze(function (n) {
if (arguments.length !== 1) {
throw new sqgl$$Error('expected 1 argument(s), got ' + arguments.length);
}
return function ($match) {
if (sqgl$$is($match, 0)) {
return function () {
@wavebeem
wavebeem / boring.js
Last active Aug 29, 2015
a boring browser global module
View boring.js
(function(global) {
var foo = global.foo;
function bar1() { return 1; }
function bar2() { return 2; }
function bar3() { return 3; }
var api = {
bar1: bar1,
bar2: bar2,
bar3: bar3
};