Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re^3: regex and "Functional Programming" by FoxtrotUniform
in thread regex and "Functional Programming" by perlcapt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found