Skip to content

Instantly share code, notes, and snippets.

let function = macro {
case { _ * $id ($args ...) { $body ... } } => {
var body = #{ $body ... };
var isAwaitGenerator = false;
for (var i = 0; i < body.length; i++) {
if (body[i].token.type === parser.Token.Identifier &&
body[i].token.value === 'await') {
var expr = getExpr(body.slice(i));
if (expr.success) {
isAwaitGenerator = true;
letstx $name ... = [name1, name2, name3];
letstx $type ... ... = [[type1, type2], [type3, type4]]
@disnet
disnet / gist:44f8572b863ed398a69a
Created June 12, 2014 04:10
adjust lineNumber
macro m {
rule {} => {
(function() {
return
{
foo: "bar"
}
})
}
}
@disnet
disnet / import.js
Last active August 29, 2015 14:07
import macros
// test.js
#lang "./macros/stxcase.js";
import { m } from "./mod.js";
m(10, 100)
// mod.js
#lang "./macros/stxcase.js";
### Keybase proof
I hereby claim:
* I am disnet on github.
* I am disnet (https://keybase.io/disnet) on keybase.
* I have a public key whose fingerprint is 1CCB B2BE 266F 8706 733F C4A7 07DF 8A2D E8B1 D193
To claim this, I am signing this object:
@disnet
disnet / stxparm.md
Last active August 29, 2015 14:08
thoughts about syntax parameter

Syntax parameters allow us to play around with hygiene in a principled fashion.

stxParam it = function() { throw new Error("must be rebound"); };

let aif = macro {
    rule { ($cond ...) { $body ...} } => {
	var it_inner  = $cond ...;
	if (it_inner) {
macro m {
rule { $x } => { var $x; }
}
m x
let function = macro {
rule { $name (callback $arg $rest ...) { $body ... } } => {
function $name ($arg $rest ...) {
$body ...
}
}
}
function foo(callback cb, x, y, z) {
cb(x + y + z);
@disnet
disnet / getlocation.js
Created March 21, 2016 21:14
handle url parsing in IE
// the web is crazy
// http://stackoverflow.com/questions/736513/how-do-i-parse-a-url-into-hostname-and-path-in-javascript
function getLocation(href) {
var location = document.createElement("a");
location.href = href;
// IE doesn't populate all link properties when setting .href with a relative URL,
// however .href will return an absolute URL which then can be used on itself
// to populate these additional fields.
if (location.host == "") {
location.href = location.href;
operator >>= left 1 = (left, right) => {
return #`${left}.then(${right})`;
}
fetch('/foo.json') >>= resp => { return resp.json() }
>>= json => { return processJson(json) }