idk pasted by phasers-to-stun on Sun Jan 31 05:08:38 2016

(use srfi-13)
(use srfi-1)

(define (range str stp inc)
  (cond ((< str stp) (cons str (range (+ str 1) stp inc)))
	(else '())))

(define ($ . its)
  (lambda (p)
    (eval `(cond
	    ,@(map (lambda (q r)
		     `((eq? ',p ',q) ,r))
		   (range 0 (length its) 1)
		   its)
	    ((eq? ',p 'ln) ,(length its))
	    ((eq? ',p 'v?) #t)))))

(define (.. v1 v2)
  (cond ((eq? (v1 'ln) (v2 'ln))
	 (let ((l (v1 'ln)))
	   (fold + 0
		 (map (lambda (n)
			(* (v1 n) (v2 n)))
		      (range 0 l 1)))))
	(else (error "vectors must be of the same size"))))

(define (... v1 v2)
  (cond ((and (eq? (v1 'ln) 3) (eq? (v2 'ln) 3))
	 ($ (- (* (v1 1) (v2 2))
	       (* (v1 2) (v2 1)))
	    (- (* (v1 2) (v2 0))
	       (* (v1 0) (v2 2)))
	    (- (* (v1 0) (v2 1))
	       (* (v1 1) (v2 0)))))
	(else (error "vectors must both be of length 3"))))

(define (! v)
  (let loop ((i 0))
    (if (< i (v 'ln))
	(cons (v i)
	      (loop (+ i 1)))
	'())))

(define (vec? it)
  (cond ((list? it) #f)
	((number? it) #f)
	((pair? it) #f)
	((symbol? it) #f)
	((it 'v?) #t)
	(else #f)))

(define d ($ ($ 1 0 0)
	     ($ 0 1 0)
	     ($ 0 0 1)))

(define v ($ 1 2 3))

(display (v 1))
(newline)

;this is the offending line
(display ((d 1) 1))

vectors for real... added by elf on Sun Jan 31 05:14:32 2016

; so you know that vectors do exist as scheme types, right?

(use srfi-1)

; uninitialised x by y matrix
(define (make-matrix x y)
    (let ((v (make-vector y)))
        (for-each
            (lambda (z)
                (vector-set! v z (make-vector x)))
            (iota y))
        v))

; reference a matrix element
(define (matrix-ref m x y)
    (vector-ref (vector-ref m y) x))

; set a matrix element
(define (matrix-set! m x y e)
    (vector-set! (vector-ref m y) x e))