Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp,comp.lang.scheme Subject: Re: Stack overflow problem Date: Mon, 2 Sep 2024 20:14:19 -0000 (UTC) Organization: A noiseless patient Spider Lines: 36 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Mon, 02 Sep 2024 22:14:19 +0200 (CEST) Injection-Info: dont-email.me; posting-host="a435632fcbba468531e98d5e4c12abf8"; logging-data="3139192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GJrc94T3RFIWpnpbxiQrt" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:GVkK8uslVgf3WJKv1g49ngKUhKQ= Bytes: 1776 > > (defun nums (n) (loop for i from 1 to n collect i)) > > > > (defmethod sum ((x null)) 0) > > (defmethod sum ((x list)) (+ (first x) (sum (rest x))) > > > > (sum (nums 100)) => Stack overflow. > > > > I was hoping someone could toss some insight my way as to why this is. > > The recursion is simply too deep. > > If you're blowing out at 100 deep, you are probably running > the code interpreted, which would add a bunch of additional > stack frames. If you compile the methods, you'll probably > get an order of magnitude farther. > > But you could just write instead: > > (reduce #'+ (nums 100)) > or > (loop for i from i to n summing i) > > and not have to worry about the stack. Gauche Scheme: (define-method object-apply ((lst )) (fold + 0 lst)) gosh> '(1 3 5 7 9) (1 3 5 7 9) gosh> ('(1 3 5 7 9)) 25 gosh> ((iota 333 1 2)) 110889