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

Re^2: If I was forced to use only one kind of loop for the rest of my days it would be a

by BerntB (Deacon)
on Sep 30, 2005 at 03:36 UTC ( #496327=note: print w/replies, xml ) Need Help??


in reply to Re: If I was forced to use only one kind of loop for the rest of my days it would be a
in thread If I was forced to use only one kind of loop for the rest of my days it would be a

However, the rest of my life is just too long
Someone has better statistics of heart problems among their relatives than I have... :-)
wouldn't choose foreach as the single looping construct, as I've learnt that it wouldn't give me a Turing-complete language.
A language with 'if' statements, blocks and foreach should be Turing complete? Write a state engine with if conditions -- put inside an infinitely looping foreach. (-: To get that foreach, lazy eval would be a feature, of course. :-)

To chose goto and learn source filtering to get everything else is cheating, I guess.

  • Comment on Re^2: If I was forced to use only one kind of loop for the rest of my days it would be a

Replies are listed 'Best First'.
Re^3: If I was forced to use only one kind of loop for the rest of my days it would be a
by ambrus (Abbot) on Sep 30, 2005 at 06:20 UTC

    That's it: an infinitely looping foreach isn't a foreach. It's not a foreach in perl. It's not a for-each in standart scheme either, as r5rs clearly says that the arguments to for-each are lists. (In some interpreters, you can give an infinite list to for-each, but that's clearly an extension. Others, like mzscheme, raise an error on an infinite list.) For in sh and foreach in csh won't allow you to loop infinitely (except for the new arithmetic for loop in bash, but that's not a foreach loop, it's rather a c-style for loop).

      But you said Turing complete.

      A Turing machine is a theoretical construct that needs an infintely long tape, so any implementation has to be a subset, without invoking religion (-: and then you first have to prove that the g.d you use really exists :-).

      So isn't it a bit non-gracious to complain about an infinite list?

      I mean, it wouldn't be impossible to use a tied array. (The semantics for how a list is created makes that impossible, I think?)

      (define a (list 1 2 3)) (set-cdr! a a) (for-each (lambda (x) (display "hello world\n")) a)

        Please read what I said in the parent node.

        That's not a proper list, so r5rs doesn't guarantee this will work. It does work with some scheme implementations, but MzScheme says

        for-each: expects type <proper list> as 2nd argument, given: #0=(1 . # +0#); other arguments were: #<procedure:STDIN::59>
        if I type this code in it.

        Update: let me quote from the r5rs.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2019-10-16 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?