Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: finding number of contiguous letters

by blazar (Canon)
on May 23, 2007 at 20:03 UTC ( #617103=note: print w/replies, xml ) Need Help??


in reply to Re^2: finding number of contiguous letters
in thread finding number of contiguous letters

I was considering how to do if we had tail recursion.

We do have tail recursion. Well not really: sort of. That's courtesy of magic goto: but then of course one has to explicitly make use of it, not that TR is automatically recognized, which is what you clearly meant.

  • Comment on Re^3: finding number of contiguous letters

Replies are listed 'Best First'.
Re^4: finding number of contiguous letters
by otto (Beadle) on May 24, 2007 at 00:04 UTC
    Blazar,

    You got me thinking, I'm going to play with this some more, but first... are sub arguments, ie a list, evaluated in order?

    For example suppose a list is composed of ( <a>, <b>, <c> )where each of the a, b, c are one or more sub calls that may mutate some value, which may be used by others further down the list, will the list values be evaluated in order of a, b, c, or is it undefined?

    I quickly looked at the sub function and the comma operator which did not shed any light, or at least I didn't see it...

    .. Otto

      For example suppose a list is composed of ( <a>, <b>, <c> ) where each of the a, b, c are one or more sub calls that may mutate some value, which may be used by others further down the list, will the list values be evaluated in order of a, b, c, or is it undefined?

      IIUC, why don't you find out yourself?

      #!/usr/bin/perl -l use strict; use warnings; BEGIN { my $foo; sub foo () { $foo } for my $n (qw/a b c d e f/) { no strict 'refs'; *$n = sub () { warn $n; $foo++ }; } } my $arr=(a,b,c,d,e,f); print foo, $arr; __END__
        Yes, I could find out, but then that would be assuming that all perl interpreters would behave the same for all os'es, compile options, etc. I try to never assume something in the use of a language, because if it is not specified, then any behavior is acceptable, and per spec. Any programmer that uses undefined behavior assuming it will be consistent, is just wanting bugs. Lisp applicative v. normal orders are an example that come to mind of differing evalution methods, each with their benefits and costs. This is why I was asking if perl the language spec'd list element evaluation order...

        Since I was toying around, and since this was lisp-ish, and since eval order would play a huge role in reducing the problem to a tight-lispish-perlish sub, not withstanding the far better solutions via perl's other functions, I was curious if perl did spec eval order, or not...

        The question still stands, is there a language spec regarding evaluation order of list elements.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2020-10-21 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (223 votes). Check out past polls.

    Notices?