Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
BIG successes of Lisp (was ...)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Brian Kelley, post: 1733358"] As people have pointed out, I am abusing the C-implementation quite roundly. That being said, I tend to write proxies/models (see FileSafeWrapper) that do the appropriate action on failure modes and don't leave it up the garbage collector. Refer to the "Do as I Do, not as I Say" line of reasoning. I don't consider proxies as "functional" solutions, but that might just be me. They are just another way of generating something other than the default behavior. Python's lambda is fairly awkward to start with, it is also slower than writing a new function. I fully admit that I have often wanted lambda to be able to look up variables in the calling frame. foo = lambda x: object.insert(x) object = OracleDatabase() foo(x) object = MySqlDatabase() foo(x) But in practice I never write lambda's this way. I always bind them to a namespace (in this case a class). class bar: def some_fun(x): foo = lambda self=self, x: self.object.insert(x) foo(x) Now I could use foo on another object as well. foo(object, x) I can explain what I meant with an example: suppose you wanted to tell the user what file failed to open/write and specify a new file to open. You will have to write a handler for this and supply it to (with-open-file ...) or catch the error some other way. Apologies, I meant to say that writing a macro to handle particular exceptions in a default-application wide way is a good thing and appropriate. Right. I'm was only trying to point out, rather lamely I might add, that the macros I have been seeing I would solve in an object-oriented manner. This might simply be because python doesn't have macros. But I like the thought of "here is your fail-safe file object, use it however you like". It is hard for me to say which is 'better' though, I tend to use the language facilities available (and abuse them as pointedly stated), in fact it took me a while to realize that (with-open-file) was indeed a macro, it simply was "the way it was done(TM)" for a while. Certainly, new (and old) users can forget to use their file I/O in the appropriate macro as easily as forgetting to use try: finally: In python I use my FileSafeWrapper(...) that ensures that the file is properly closed on errors and the like. As I stated, this wasn't handed to me by default though like I remember as (with-file-open ...) was from my CHLS days. So let me ask a lisp question. When is it appropriate to use a macro and when is it appropriate to use a proxy or polymorphism? Perhaps understanding this would break my macro stale-mate. p.s. given some of the other posts, I am heartened by the civility of this particular thread. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
BIG successes of Lisp (was ...)
Top