Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77683 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24506 invoked from network); 26 Sep 2014 17:41:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Sep 2014 17:41:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=lars@strojny.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lars@strojny.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain strojny.net from 46.4.40.248 cause and error) X-PHP-List-Original-Sender: lars@strojny.net X-Host-Fingerprint: 46.4.40.248 milch.schokokeks.org Received: from [46.4.40.248] ([46.4.40.248:49562] helo=milch.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/E3-02658-535A5245 for ; Fri, 26 Sep 2014 13:41:10 -0400 Received: from [192.168.2.229] (p50931bfd.dip0.t-ipconnect.de [::ffff:80.147.27.253]) (AUTH: PLAIN lars@schokokeks.org, TLS: TLSv1/SSLv3,256bits,ECDHE-RSA-AES256-SHA) by milch.schokokeks.org with ESMTPSA; Fri, 26 Sep 2014 19:41:06 +0200 id 000000000000002C.000000005425A532.0000599D Content-Type: multipart/signed; boundary="Apple-Mail=_EFACA1F0-F975-4927-8F4F-6565AC012316"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <54259039.5020809@gmail.com> Date: Fri, 26 Sep 2014 19:41:02 +0200 Cc: internals@lists.php.net Message-ID: <2876FD14-51DF-4CD2-A4DE-E4DFAC846BC2@strojny.net> References: <54233506.8080102@gmail.com> <094CB804-0F9F-44D4-BCA2-4D7612E92C10@strojny.net> <54259039.5020809@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] Little switch improvement: get the used variable From: lars@strojny.net (Lars Strojny) --Apple-Mail=_EFACA1F0-F975-4927-8F4F-6565AC012316 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 Hi Rowan, On 26 Sep 2014, at 18:11, Rowan Collins wrote: [...] > Without the additional guarantees provided by a purely functional = environment, that's really just inverting the function header and if = statement. >=20 > Adding an extra case to that still means repeating the operator, so = isn't the same as what I was talking about at all: >=20 > foo(N) when N>100 -> > N ** foo(N-10); >=20 > foo(N) when N>0 -> > N * foo(N-1); >=20 > foo(0) -> > 1. That is true, for the guarding it is indeed syntactic sugar. Sugar that = could probably help with optimisations as it makes reasoning easier from = an interpreter perspective but still syntactic sugar. >=20 >> In Scala one could replicate the instanceof behaviour by defining = multiple methods of the same name with different argument types. >=20 > Or, indeed, in most strongly typed languages; in OOP, polymorphism can = be exploited for the same purpose, e.g. using the Visitor Pattern. = Again, I'm not sure what this has to do with switch statements, except = that overloading and polymorphism can both allow you to factor out *any* = if/switch statement, if you so desire. That is exactly my point: instead of "optimising" the switch/case = construct which is good enough as if/elseif/else replacement I feel our = time would be better spent on thinking of polymorphism, guards and = pattern matching. cu, Lars --Apple-Mail=_EFACA1F0-F975-4927-8F4F-6565AC012316 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iQIVAwUBVCWlLiQPF+sCY6wHAQK5CA//fkMf8ApzDaXlP9TDOUZr2GH4YTb0GUUm QGuqWFr2Xmsj4vHJJCLiKMpvsStIW+pnoc/dIVJkWOYtY1UaVRCicjcO/oI36lCU lNx+JxL0zwB6Ng+LA0xLoaqkStKOsmW86DBEREpqk/mwqLPhHWrXLq0jC8s9f4yP euqikp9pf1d+6GpQuDtdCo6GoO53rRcCuofP8d6tIKWXkepSI265cJvyG1pSafYs jpHvsrjQAYiZaetEi2ad499FLWjM07TrHL/QZLP3uuxNtv8YA9PudzCldMX69ClB QHEHbTnsSu214UaDTi2zuZqlTBOqEVAU/4mgbdQcNlXNMiOXSUA/0pPdNIT0Miua u1slpaoVM8vBOdQeZuhgOVFgZ59GIujvzuOrwxJm2AvCU+CunSTCuS1MmYydkTNT QXjX/cu69pDQ6e9WTOoD+TV5zRJ8HgRUxW5hpaRhlEbIZww7DZNZ1+Pm8DNT57FU mVMI24x/kGg91jCIukEVCvpDJv7HlvkA7aiBlLqcJDTsCH4kYwxQAZlD5eLDQiLn 2fNwLz9oOjVRhslPIfcbM89MXNYaM+YM2umBJlo3uXQGCPAm5uqeImjQb5WK8hhy xVU62KhckzSgqSHX9NWdfm1jUJzD2HiBSgaYuk4w+/wdNswL9hpCoqluxLtR/ugr 5R5XBFYD9f8= =iFMF -----END PGP SIGNATURE----- --Apple-Mail=_EFACA1F0-F975-4927-8F4F-6565AC012316--