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
// main.swift | |
// Testing | |
import Foundation | |
import Cocoa | |
import Carbon | |
import AppKit | |
println("Hello, World!") |
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
require('source-map-support').install() | |
function displayln(x) { | |
console.log(x); | |
} | |
/*** CONTROL CONSTRUCTS ***/ | |
/* when expr body | |
Racket when */ |
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 even { | |
function (stx) { /* stx is an array of syntax objects */ | |
console.log(stx); | |
var name_stx = stx[0]; | |
var arg = stx[1]; | |
var val = arg.token.value; | |
var res = ( ((val%2)==0) ? [makeValue(true,name_stx)] : false ); | |
if (res) return { result: [stx[1]], | |
rest: stx.slice(2) } | |
else return false }} |
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 compiletimeutils { | |
case { $ctu ()} | |
=> { letstx $is_stx = [makeIdent("is_stx", #{$ctu})]; | |
return #{function $is_stx(s) { | |
return ((typeof s)=="object") && | |
!(s[0] == undefined) && | |
((typeof(s[0]["token"]))=="object") } ;} } | |
} | |
macro m { |
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
/*** CONTROL CONSTUCTS ***/ | |
/* rif expr expr1 expr2 | |
equivalent to (expr ? expr1 : expr2) | |
Note: The Javascript if is a "statement-if", so this is the "expression-if" */ | |
macro rif { | |
case {_ ($e:expr, $e1:expr, $e2:expr)} | |
=> {return #{(($e) ? ($e1) : ($e2))}}} |
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
(define (cross a b) | |
(match-define (vector a1 a2 a3) (matrix->vector a)) | |
(match-define (vector b1 b2 b3) (matrix->vector b)) | |
(matrix [[(- (* a2 b3) (* a3 b2))] | |
[(- (* a3 b1) (* a1 b3))] | |
[(- (* a1 b2) (* a2 b1))]])) |
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
(define (cross-product a b) | |
(for/matrix 3 1 ([n 3]) | |
(define (ref c i) (matrix-ref c (modulo (+ n i) 3) 0)) | |
(- (* (ref a 1) (ref b 2)) (* (ref a 2) (ref b 1))))) | |
(cross-product (col-matrix [1 0 0]) | |
(col-matrix [0 1 0])) |
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
#lang racket | |
(require math | |
(prefix-in racket: racket)) | |
(define (+ . xs) | |
(cond | |
[(andmap number? xs) (apply racket:+ xs)] | |
[else (apply matrix+ xs)])) | |
(+ (matrix [[1 2] [3 4]]) |
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
#lang racket | |
(require math) | |
(define old-printer (array-custom-printer)) | |
(define (matrix-printer A name port mode) | |
(cond | |
[(not (matrix? A)) (old-printer A name port mode)] | |
[else (for ([r (matrix-rows A)]) |
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
#lang racket | |
(require syntax/parse) | |
(define-syntax-class term | |
(pattern ((~literal t) t))) | |
(define-syntax-class operator | |
(pattern ((~literal o) op))) | |
(define-splicing-syntax-class term-op |