From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.devel Subject: Re: I wrote fluid advection code: How to make this more elegant? Date: Sun, 24 Jan 2016 18:24:22 +0100 Message-ID: <8760yiopq1.fsf@web.de> References: <87io2kpqdq.fsf@web.de> <877fj0lb64.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1453656291 4102 80.91.229.3 (24 Jan 2016 17:24:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 24 Jan 2016 17:24:51 +0000 (UTC) Cc: Arne Babenhauserheide , David A Wheeler , guile-devel@gnu.org To: Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1=2FKammer?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 24 18:24:42 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 1aNOP1-0004TF-UO for guile-devel@m.gmane.org; Sun, 24 Jan 2016 18:24:40 +0100 Original-Received: from localhost ([::1]:32953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNOP1-0000H4-71 for guile-devel@m.gmane.org; Sun, 24 Jan 2016 12:24:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNOOu-0000Gp-7k for guile-devel@gnu.org; Sun, 24 Jan 2016 12:24:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNOOp-0003C4-2v for guile-devel@gnu.org; Sun, 24 Jan 2016 12:24:32 -0500 Original-Received: from mout.web.de ([212.227.15.14]:51578) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNOOo-0003Bx-PB for guile-devel@gnu.org; Sun, 24 Jan 2016 12:24:26 -0500 Original-Received: from fluss ([85.212.92.95]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0LZeou-1Zgf8G1LtE-00lRIa; Sun, 24 Jan 2016 18:24:24 +0100 User-agent: mu4e 0.9.15; emacs 24.5.1 In-reply-to: <877fj0lb64.fsf@T420.taylan> X-Provags-ID: V03:K0:HpCVP4BhJqEb/HeaITP4g0KsU/aXL2yEpmfrLVqtCxBCih0rsFg dwELr+TUbow8d2sUrENp2gzxoLEoks2i8QRmjgOijaVVkXYslawTcO/p3hCvYggQjyrBVfn JYjhX+O+muU0ITBK1s1i97SvtH+MzWIftsMQn3WcAmGlaYtc28Cij4kRKiI576HZyK1wUC8 Q/rw4I9vZzMMZUuB3pFAg== X-UI-Out-Filterresults: notjunk:1;V01:K0:I0WE4XZcR9k=:mhPhxbNmzgMi4MFmkmHuMy s4CKFdKDWdbhbAwYVaJm4Jl+Qfus3GpVS8C0sefR3LE1jUXQfd7sfsq4Oxnzg0qbBKMOtYpPX iFGfRBffSgSQrDE/txv3UjgbBxvmxNRmQ6QrL+U3vlupcpqxvYfq+COa/rI1yb8Ynlw6XB/fn r0GD2/DLWQj6x9GlcJYpN2zB+Hj3snGtIvukJNSUjGAvRKmQD0crUDiBT6hp3TaTLD/niWEGM iv4gURJzeRgVVP59rH81/kGj+eoZ0Sn0HbhiiDo+LnxLAy47KGV+djgXeOa8HEDDkiB0Vgy/n tx1C5z9s/pBe0tL4p7AEXSDokE7GWK9oX6BVX4nelvud0OoJFjarSV/WQHzxyiU3hbcndIpBy iBHY2yJVP1LuZZLFuv/1UfuwD3t2qD6/G0/cRC5P+CjeIGj6rfv/fT3zY8R6NRKfobJncp/WD HKwthmDVfT4u4mCbMdqbPUvsUomTA/kjLrrq5PtM+jsHxHWv7kK25AJEO6tqnpwLyUGonKcW3 kpvjE6QPXI6yhrcwppi7k1RvWAtdOT/0Ij4uwm2CbFJR8dJBoOS2ypMKyydxxa0aUIEoiOt+r a426BOddhE1cnJnhpj3UUy+ifjFR5DosudMRQJGkKELsVfXsYD2yls1uPx1+3ZToxSSYa4/uF DnGumRrxOzAn7V0qNyszIwqSXvVYL4LnCt+k+ufcLcyOv18Ea/za/NaDAQNwFzhtYABvhp1HC 4PRxFg4xmy2vaNjGIlu8yHLQDUz5akn8pezHJTiXVTvXBsoek9x5F3KbGro= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.14 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:18133 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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)) (though this did not work for me in the REPL right now =E2=80=94 did I miss= something?) 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 * psi= [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]})) And I don=E2=80=99t think it=E2=80=99s worse than the Python version, becau= se in Python I also need to first import numpy which changes some semantics (the [] operator changes and arrays have some special properties which can sometimes bite). Besides: when working on the Python, I was tempted to bracket the expression to make it easier to split the lines and make the boundary between sub-expressions clearer: (psi[i] - c1*(psi[i+1] - psi[i-1]) + c2*(psi[i+1] - 2.0*psi[i] + psi[i-1])) Best wishes, Arne PS: CCed to David A. Wheeler who wrote SRFI-105. =2D-=20 Unpolitisch sein hei=C3=9Ft politisch sein ohne es zu merken --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iJwEAQEIAAYFAlalCMcACgkQ3M8NswvBBUhMNwP9Hen4rn4YY2dR1lV3bpNnSAgB vlWpGxZQfIimPaLgEfmBLze3XwqWxgnaovB5xO3I7w77kVXRzj9kDlfDu2+KTGtJ GCll3nVZXMKRYK57NhFIW+IBM9zswFM5R8AKfpM2KmcDY6uVwHBqcL/r6dCmDKgR FpLYT4msZCtH6pKor8w= =Y15k -----END PGP SIGNATURE----- --=-=-=--