Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: regex and "Functional Programming"

by FoxtrotUniform (Prior)
on Oct 23, 2004 at 00:22 UTC ( #401733=note: print w/ replies, xml ) Need Help??


in reply to regex and "Functional Programming"

See, for instance About Haskell. Personally, I think of "functional programming" as a style of programming that doesn't do much in the way of assignment or iteration and treats functions as first-class values: for instance, functions can take functions as parameters and return other functions. An example might be Specializing Functions with Currying. Most functional languages are really good at list processing, Lisp being the canonical example.

--
Yours in pedantry,
F o x t r o t U n i f o r m

"Lines of code don't matter as long as I'm not writing them." -- merlyn


Comment on Re: regex and "Functional Programming"
Re^2: regex and "Functional Programming"
by Zed_Lopez (Chaplain) on Oct 23, 2004 at 15:06 UTC

    There's a whole lot of iterating going on in functional languages; it's just going to tend to look like perl map or foreach loops and not like a while or C-style for loop.

    Generally, though, where applicable, one's more likely to choose a recursive algorithm than an iterative one, which is likely what you meant, but, well, yours in pedantry and all.

      There's a whole lot of iterating going on in functional languages; it's just going to tend to look like perl map or foreach loops and not like a while or C-style for loop.

      Heh. I can't speak for all functional languages, but the map function in Haskell is defined recursively in the Haskell Standard Prelude. So is iterate (which really means "repeat-compose"), as well as the folds. Hell, even the "iterative" sequenced monad operations are defined recursively. Mostly, this follows from the recursive definition of lists: a list is either an empty list, or a datum consed onto a list.

      There's probably some iteration going on in even the most standards-compilant Haskell implementation, but as far as I can tell none of it happens at the language level. Feel free to correct me, though, if you find any in the Prelude; I don't know it as well as I ought.

      Of course, the first example in my copy of ANSI Common Lisp isn't very "functional" at all:

      (defun sum (n) (let ((s 0)) (dotimes (i n s) (incf s i))))

      --
      Yours in pedantry,
      F o x t r o t U n i f o r m

      "Lines of code don't matter as long as I'm not writing them." -- merlyn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://401733]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-12-25 03:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls