| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Comments:
<0> Hmmm, I guess the wikipedia article is explaining multiple dispatch awfully then. Multiple Dispatch looks like polymorphism with overloading. So like in Java I could have handle(V1Type v, Scrollbar s); and handle(V2Type v, Scrollbar s); which would invoke different methods for scross bar based on type type of the first parameter. <1> that's multiple dispatch <0> scroll bar even. <1> that's correct. <2> Yes <2> Wikipedia made it sound like function overloading <1> that's correct. <1> that's what multiple dispatch is. <2> Umm not entirely if you follow Erwin's example <1> java's implementation is a bit limited, but that's correct. <1> erlang, for example, has much more powerful multiple dispatch <0> Is it limited because you cannot discriminate on return values? <2> If I'd have to describe it, I'd call it conditional function overloading. Types not being the only parameter, but possibly values <1> Wavicle: no, you can't put constraints on <3> Jerub: I'm not counting exceptions, of course. <3> nor circular imports.
<1> like, erlang, you can do something like: foo(SomeNumber) when SomeNumber > 5 -> (do something). <0> Okay so you can say handle(int 1..10) { handle small numbers }; handle(int 10...) { handle big numbers } <0> That sort of thing? <0> that's "good" multiple dispatch? <1> Wavicle: that's a less limited multiple dispatch <1> ADA has multiple dispatch on return value too. <1> you can declare two functions, both with the same name, one returns an int, the other returns a string. <4> thanks for the help everyone, i think i'm done for today. things make more sense now tho <2> This type of thing should really be left to factory cl***es though IMHO <1> and the correct one will be called depending on how you're using the result. <5> _42: Are you familiar with the visitor pattern? It's unnecessary if you have multiple dispatch. <2> Jerub: You mean it will know the context of the return value in a dynamically typed language? <0> Does Python's multiple dispatch work on return values or parameter constraints? <1> _42: ADA is statically typed <2> I see <5> Err, how do you dispatch on return values? <0> Erwin: Call different methods based on desired return value. <2> Well in Python it'd be morally wrong to work off return values <5> Oh, yeah. Well, impossible without static typing. <0> You can use a decorator to specify the type of a return value in Python. <5> But names do not have types, object do. <5> So, foo = someMethod() cannot determine what type we want returned and bound to foo <1> Erwin: impossible you say? <1> fie! fie on thee <1> Erwin: framehacks for the win! <5> Jerub: That will only work if you've already bound foo <5> Unless you want to add a decorator to declare type of local variables :) <1> see! not impossible <5> I wish I had time and determine to continue my statical type checking system for Python though. <6> is there a way to do a "tee" in python <5> It might be even easier with the new AST stuff. I had it as far as being able to tell you that x = 42; print x.lower() was not going to happen :) <6> i want to tee stuff <5> Python is not a shell <6> i know <2> What is AST <6> but maybe i can write a stream Erwin ? <5> Yes, they have "write" methods, as it happens <6> Erwin, r0x <7> Abstract Syntax Tree <6> so i can just p*** inan object for the fd? <6> wtf <8> is there a way to have line history in the python shell? <8> (saved between sessions, I mean) <6> Erwin, tell me what to pydoc <9> Yango: ipython saves history <3> Yango: yes, the readline module can do it for you. <6> can't i do cl*** tee(SomeThing): <3> pundai|work: depends on SomeThing. <6> Yhg1s, yes... <8> Yhg1s making a script that's executed upon exiting the shell and upon startup? is there a PYTHONEXIT env var? <3> Yango: yes, and no, but you can use atexit. <10> there's a readline option <8> deltab I have readline enabled, but that doesn't save history between python shell sessions <3> Yango: readline.read_history_file(); atexit.register(readline.write_history_file) <8> yhg1s: thanks, i had only the first half solved by this time :) <5> Hmm, last time I set this up I managed to get python to *append* to the history file <5> When I later wondered why it suddenly took several seconds to start up, I discovered an 18M history file <0> pundai: I'm lost, isn't "tee" a unix program for forking output to stdout and a file? What are you trying to do? <11> can someone tell me how to solve this?
<11> exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xa7 in position <11> 6: ordinal not in range(128) <11> i have no idea why it thinks it's unicode <8> thanks for the hint, erwin :) <12> interesting.. <12> so, the builtin dict.update() byp***es __setitem__()? <10> inhahe: it's not; it knows it isn't ASCII but can't figure out what it means <12> rather, if i override __setitem__() in a dict subcl***, <12> does dict.update() use the base __setitem__() or my over-ridden one? <11> i wish it could be simple and not worry about what it means :P i didn't have this error before and i don't know what i did to change it.. deltab do you know how i can fix it? <6> can anyone tell me how to create my own stream so i can use it like tee <10> inhahe: you're doing some that requires unicode, but only providing bytes. Python has to get unicode from the bytes before it can continue <10> ^doing something that requires unicode <11> i have no idea why it requires unicode <10> maybe we do <6> damnit <6> does no one need tee <10> or would if we saw your code <13> pundai|work: maybe create a cl*** that has a write() and read() method and then override sys.stdout <6> i can do cl*** f(sys.stdout)? <13> and in read, write you could call the old sys.stdout <12> does dict.update() use __setitem__()? <10> pundai|work: read one file, write to two <6> i did not know this <6> isnt sys.stdout an object not a cl*** <10> yes <13> you create your cl***, then use an instance of it to override sys.stdout <6> ok i dont get it <6> http://rafb.net/paste/results/LkDgKG15.html ?? <0> sys.stdout = TeeWriter(stdout,myfile) <6> what is TeeWriter <13> the cl*** you created <0> cl*** TeeWriter(): def __init__(self,out1,out2): <0> (etc.) <13> that will take the place of sys.stdout <6> and all this cl*** has to do is have write()? <13> read might be a good idea too <10> inhahe: so, what are you doing? <13> even if read does nothing <0> pundai|work: Maybe. What you really want is to make sure "print" still works. Try it. <8> how can I 'touch' a file in python? <14> Yango: Open the file for appending then close it <6> maybe can someone just give mee a full example <6> cuz im lost <8> cerulean: Was just trying that, but IOError, file does not exist <8> f = open(hist_file,'a') <8> ;f.write('') <8> ;f.close() <14> Yango: That's funny - works here <0> try: (...) except IOError: f = open(hist_file,'w'); f.close() # create the file if it don't exist <14> file("foo", "a") should create foo if it doesn't exist <14> it does here, at least. <0> *shrug* I was just taking a wild guess. <10> Yango: what do you mean by 'touch'? update timestamp? create file? <8> create file, but hist_file had a typo *blush* <14> That will update the timestamp, mind. If you just want to create the file, check if it exists (try opening it for reading and catching the exception), and creating the new file otherwise <8> just did that, cerulean, thanks. what did cerulean studios write? <14> they wrote Trillian. <13> pundai|work: how's this ? http://rafb.net/paste/results/yIEgFr95.html <10> One stream enters, two streams leave! <6> Eblis, thanks, i'll try that asap <15> how do yu override the = operator <16> GOOD SHABBOS!!! <5> This is great -- kids making drawings and writing about scientists before and after they've met them -- http://www-ed.fnal.gov/projects/scientists/index1.html <17> how do you change a C/ C++ call to Python? <17> like: <17> CRYPT_CONTEXT cryptContext; <17> cryptCreateContext( &cryptContext, cryptUser, CRYPT_ALGO_RSA ); <17> /* Load key, perform en/decryption */ <17> cryptDestroyContext( cryptContext ); <17> in VB, cryptContext is a long integer <5> If you have a library written in C that you want to interface to from python you can use pyrex, swig, ctypes or even write the wrapping C code by hand <17> there's already a Python wrapper, I'm just not sure how to use it
Return to
#python or Go to some related
logs:
#perl ntpv compiling
dell m50 xorg.conf doctormo +site:quotesdb.info kind of proccesor for linux suse gentoo madwifi ioctl[ieee80211_ioctl_setmlme] ubuntu automount usbdisk hairydairymaid problems xine MDF format #math
|
|