https://issues.dlang.org/show_bug.cgi?id=596
Andrei Alexandrescu changed:
What|Removed |Added
Status|ASSIGNED|RESOLVED
Resolution|---
https://issues.dlang.org/show_bug.cgi?id=596
Andrei Alexandrescu and...@erdani.com changed:
What|Removed |Added
Version|unspecified |D2
--
https://issues.dlang.org/show_bug.cgi?id=596
--- Comment #15 from bearophile_h...@eml.cc ---
See also the work-in-progress specs for pattern matching in C#:
https://onedrive.live.com/view.aspx?resid=4558A04E77D0CF5!5396app=Word
--
https://issues.dlang.org/show_bug.cgi?id=596
--- Comment #14 from bearophile_h...@eml.cc ---
Meta in the D newsgroup suggests other names for unapply: opDestructure or
opMatch. I think opMatch sounds good and better than unapply for D.
--
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #13 from bearophile_h...@eml.cc 2013-03-29 15:51:03 PDT ---
It's useful to switch on struct values:
import std.bigint;
void main() {
auto x = BigInt(3);
switch (x) {
case BigInt(0): break;
default: break;
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #10 from bearophile_h...@eml.cc 2013-03-03 04:24:29 PST ---
When final switch supports structs, writing a fizzBuzz
(http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
) gets simpler and safer:
http://d.puremagic.com/issues/show_bug.cgi?id=596
Simen Kjaeraas simen.kja...@gmail.com changed:
What|Removed |Added
CC|
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #12 from bearophile_h...@eml.cc 2013-03-03 10:50:27 PST ---
(In reply to comment #11)
The problem of your proposed pattern matching is that there is not necessarily
a simple correlation between constructor parameters and runtime
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #9 from bearophile_h...@eml.cc 2013-02-19 16:22:06 PST ---
To match classes Scala uses the standard method unapply:
http://www.scala-lang.org/node/112
object Twice {
def apply(x: Int): Int = x * 2
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #8 from bearophile_h...@eml.cc 2011-09-28 19:13:23 PDT ---
Supporting something like this will be very useful (this is done very commonly
in functional languages):
import std.variant: Algebraic;
alias Algebraic!(int, float) A;
void
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #7 from bearophile_h...@eml.cc 2011-08-15 16:44:27 PDT ---
One more useful use is with OOP (this is GUI code):
import core.stdc.stdio;
class Control {}
class Slider : Control {}
class Button : Control {}
void main() {
Control c
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #5 from bearophile_h...@eml.cc 2011-03-21 18:24:53 PDT ---
If structs too gets supported by switch, then BigInts too become allowed:
import std.bigint;
void main() {
auto x = BigInt(3);
switch (x) {
case BigInt(0):
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #4 from bearophile_h...@eml.cc 2011-01-30 06:37:06 PST ---
(In reply to comment #3)
struct Foo { int x, y; }
void main() {
auto f = Foo(1, 2);
int f;
switch (f) {
case Foo(1, _): break; // all structs where
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #3 from bearophile_h...@eml.cc 2011-01-07 05:13:09 PST ---
A possible improvement for the switch on structs is to support wildcards in
some way:
struct Foo { int x, y; }
void main() {
auto f = Foo(1, 2);
int f;
switch
http://d.puremagic.com/issues/show_bug.cgi?id=596
Andrei Alexandrescu and...@metalanguage.com changed:
What|Removed |Added
Status|NEW |ASSIGNED
http://d.puremagic.com/issues/show_bug.cgi?id=596
bearophile_h...@eml.cc changed:
What|Removed |Added
CC||bearophile_h...@eml.cc
---
16 matches
Mail list logo