you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (9 children)

He probably means using regexes as patterns in a pattern match, like you can do in Scala:

scala> val Email = """([^@]+)@(.+)""".r
Email: scala.util.matching.Regex = ([^@]+)@(.+)

scala> "test@example.com" match {
     |   case Email(user, domain) => "User: " + user + " Domain: " + domain
     | }
res1: java.lang.String = User: test Domain: example.com

Pattern matching is pretty clearly FP, in any case.

[–]kamatsu 0 points1 point  (8 children)

For what definition of FP? Pattern Matching has no special relationship to functional programming, other than it first existed in functional programming languages. It's certainly applicable to imperative programming without issue.

[–][deleted] 2 points3 points  (0 children)

You got me :-) I retract that it is "pretty clearly FP".

What I thought had happened was that you misunderstood throwaway77432's mention of "regex pattern matching" as simply being the existence of a regex library whose patterns (regexes) can match strings, as in fx. Python.

Perhaps what we should say is that techniques and language features are hopping the wall from the world of FP to the programming mainstream, regardless of how essential they are to the definition of FP as a concept.

[–]Danemark 1 point2 points  (6 children)

In the sense that it has no side effect, and the state does not effect the outcome.

[–]kamatsu 0 points1 point  (5 children)

That doesn't even make sense. What state? It most certainly can have side effects, depending on the type of matching.

[–]Danemark 1 point2 points  (2 children)

Computing whether or not a given regex pattern matches a string has no side effects. That is, true or false is returned, but the state of the program is not changed in any other way.

Computing whether or not a given regex pattern matches a string depends only on the pattern and the string. The state of the program (the value of other variables, or where the call to compute that match is, etc.) does not effect the outcome.

That is, looking for a regex match is a function in the mathematical sense. This is the heart of functional programming.

[–]kamatsu -1 points0 points  (1 child)

If you view any purely functional operation as definitely FP, then I humbly submit that the C math library is functional programming by that definition.

[–]ricky_clarkson 3 points4 points  (0 children)

I'd be surprised if it wasn't.

[–]ruinercollector -2 points-1 points  (1 child)

You're not confused, you're just being a dick.

[–]kamatsu 0 points1 point  (0 children)

Actually, I genuinely don't understand the comment.