-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
74 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function pair(x, xs) { | ||
return [x, xs]; | ||
} | ||
|
||
export function array_test(x) { | ||
if (typeof Array.isArray !== 'undefined') { | ||
return Array.isArray(x); | ||
} else { | ||
return x instanceof Array; | ||
} | ||
} | ||
|
||
export function is_pair(x) { | ||
return array_test(x) && x.length === 2; | ||
} | ||
|
||
export function head(xs) { | ||
if (is_pair(xs)) { | ||
return xs[0]; | ||
} else { | ||
throw new Error('head(xs) expects a pair as argument xs, but encountered ' + xs); | ||
} | ||
} | ||
|
||
export function tail(xs) { | ||
if (is_pair(xs)) { | ||
return xs[1]; | ||
} else { | ||
throw new Error('tail(xs) expects a pair as argument xs, but encountered ' + xs); | ||
} | ||
} | ||
|
||
export function error(value, ...strs) { | ||
const output = strs.length === 0 ? value : value + ' ' + strs.join(' '); | ||
throw new Error(output); | ||
} |
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