Message from discussion
Common Lisp style question
Received: by 10.227.147.18 with SMTP id j18mr207008wbv.4.1307187216936;
Sat, 04 Jun 2011 04:33:36 -0700 (PDT)
X-BeenThere: land-of-lisp@googlegroups.com
Received: by 10.227.149.146 with SMTP id t18ls1599032wbv.0.gmail; Sat, 04 Jun
2011 04:33:36 -0700 (PDT)
Received: by 10.227.130.104 with SMTP id r40mr223759wbs.14.1307187216246;
Sat, 04 Jun 2011 04:33:36 -0700 (PDT)
Received: by 10.227.130.104 with SMTP id r40mr223758wbs.14.1307187216229;
Sat, 04 Jun 2011 04:33:36 -0700 (PDT)
Return-Path: <peter.fri...@gmail.com>
Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181])
by gmr-mx.google.com with ESMTPS id ge17si2855275wbb.1.2011.06.04.04.33.36
(version=TLSv1/SSLv3 cipher=OTHER);
Sat, 04 Jun 2011 04:33:36 -0700 (PDT)
Received-SPF: pass (google.com: domain of peter.fri...@gmail.com designates 74.125.82.181 as permitted sender) client-ip=74.125.82.181;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of peter.fri...@gmail.com designates 74.125.82.181 as permitted sender) smtp.mail=peter.fri...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by wyi11 with SMTP id 11so2660581wyi.40
for <land-of-lisp@googlegroups.com>; Sat, 04 Jun 2011 04:33:36 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:content-type:mime-version:subject:from
:in-reply-to:date:content-transfer-encoding:message-id:references:to
:x-mailer;
bh=Pc/sklClDkUsJkaDWMnwxVXtrwpLjSE3HBtPl42A+hA=;
b=gMO9PdknUnY2IBWRbu5PuGguINSpe98DQ5lIXeDOm7zUKw/JZygC3NW9EVCoITJ9lX
VIHsbQ8xMh2oudR9UAQuRMeclnqYWU8p/Zc32oMa7WAFeC9QTDeZMjpkjc14DDpaLN+K
88RCSA1NP0U1WMazk/i8hxnCVYTYI8fo+S11k=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=content-type:mime-version:subject:from:in-reply-to:date
:content-transfer-encoding:message-id:references:to:x-mailer;
b=BzkU5XxM0dkzSRM6+wtdgHaYx9XeXQvNeAk9HnoT6zsFNk+27DmACAQiUnWvd8UANA
hdlkbNhw36Mamaf2LwjeHpnFRul+qqC4tLEmzZ1Y26hhMue6DF4o2GbLifSmy2JmOvzj
tsZsdYpXKXg/cWKU21NE5ubKn6Om5E2B0Q3mg=
Received: by 10.217.7.71 with SMTP id z49mr487155wes.33.1307187216094;
Sat, 04 Jun 2011 04:33:36 -0700 (PDT)
Return-Path: <peter.fri...@gmail.com>
Received: from [10.0.1.2] (d515374FE.access.telenet.be [81.83.116.254])
by mx.google.com with ESMTPS id o38sm1595693wba.54.2011.06.04.04.33.33
(version=TLSv1/SSLv3 cipher=OTHER);
Sat, 04 Jun 2011 04:33:35 -0700 (PDT)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Apple Message framework v1084)
Subject: Re: Common Lisp style question
From: Peter Frings <peter.fri...@gmail.com>
In-Reply-To: <aef4fc95-5edc-43af-820f-5a8955869...@n10g2000yqf.googlegroups.com>
Date: Sat, 4 Jun 2011 13:33:32 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <E76ADFCF-B8D6-4155-8E8A-B97197049...@gmail.com>
References: <48AFAE21-1CD0-44BE-AEB4-CDA13E998...@kenworthy.info> <f27accd4-810d-4d56-87da-e37e7565b...@l18g2000yql.googlegroups.com> <aef4fc95-5edc-43af-820f-5a8955869...@n10g2000yqf.googlegroups.com>
To: land-of-lisp@googlegroups.com,
Purity Control <cr...@craigferry.net>,
Edward Kenworthy <edw...@kenworthy.info>
X-Mailer: Apple Mail (2.1084)
I prefer the first, with the (let).=20
As Craig said, it's clearer for the programmer and the ones that need to =
maintain it afterwards. Let the compiler figure out how to compile it in =
the most efficient way, and only optimize when it's indeed a verified =
bottleneck. In Knuth's words: "premature optimization is the root of all =
evil". (About optimization: often, using a better algorithm gains you =
more that tweaking a few bits here and there.)
So, go for the most understandable code.
As for the question whether it's too imperative, I would answer no. =
While the language allows you to modify those variables, you don't: you =
use them as constants. It's not because the language allows mutation, =
that your code is imperative. It's the code. (Which would've been my =
answer to the *ear-muffs* discussion a couple of days ago as well.)
A similar question is when using (nreverse) when returning a newly =
constructed list (common idiom in recursion with accumulators). It's not =
strictly functional, since you modify a variable. But for all practical =
purposes, it is functional (and it's also a bit of premature =
optimization :-) ).
So, adhere to the *ideas* of FP and avoid `extremism'. Else learn =
Haskell where even (random) is strict :-)
Cheers,
Peter.