I get an ERROR on line 11 of file project_euler.scm: empty application in source: () whenever I run this code below using chibi-scheme v 0.5.3 but it just runs fine when I use Dr Racket. Has anyone got any idea why this is happening?
#! /usr/bin/env chibi-scheme
(define (sum-of-amicable-pairs n)
(let ((sums (list->vector (map (lambda (i)
(reduce + 0
(filter (lambda (j) (= (remainder i j) 0))
(iota (+ 1 (quotient i 2)) 1 1))))
(iota n 0 1)))))
(let loop ((len (vector-length sums))
(res-list '())
(i 0))
(cond
((= i len) (reduce + 0 res-list))
((and (< (vector-ref sums i) n)
(or (> (vector-ref sums i) i) (< (vector-ref sums i) i))
(= (vector-ref sums (vector-ref sums i)) i))
(loop len (cons (+ (vector-ref sums i) (vector-ref sums (vector-ref sums i))) res-list)
(+ i 1)))
(else
(loop len res-list (+ i 1)))))))
(sum-of-amicable-pairs 10000)
Okay, I think I know what’s going on here. When you load up the chibi-scheme REPL, it’s using R7RS Scheme, but when you load a file, it’s using the most basic version of Scheme that Chibi supports. See: http://synthcode.com/scheme/chibi/#h3_SchemeStandard
If you put
(import (scheme base))at the top of your file then you no longer get the error about the empty application. Also you should do(import (srfi 1))in order to get the list processing procedures you use. See: http://synthcode.com/scheme/chibi/#h2_StandardModules