From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Lam Newsgroups: gmane.lisp.guile.user Subject: Re: guile style Date: Sat, 19 Jun 2021 19:20:06 +0800 Message-ID: References: <7aeef132-6bd7-c178-5786-c0a3d6b3edc8@nycap.rr.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5853"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel-confirm+bec536c361a61d32a192d9a45ad6dea4f892df58@gnu.org, guile-user To: jerry Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jun 19 13:20:45 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 1luZ1p-0001NB-1v for guile-user@m.gmane-mx.org; Sat, 19 Jun 2021 13:20:45 +0200 Original-Received: from localhost ([::1]:54390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luZ1n-0001dV-7k for guile-user@m.gmane-mx.org; Sat, 19 Jun 2021 07:20:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luZ1T-0001d4-Ef; Sat, 19 Jun 2021 07:20:23 -0400 Original-Received: from mail-qk1-x72d.google.com ([2607:f8b0:4864:20::72d]:42569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luZ1Q-0005cB-TV; Sat, 19 Jun 2021 07:20:23 -0400 Original-Received: by mail-qk1-x72d.google.com with SMTP id w21so3974585qkb.9; Sat, 19 Jun 2021 04:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XGBFjVt+8WyQFl07taN9GfK9N1W7Y3+OtMzmjt9jScY=; b=GZZcDTA9GM+tr85lYazTFKR+bqmKPOTnSM1y/BqLiR951JjPgd/s5BL3dCnu2MgGI1 qIslHOMEcp0v5tWBrD5Rw7kkDjzERG1FcLtxSdv+cpkfXfAdFvU56lS9bKz+jbj1UnYY nAYuvhMSIqD8V/2AE7Wsxqa/m33Id7NyYOknP2/XGXJeNRQrTMNuuL+KBY+AhPBLk2ux ouxRD2rr25ct+DYI7B6/gOYWWqSfGONrqatx8IYjysxOrEp2v5Vvu770ULsUpz/e56DK 0erbmEPYm3ItgjHhIiS5cW0NDYbJ63fvq2oowAq11zhTU1UMsj7MnOtqyd/m9MdS0I1q YszQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XGBFjVt+8WyQFl07taN9GfK9N1W7Y3+OtMzmjt9jScY=; b=LKn8Oh2IQ4jei2xGSDVTLRWZ3yPCaXO+YuWN0bB9QGLcDhFAyuTakDO5pV2G5z9uK8 DF5W/tBo9wlsKqdy7SPQQyG8zvMYg8wCwl04F/WeJMm69vwQ3qFF/TYrXDK/O/s5L2Yg //kgQLh7hx2X1nhyKsxMdVWfK6Xy8uN+jGBJdw+ObLQ74HjVX3Uv2DWSen/AklgWQMy1 uKRuZKksGZkOxyD27U0LrRM8jG4Ky0vPjhmCcz5o2o93XLCGCL19st7TqxTykx+T693i hF8+RWXiKHYhkOu8ucjkWgl8LIs+9dTsp0hoQiIOB3ialFmNxpANwvbHHhaR+3TOnkv3 vBRg== X-Gm-Message-State: AOAM533aOBGYFM1aLsVuhlPXj8uZNh9nC2FQJvJTIXWQdIbEl71qs3Bd mv3tUSPZIoXNNsnhi6mGcoFSfef9f74YTseffP4= X-Google-Smtp-Source: ABdhPJxXefEQdMhpryyxjAgnx26/cFisGy0Ls2e9mKOyKH2u7JyuNe5LRmA9PfOObScYXefDz+kmZIrhksuVwCLZqx8= X-Received: by 2002:a05:620a:2052:: with SMTP id d18mr13802900qka.185.1624101618493; Sat, 19 Jun 2021 04:20:18 -0700 (PDT) In-Reply-To: <7aeef132-6bd7-c178-5786-c0a3d6b3edc8@nycap.rr.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::72d; envelope-from=christopher.lck@gmail.com; helo=mail-qk1-x72d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:17608 Archived-At: Agree set! is not a desirable form. It is not consistently optimisable. I cannot find the reference in the manual. Also consider the first form: you're building a list in 3 passes -- call iota to generate a list, call filter to navigate the list again, then fold to accumulate your answer. Therefore it's O(3N). The preferred form is definitely from the little schemer. On Sat, 19 Jun 2021, 8:56 am jerry, wrote: > 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)) ))) > >