From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: I wrote fluid advection code: How to make this more elegant? Date: Sun, 24 Jan 2016 18:46:43 +0100 Message-ID: <878u3ekgzg.fsf@T420.taylan> References: <87io2kpqdq.fsf@web.de> <877fj0lb64.fsf@T420.taylan> <8760yiopq1.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1453657389 20118 80.91.229.3 (24 Jan 2016 17:43:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 24 Jan 2016 17:43:09 +0000 (UTC) Cc: guile-devel@gnu.org To: Arne Babenhauserheide Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 24 18:43:09 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aNOgt-0005cj-H6 for guile-devel@m.gmane.org; Sun, 24 Jan 2016 18:43:07 +0100 Original-Received: from localhost ([::1]:32979 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNOgp-0003Lv-MP for guile-devel@m.gmane.org; Sun, 24 Jan 2016 12:43:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNOgi-0003Ln-Fy for guile-devel@gnu.org; Sun, 24 Jan 2016 12:42:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNOgh-00075A-Ft for guile-devel@gnu.org; Sun, 24 Jan 2016 12:42:56 -0500 Original-Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:34593) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNOgh-000755-8d for guile-devel@gnu.org; Sun, 24 Jan 2016 12:42:55 -0500 Original-Received: by mail-wm0-x236.google.com with SMTP id u188so40311664wmu.1 for ; Sun, 24 Jan 2016 09:42:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=alyYDvLB+5lS07ncsavJfrF5Qx7Tf4B64QVnfCpv/8M=; b=0CDsTl6QNe3IABweL0/F4VYRfb1awQCY3119TAyEDg+NhxEaeFZnyEc4j/n1LSRZa5 Ohic9eQbEsK8XeUx6Cqpy/MwBzPRjOKzT2RqZ2mugkJiQDodf9EHsW9UJ4HhbLK9x/je AcrNcTurBBJrCNUTJoW8J9864uErhux+qLgdlis7wQG1Gi9VpAs0EJCb9mUEzCMos+yH EqW0tSWOAMC99YpsIR/n70QqKeQYspdbMr5JO0Rjenaqi/ZRgKXYWbZcJOf7LQm5Ctux ocWxp6FPv7R1IyUYFRs9AUId5gTR8L/6krXjNWdkSvrE11vfTuBrBFmWwXUh7QxHNtPG xEOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=alyYDvLB+5lS07ncsavJfrF5Qx7Tf4B64QVnfCpv/8M=; b=aevqCutQEpygUeIteOdyUSoEpOG0OEX1IMkyQghz9Wy76JPmlqU6d/eU8lo6o8s9O8 y3SPiMVFs4TWqqeRXUF/iAIT8MsDKLBpVHE03Tr27TxDaLJk4u+NeoQq48G53IgS9cl+ 358Cb/HOz+pJPMome24/1xo2jL06IKKuXJh6JX6WUNuEXhrUJGXh6iefF4H5iAsJ+HXe +sS3OvLgJICZPxUeA4fSiPNKzRCLQwRmmadIsqicZOIFPmp1LizroFdaBS8iwP/4shfQ qhi377M34LJlvs4k8OZUbk9UibF1JmBWvD5GV6KO8lRio8uAhiQtBhAbhJt8getyu54p TXGA== X-Gm-Message-State: AG10YOT52O02G38SUG/6VVqmPlcw7OWkvx5i+5BDvVOGyiZqCMChHB83fOfXNEg/BjkgAQ== X-Received: by 10.28.90.67 with SMTP id o64mr13289341wmb.38.1453657372639; Sun, 24 Jan 2016 09:42:52 -0800 (PST) Original-Received: from T420.taylan ([2a02:908:c30:3ec0:221:ccff:fe66:68f0]) by smtp.gmail.com with ESMTPSA id v2sm12389092wmv.12.2016.01.24.09.42.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Jan 2016 09:42:51 -0800 (PST) In-Reply-To: <8760yiopq1.fsf@web.de> (Arne Babenhauserheide's message of "Sun, 24 Jan 2016 18:24:22 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::236 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:18134 Archived-At: Arne Babenhauserheide writes: > Taylan Ulrich Bay=C4=B1rl=C4=B1/Kammer writes: >> Arne Babenhauserheide writes: >>> The original version was in Python: >>> >>> psi[i] - c1*(psi[i+1] - psi[i-1]) + c2*(psi[i+1] - 2.0*psi[i] + psi= [i-1]) >>> >>> My port to Scheme looks like this: >>> >>> (let ((newvalue (+ (- (psir i) >>> (* c1 (- (psir (+ i 1)) (psir (- i 1))))) >>> (* c2 (+ (- (psir (+ i 1)) (* 2 (psir i))) >>> (psir (- i 1))))))) >>> (array-set! psinew newvalue i)) >> >> Guile supports SRFI-105, so that could be: >> >> {{psi[i] - {c1 * {psi[{i + 1}] - psi[{i - 1}]}}} + {c2 * {{psi[{i + = 1}] - {2 * psi[i]}} + psi[{i - 1}]}}} > > That=E2=80=99s already pretty close =E2=80=94 I wonder why I didn=E2=80= =99t think of the psi[i] > form. > > I think a + around the equation would actually help here: > > (+ psi[i] > (* -1 c1 {psi[{i + 1}] - psi[{i - 1}]}) > (* c2 {{psi[{i + 1}] - {2 * psi[i]}} + psi[{i - 1}]})) > > Though neoteric expressions combined with curly infix make this even > easier: p{i + 1} =E2=86=92 (p (+ i 1)) Good call, I had forgotten that's included in SRFI 105. (Thought it was just for x[y].) > (though this did not work for me in the REPL right now =E2=80=94 did I mi= ss something?) Any SRFI 105 syntax must appear within {}, so that would have to be e.g. {p{i + 1}}, although if it appears within a larger {} block then it won't have that annoyance. > So the function psir could be used to have elegant access to elements: > > (+ psi[i] > (* -1 c1 {psi[{i + 1}] - psi[{i - 1}]}) > (* c2 {{psi[{i + 1}] - {2 * psi[i]}} + psi[{i - 1}]})) > >> {psi[i] - c1 * {psi[i + 1] - psi[i - 1]} + c2 * {psi[i + 1] - 2 * ps= i[i] + psi[i - 1]}} > > That looks roughly as readable as the Python version. With the + around > I think it becomes better: > > (+ psi[i] > (* -1 c1 {psi[i + 1] - psi[i - 1]}) > (* c2 {{psi[i + 1] - {2 * psi[i]}} + psi[i - 1]})) I agree mixing in some prefix notation actually makes things more readable here. Taylan