This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test1 { | |
(*, false, true ) => 1, | |
(false, true, * ) => 2, | |
(*, *, false) => 3, | |
(*, *, true ) => 4 | |
} | |
function test2 { | |
(1, { a: 1, b: 2 }) => 1, | |
(*, { a: 1, b: 2 }) => 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function balance { | |
Black(Red(Red(a, x, b), y, c), z, d) => Red(Black(a, x, b), y, Black(c, z, d)), | |
Black(Red(a, x, Red(b, y, c)), z, d) => Red(Black(a, x, b), y, Black(c, z, d)), | |
Black(a, x, Red(Red(b, y, c), z, d)) => Red(Black(a, x, b), y, Black(c, z, d)), | |
Black(a, x, Red(b, y, Red(c, z, d))) => Red(Black(a, x, b), y, Black(c, z, d)), | |
t => t | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function balance { | |
['black', ['red', ['red', *, *, *], *, *], *, *] => 'balance-1', | |
['black', ['red', *, *, ['red', *, *, *]], *, *] => 'balance-2', | |
['black', *, *, ['red', ['red', *, *, *], *, *]] => 'balance-3', | |
['black', *, *, ['red', *, *, ['red', *, *, *]]] => 'balance-4', | |
* => 'balanced' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test1 { | |
Black(Red(Red(*, *, *), *, *), *, *) => 'balance-1', | |
Black(Red(*, *, Red(*, *, *)), *, *) => 'balance-2', | |
Black(*, *, Red(Red(*, *, *), *, *)) => 'balance-3', | |
Black(*, *, Red(*, *, Red(*, *, *))) => 'balance-4', | |
default => 'balanced' | |
} | |
function test2(tree) { | |
var res; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro to_str { | |
case { _ ($toks ...) } => { | |
return [makeValue(#{ $toks ... }.map(unwrapSyntax).join(''), #{ here })]; | |
} | |
} | |
to_str(1 2 3 4) | |
// '1234' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro protocol { | |
case { _ $name:ident { $fn:protocol_fn ... } } => { | |
// Probably not a good idea to rely on `__fresh`. Sweet.js should provide | |
// some sort of blessed gensym capability. | |
letstx $id = [makeValue(__fresh(), #{ here })]; | |
return #{ | |
function $name(proto, impl) { | |
if (!impl) { | |
impl = proto; | |
proto = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Control.Global (importLib) where | |
foreign import importLib | |
"function importLib(node) {\ | |
\ return function(global) {\ | |
\ if (typeof require !== 'undefined' && typeof process !== 'undefined') {\ | |
\ return require(node);\ | |
\ } else {\ | |
\ return window[global];\ | |
\ }\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#usage: ./require.sh <root_dir> <main_file> [<output_file>] | |
cd $1 | |
ftype=`echo $2 | awk -F . '{print $NF}'` | |
files="" | |
function parsedeps { | |
files="$1 $files" | |
deps=`egrep '^(#|//|/\*)= require .*$' $1 | awk "{print \\$3 \".$ftype\"}" | tail -r` | |
for dep in $deps; do parsedeps $dep; done | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{data, any, only} = require 'adt' | |
# List definition using `any`. While we can restrict the tail to be a only List types, | |
# we can't restrict the head to be a specific type. | |
List = data -> | |
Nil: null | |
Cons: | |
head: any | |
tail: only this | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro $testadd { | |
case { $$mac $expr } => { | |
var ident = makeIdent('test', #{ $$mac }); | |
return withSyntax ($ident = [ident]) { | |
return #{ | |
return $expr + $ident; | |
} | |
} | |
} | |
} |
OlderNewer