LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-30-2013, 10:15 PM   #1
stateless
Member
 
Registered: Jan 2013
Distribution: Debian
Posts: 166
Blog Entries: 1

Rep: Reputation: 4
python: passing functions or unevaluated code with multiple lines or expressions


Hey guys, I'm really a lisp programmer at heart, but I'm doing python programming to pay the bills. So, I've been trying to make my python experience as functional as possible. Obviously, passing functions in as a parameter (or the closest thing I can get to that) is pretty important.

I've found that I can 1) define a function and pass in the name, 2) eval() a string, or 3) use a lambda without parameters. Stylistically, option 3 is much preferred -- however, it seems that there is a one-line limit for lambdas that is not going away any time soon.

I am wondering if there is some trick to get around that lambda limitation. Or some other approach I haven't considered.

Last edited by stateless; 11-30-2013 at 10:18 PM.
 
Old 11-30-2013, 10:38 PM   #2
Garda
Member
 
Registered: May 2005
Distribution: Debian
Posts: 83
Blog Entries: 2

Rep: Reputation: 15
I could be wrong about all this and making it up, but I believe it was this video (and I can't remember when, but it's around the time he talks about functional things) in which Guido discusses exactly this. Basically, he's not too big a fan of functional programming and it's supposed to be that lambdas are only one line. Similarly, he keeps wanting to get rid of reduce() and thinks it was a huge mistake.

I think it's part of the Python philosophy that you can do it in a million ways, but doing it the Python way is the safe, uncontroversial way that will probably work out OK. I think Python is the slightly conservative, middle-american of programming languages.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl code to split multiple lines of data into 2columns lakssreedhar Linux - Newbie 4 07-02-2012 06:50 PM
[SOLVED] passing globbing expressions as argument to bash script mdcjsps Linux - Newbie 6 10-29-2011 05:09 AM
[SOLVED] python passing multiple args to bash gary_in_springhill Programming 6 01-16-2011 05:14 AM
[SOLVED] Small matlab code to convert Morse code to plaintext using regular expressions gregorian Programming 3 03-31-2010 12:34 PM
match text over multiple lines Python donnied Programming 5 05-24-2009 09:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration