Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77654 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53998 invoked from network); 26 Sep 2014 08:23:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Sep 2014 08:23:28 -0000 Authentication-Results: pb1.pair.com header.from=lars@strojny.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lars@strojny.net; spf=permerror; 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:52518] helo=milch.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/35-27411-E7225245 for ; Fri, 26 Sep 2014 04:23:27 -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 10:23:22 +0200 id 0000000000000026.000000005425227A.0000204E Content-Type: multipart/signed; boundary="Apple-Mail=_82E4DF0F-7A9D-4C3B-9E4A-C1A453C855E3"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <54233506.8080102@gmail.com> Date: Fri, 26 Sep 2014 10:23:21 +0200 Cc: internals@lists.php.net Message-ID: <094CB804-0F9F-44D4-BCA2-4D7612E92C10@strojny.net> References: <54233506.8080102@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=_82E4DF0F-7A9D-4C3B-9E4A-C1A453C855E3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi everyone, On 24 Sep 2014, at 23:17, Rowan Collins wrote: > switch ( $number ) use ( =3D=3D=3D ) { [...] > switch ( $age ) use ( < ) { [...] > switch ( calculate_age($birth_date, $departure_date) as = $age_at_departure ) use ( < ) { [...] > switch ( $product ) use ( instanceOf ) { All of these examples are trying to reinvent concepts that can be solved = with guards, pattern matching and overloading in other languages. In = Erlang one can write the same function name multiple times and guard it = ("when" in fact(N)) or match the value ("0" in fact(0)). fact(N) when N>0 -> N * fact(N-1); fact(0) -> 1. In Scala one could replicate the instanceof behaviour by defining = multiple methods of the same name with different argument types. So I would rather see us making method declarations more flexible to = cover those use cases instead of shoving all the functionality into = switch/case. Last time I checked the interpreter to try and introduce = more features around method declarations, it looks incredibly hard to do = in a way that performs well. What is our stance on adding advanced = features around declaring methods? cu, Lars --Apple-Mail=_82E4DF0F-7A9D-4C3B-9E4A-C1A453C855E3 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 iQIVAwUBVCUieSQPF+sCY6wHAQJInA/+MCqIxbEXbFIJ/IwB0G8jQ3fKp9XU/I/E mz9Ygv0kavHz+OFw9e96tT1xLcRfdqFxh6X0bR25HR35zGYBPceAyr0EmknZk/qX PaJSsmppRdDPgkM79/lXP09Zpz9kDeF5DpQK+s2xNpSGvA+pJmioqaYaVkYF78vN CCPFAlrnnwNoZ9qWJs2e28tZ0vvPYoOR1ePWLuTiR3feQ/IkiuoD80G7ULvQ6lVF 9LQebzpSmLXlWJuX0mrlRnzQz6goRueHhmCPhREAl3in/Q1OWrkvZCzHyQDX/xHh QzLZBkBmkGT2fTPEIvo8J3L+q8sR3mOazVBxmDqPJumS8I0z13UlpQdEwHpcYEGF /fmT1T++vpH4tyinUnmN4Ecoc/N81aKxN7h1RrDRLyOEKBuKqyWy0FdQIM7V9gOE 5Kv3mrgB+RzfLkljO5v0wj3GytA+9spoy4Fr7Sa7OuNefr6LTJrUs3GcNh2oDKzL gYG/haQzOGUo7tCZF27RZ2fXsVCX5rbxDR0NszlQ19QeKoHCOEeWtbiV2jIX2j3w qCEi0eItoqTaOBWSE6mCgVyd1zWBR65rOltRtZv03XqyCUcyJeG0ZYCJCNVsicKK ark3CK/SJoaa2LJL7pcxgb7l8zgm1+mn8w9SpGBiFkaH+ojvbszy6L9iOCPjxr69 cvp2zUkqnJc= =gSHp -----END PGP SIGNATURE----- --Apple-Mail=_82E4DF0F-7A9D-4C3B-9E4A-C1A453C855E3--