This file contains hidden or 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
(define-syntax for | |
(syntax-rules (as in) ;; this makes 'as' and 'is' literals (keywords), rather than things to be captured | |
((for each in list body ...) ;; 'for' and 'in' as literals; 'each', 'list' and 'body ...' are 'variables' to fill | |
(for-each | |
(lambda (each) body ...) | |
list)) | |
((for list as each body ...) ;; 'for' and 'as' as literals; 'each', 'list' and 'body ...' are 'variables' to fill | |
(for each in list body ...)))) ;; this macro is a 'wrapper' around the previous | |
(for i in '(1 2 3 4) |
This file contains hidden or 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
(define-syntax with | |
(syntax-rules () | |
((with func body ...) | |
(begin | |
(func 'start) | |
body ... | |
(func 'end))))) | |
(define-syntax println ;; this could easily be a function | |
(syntax-rules () |
This file contains hidden or 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
(define (sum . args) | |
(apply + args)) | |
(define-syntax start | |
(syntax-rules (end) | |
((start body ... end) | |
(sum body ...)))) | |
(display (start 10 20 30 end)) |
This file contains hidden or 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
#define _XOPEN_SOURCE 500 /* Enable certain library functions (strdup) on linux. See feature_test_macros(7) */ | |
#include <time.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <limits.h> | |
#include <string.h> | |
#include <assert.h> | |
struct avl_node_s { |
This file contains hidden or 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
(define-syntax <> | |
(syntax-rules () | |
((_ v e ...) | |
(if (null? (command-line-arguments)) | |
(let loop ((v (read-line))) | |
(unless (eof-object? v) | |
e ... | |
(loop (read-line)))) | |
(let file-loop ((port (open-input-file (car (command-line-arguments)))) | |
(rest (cdr (command-line-arguments)))) |
This file contains hidden or 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
def my_hc(c): | |
return ord(c) - ord('a') + 1 | |
def my_hs(s, a): | |
hash = 0 | |
for i in range(len(s)): | |
hash += (a**i) * my_hc(s[i]) | |
return hash | |
This file contains hidden or 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
// you can also find an example running at http://ideone.com/zeudW8 | |
//In one line, what is obtained when the result of passing 9 into | |
//the fourth function of the puzzlers array is then | |
//passed into the function whose array index matches | |
//the result of passing 3 into the second function of | |
//the puzzlers array? | |
var puzzlers = [ |
This file contains hidden or 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
type Foo | |
a::Int | |
b::String | |
end | |
fn plus(this::Foo, other::Foo) -> Foo | |
return Foo(this + other.a, this + other.b) | |
end | |
fn plus(this::Foo, i::Int) -> Int |
This file contains hidden or 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
type Map<K, V> | |
... | |
end | |
slice<K, V>(m::Map<K,V>, k::K) -> V | |
... | |
end | |
slice<K, V>(&m::Map<K,V>, k::K) -> &V |
This file contains hidden or 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
in icarus we want to allow a function to be named the same as an operator | |
fn and(a::Bool, b::Bool) -> Bool ... end | |
a and b | |
and(a, b) | |
this can make parsing interesting | |
a and(b or c) |
OlderNewer