Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using pattern matching 😻 #5

Open
h4cc opened this issue Nov 28, 2014 · 3 comments
Open

Using pattern matching 😻 #5

h4cc opened this issue Nov 28, 2014 · 3 comments

Comments

@h4cc
Copy link
Contributor

h4cc commented Nov 28, 2014

Just a quick idea. If there are placeholders like __, maybe there is a chance to implement something like erlang has with its pattern matching system. 😻
A simple matching on ints, strings or booleans for a start would be interesting. 💓

@h4cc
Copy link
Contributor Author

h4cc commented Nov 28, 2014

Just a very tiny example: https://gist.github.com/h4cc/7bb9da10d6897944a63c

Best idea i had till now was using a Pair(pattern, function) to solve that.

@mathiasverraes
Copy link
Owner

Looks cool :-) Please make a PR so we can explore it further.

We need examples that proof the usefulness though. If we can only do pattern matches that can be easily rewritten as return $x == 42 ? "Called with 42" : "Called with $x"; then there's no point.

@turanct
Copy link
Contributor

turanct commented Jun 14, 2015

this would be very practical if we could do something like this:

<?php

function map($function, $list)
{
    match($list,
        with(l(), l()),
        with(cons($head, $tail),
            cons($function($head), map($function, $tail))
        )
    );
}

trouble with this is that $head & $tail are unassigned at the moment we do the with() call, which will lead to php errors&warnings. Anyone with ideas about how to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants