From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: jerry Newsgroups: gmane.lisp.guile.user Subject: guile style Date: Fri, 18 Jun 2021 20:55:34 -0400 Message-ID: <7aeef132-6bd7-c178-5786-c0a3d6b3edc8@nycap.rr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13861"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 To: guile-devel-confirm+bec536c361a61d32a192d9a45ad6dea4f892df58@gnu.org, guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jun 19 02:55:59 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1luPHD-0003WV-6d for guile-user@m.gmane-mx.org; Sat, 19 Jun 2021 02:55:59 +0200 Original-Received: from localhost ([::1]:40762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luPHC-0001XT-9A for guile-user@m.gmane-mx.org; Fri, 18 Jun 2021 20:55:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luPH2-0001XE-0H; Fri, 18 Jun 2021 20:55:48 -0400 Original-Received: from impout007aa.msg.chrl.nc.charter.net ([47.43.20.31]:35739 helo=impout007.msg.chrl.nc.charter.net) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luPGz-0007zc-0u; Fri, 18 Jun 2021 20:55:47 -0400 Original-Received: from [192.168.1.8] ([67.241.26.17]) by cmsmtp with ESMTPA id uPGolXuk45d1DuPGxlsVjP; Sat, 19 Jun 2021 00:55:43 +0000 Authentication-Results: nycap.rr.com; none X-Authority-Analysis: v=2.4 cv=eP7WMFl1 c=1 sm=1 tr=0 ts=60cd408f a=6kFUCgT7isY2CrseCyFLdg==:117 a=6kFUCgT7isY2CrseCyFLdg==:17 a=IkcTkHD0fZMA:10 a=-KobnvN9oEwm7B4garUA:9 a=QEXdDO2ut3YA:10 Content-Language: en-US X-CMAE-Envelope: MS4xfCW6xhZZMBxe5oTvlBLc4efr5MyAN3YebMfdYmY5VneSWJlP7mbXmvqavhsQZRUIfjwf2F/EBT/2bff3xRw5GXOBpADVCNge7qoPMV107lB21xyECSL9 mEjJ6vMP9EVi5C1JMJ3mSEUF2U+uO9tRDCSd0aCVPPfsE9hFcP667DYFnTqX2fg6540Yn7acyfa8CacpulUPE7tZfvq4a+8cZWwKmZ/DdyvlDzTHYsUZ+NO/ qlSBbSpx3ak7mESsdxiSiNGhC/sPsrxp1FRT5brumsNATaphBnuTEsNgEZFT5ape Received-SPF: softfail client-ip=47.43.20.31; envelope-from=jdinardo@nycap.rr.com; helo=impout007.msg.chrl.nc.charter.net X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17604 Archived-At: I am fairly new to guile and scheme. People tell me that I should use a functional style. I have 3 solutions for project euler problem #1. The first is functional, the second is imperative and the third is written in "Little Schemer" style. I was hoping other guile users would comment on preferences or the "correct way". Sorry in advance for any wrapping problems that may occur. #!/usr/local/bin/guile -s !# (use-modules (srfi srfi-1) (jpd stdio)) ;; for folds (define N 1000) (define ans (fold + 0 (filter (lambda (x) (or (= 0 (modulo x 3)) (= 0 (modulo x 5)))) (iota N)))) (print ans) (define ans 0) (for i N (if (or (= 0 (modulo i 3)) (= 0 (modulo i 5))) (set! ans (+ ans i)))) (print ans) (define ans (let loop ((i 1) (ans 0)) (cond ((>= i N) ans) ((or (= 0 (modulo i 3)) (= 0 (modulo i 5))) (loop (1+ i) (+ ans i))) (else (loop (1+ i) ans)) )))