since I'm a newbie to Common Lisp I tried to solve problems on SPOJ by using Common Lisp (SBCL). The first problem is a simple task of reading numbers until number 42 is found. Here's my solution:
(defun study-num () (let ((num (parse-integer (read-line t)))) (when (not (= num 42)) (format t "~A~%" num) (study-num)))) (study-num) The solution is accepted. But when I looked into the details of the result I found it used 57M of MEM! It's bloody unreasonable but I can't figure out why. What can I do to make an optimization?
timeto measure(study-num)with three guesses I get 100k consed - I guess I could get a much lower number with optimizations). Running(room)on a fresh instance of SBCL on x64 shows that it uses about 100M of RAM (about half the amount is used on x86).(format t "test")program would cost that much since I tested with it yesterday.toporpsin the shell?(room)or(time ...)in the Lisp REPL? My hypothesis is that you usedpsor something similar in the shell, and you basically saw the minimal memory usage of SBCL - which isn't that great, if you compare it to a loaded JVM (or .NET VM).topor(room)or anything else on my computer, but given by SPOJ.(time)(consed bytes are a bit different from 'max memory used at one point', as you could have 2MB consed, but a GC after the first MB, thus the second MB uses the space of the first, so just 1MB of memory actually used).