Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: What technical benfits perl offers over python + few more questions. (first class functions)

by LanX (Saint)
on Nov 13, 2021 at 15:46 UTC ( [id://11138782]=note: print w/replies, xml ) Need Help??


in reply to Re: What technical benfits perl offers over python + few more questions.
in thread What technical benfits perl offers over python + few more questions.

> 2. I'm not sure I understand how a function can be thought of as a second-class citizen;

because that's FUD

"First class object" aka citizen basically means you can pass functions around as arguments to other functions. E.G. most BASIC dialects I've seen couldn't do that.

It's a necessity for functional programming...

Perl is actually better in functional programming, since Python is restricting lambdas to one expressions only, while anonymous subs are free.

And Python doesn't offer any block prototype to make it even easier like sub foo (&) { $code = shift; ... }

Superficial people will claim that the need to explicitly reference named subs in Perl with ...

\&foo

means they are not first class.

Superficially so because almost everything in Python is implicitly a reference.

Now, who said explicit is better than implicit again ...???

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: What technical benfits perl offers over python + few more questions.
by talexb (Chancellor) on Nov 13, 2021 at 15:56 UTC
      because that's FUD

    Huh .. too bad. I dealt with FUD with Microsoft continually slamming OS/2 in the late 80's, where we slagged Windows NT on the Canopus form on Compuserve. Good times.

    I developed code in C before moving to Perl in the late 90's, and was advanced enough that I was comfortable using function pointers in my code .. so when I wanted to do the same thing Perl, it was there already. Perfect, because being able to declare a callback function (one example of a function pointer) is extremely handy.

    And I don't really care what the TIOBE results say .. if a CTO contacts me to say 'Perl developers are really hard to find' and 'Are you available?', I don't find the burning need to go learn a different language. And, of course, the Perl community has been very supportive and welcoming. So I'm not going anywhere anyway. :)

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

          For instance, can you write a generator function which returns an iterator function?

        My understanding of an iterator function tells me it's code that returns an item from a list -- which sounds like dynamic code. I don't believe C can do that easily.

          What about closures?

        C does have scoped variables, where a variable only exists within a pair of braces. When I was writing C code that got cross-compiled to 68000 assembler, I could see that the compiler just assigned space on the stack for that type of variable by moving the stack pointer down, and once the scope ended, the stack pointer was just adjusted back up.

        C also has the static keyword, which says the variable is to be stored in the lexical scope, meaning it's created at the beginning of the run (perhaps on the stack, but not anywhere that's going to get re-used), and only initialized once, if that initialization happens during declaration. So my guess is that closures are possible -- but keep in mind I studied engineering and not computer science, so that opinion is just what I've picked up since I left university.

        Alex / talexb / Toronto

        Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

        C can't do closures. It can't even do nested functions. But even if it could do nested functions, it still couldn't do closures because function pointer are just addresses. There's no way to attach data to them.

        See here for a more detailed explanation of the above.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found