|
tef posted:MY CONSISTENCY This, but unironically. tef posted:python eschews anonymous definitions -- ask yourself how you would do this in a language without braces. I can't answer that question other than by noting that it can be interpreted as an argument in favour of braces.
|
# ? Aug 9, 2011 14:04 |
|
|
# ? May 18, 2024 05:47 |
|
tef posted:MY CONSISTENCY Except lambdas!
|
# ? Aug 9, 2011 17:09 |
|
TasteMyHouse posted:Except lambdas! almost! they're not statements just expressions (unlike def, class, etc)
|
# ? Aug 9, 2011 17:16 |
|
Hammerite posted:This, but unironically. please go and learn a lisp variant. that is what you deserve.
|
# ? Aug 9, 2011 17:20 |
|
Is there any reason in windows that a window would get a WM_QUIT message everytime it starts up? It's the very first thing that happens in the message loop. Is it possible I have not set up the window correctly? edit: in c++ using the windows api.
|
# ? Aug 9, 2011 17:26 |
|
Hammerite posted:This, but unironically.
|
# ? Aug 9, 2011 17:37 |
|
tef posted:MY CONSISTENCY
|
# ? Aug 9, 2011 18:28 |
|
python's lovely lambda really isn't much of a problem because if your function needs to be more than just an expression it's probably worth giving it a name anyway
|
# ? Aug 9, 2011 19:04 |
|
When I was learning SML, I drove my TAs crazy by always writingcode:
code:
|
# ? Aug 9, 2011 19:11 |
|
it would be nice if python had a let/where statement, or some control over scoping imaginary syntax time: code:
|
# ? Aug 9, 2011 19:15 |
|
TasteMyHouse posted:A foolish consistency is the hobgoblin of little minds What this quote really says (to me, at least) is that if you have a good reason to be inconsistent then you should go ahead and be inconsistent. It seems to me that it's your job to show that there's good reason for inconsistency here. Or to put it another way, it's up to you to show that the consistency I am arguing for is indeed foolish.
|
# ? Aug 9, 2011 19:21 |
|
Hammerite posted:What this quote really says (to me, at least) is that if you have a good reason to be inconsistent then you should go ahead and be inconsistent. It seems to me that it's your job to show that there's good reason for inconsistency here. Or to put it another way, it's up to you to show that the consistency I am arguing for is indeed foolish. See that bit above in my post The one where I pointed out that it doesn't fit with pythons syntax That would be the reason against your consistency. They would rather have whitespace indentation over anonymous definitions edit: and if you don't like it, fine, use another language. one that suits your taste again, if you crave syntactic consistency, learn lisp
|
# ? Aug 9, 2011 19:43 |
|
Hammerite posted:This seems to betray a failure to truly treat functions as ordinary values just like any other type of values. If they were really so, you should have to write Python has first-class functions but does not permit the definition of anonymous functions (except via the restricted keyword lambda). code:
code:
|
# ? Aug 9, 2011 20:08 |
|
tef posted:again, if you crave syntactic consistency, learn lisp Even here you have to be careful which lisp
|
# ? Aug 9, 2011 20:44 |
|
I'm not aware of any serious lisps that don't have sugar for declaring a function — given that it's lisp, that sugar might be a macro in the standard library, but the effect is the same: it's very rare to see lisp code that declares functions with lets and lambdas.
|
# ? Aug 9, 2011 21:37 |
FlyingDodo posted:Is there any reason in windows that a window would get a WM_QUIT message everytime it starts up? It's the very first thing that happens in the message loop. Is it possible I have not set up the window correctly? My best guess: Your window procedure calls PostQuitMessage() in its WM_DESTROY handler, and your WM_CREATE handling is incorrect such that Windows assumes creation failed and immediately calls WM_DESTROY, which causes the WM_QUIT to be posted.
|
|
# ? Aug 9, 2011 21:59 |
|
Perhaps I shall learn Lisp. It sounds enlightening.
|
# ? Aug 9, 2011 22:01 |
|
even if you never actually use it everyone should learn a lisp
|
# ? Aug 9, 2011 22:37 |
|
Plorkyeran posted:even if you never actually use it everyone should learn a lisp The more flamboyant the better.
|
# ? Aug 9, 2011 23:25 |
|
Hammerite posted:Perhaps I shall learn Lisp. It sounds enlightening. I haven't finished Barski's book (land of lisp) but it's real fun, if a little triumphalist. i would recommend it if you actually want to do this
|
# ? Aug 10, 2011 03:58 |
|
To quote paul graham when talking about lisp: http://www.paulgraham.com/hijack.html 'The defense that does work is to keep code and data in separate places. Then there is no way to compromise code by playing tricks with data. Garbage-collected languages like Perl and Lisp do this, and as a result are immune from buffer overflow attacks. you see, lisp isn't about code as data, code and data are seperate
|
# ? Aug 10, 2011 06:10 |
|
I'm looking for a program that could provide metrics on my code (line of codes, nb of function, cyclomatic and stuff) what would be the best solution ? Bonus point if it is a free one
|
# ? Aug 10, 2011 11:36 |
|
I need to create a daily email to send to my group at work including several news articles that are published daily. The goal is for my email to be nearly completely automated. I'm not really sure how to approach the problem (I've had a few ideas but no immediate solutions have occurred to me) because of my limited programming experience in Office with VBA. CME publishes daily Market Report Recaps that I would like to incorporate automatically into the email. The same 6-7 recaps will be sent each day. Method 1: Each market report recap has a specific link on the CME webpage (ex: http://www.cmegroup.com/education/market-commentary/energy/2011/08/recap-energy_279.html). I am unsure of how you would write a macro to import the paragraph automatically, especially when the weblink would be changing daily, for each product, in a way that I'm not even sure of (i see the month and year timestamp, but im not sure of the pattern, or if there is a pattern, on the "_279". Method 2: This is less ideal. CME publishes RSS feeds of the market reports. You can subscribe to certain feeds and it may be possible to bring all the feeds together and publish them to a single email. The problems are that the RSS feed doesn't include the entire market report, only a few words and then a link to the full report, (although in Outlook I can download the HTML attachment) and I have to filter out a lot of reports that I'm not interested in to get to the 'market recaps' for my interest products. Realistically my programming skills are extremely limited. If any of these options seem plausible to the more experienced I would really appreciate a little bit of help. If there is another solution that would be much easier for me to create I would also really appreciate any advice on that avenue.
|
# ? Aug 10, 2011 13:25 |
|
To begin with, VBA is an odd choice unless you're 100% tied to Outlook without any other mail utilities and even then I'd try to parse the info in another language, dump to a file, and then use a simple VBA mailer probably.Effulgence posted:Method 1: You would need to find a DOM (or SAX) parser library and use it. If you can determine how they generate page URLS, you can use those directly. Otherwise, perhaps try to find a location on their site that has links that can be parsed. Generally, your second method is preferred. quote:Method 2: This is actually great, you just parse the XML RSS feed for the links and then use a DOM (or SAX) parser to extract your paragraphs. Filtering is super cheap in terms of run time. This will all be fairly difficult to work out if you've never done anything like it before but hopefully you have some keywords to search for now. baquerd fucked around with this message at 16:35 on Aug 10, 2011 |
# ? Aug 10, 2011 16:31 |
|
I'm looking for the best method to determine which section I am in on a rectangle or square to move towards the middle. I move pixel by pixel towards the middle and I can query my x,y location and the board's width/height. What I was thinking is splitting the board into eight sections and if I'm in sections 2,3,6,7 I move up or down and if I'm in 1,4,5,8 I move left or right until I get to center.
|
# ? Aug 14, 2011 01:54 |
|
calcio posted:I move pixel by pixel towards the middle and I can query my x,y location and the board's width/height. You need some information on your position relative to the rectangle. If all you know is your absolute position and the size of the rectangle, you don't even know whether you're inside its boundary.
|
# ? Aug 14, 2011 01:58 |
|
calcio posted:I'm looking for the best method to determine which section I am in on a rectangle or square to move towards the middle. You can actually figure out whether you need to move horizontally or vertically by comparing |x| and |y| (where x and y are relative to the middle of the square), and then check the sign to figure out which direction to move.
|
# ? Aug 14, 2011 01:59 |
|
ultrafilter posted:You need some information on your position relative to the rectangle. If all you know is your absolute position and the size of the rectangle, you don't even know whether you're inside its boundary.
|
# ? Aug 14, 2011 03:35 |
|
calcio posted:It's 0,0 top left and movement will wrap around. If the rectangle is height h and width w, the corners are at (0, 0), (w, 0), (0, h) and (w, h). You can view your problem as finding the point (x, y) that minimizes the sum of the squared distances from the corners, which works out to be 2(h^2 + w^2 - 2wx - 2hy + 2(x^2 + y^2)). What it sounds like you want to do is to use a coordinate descent algorithm with a small step size.
|
# ? Aug 14, 2011 04:03 |
|
These solutions all suck because you end up moving in a vertical or horizontal line and then diagonally.
|
# ? Aug 14, 2011 06:28 |
|
Here's one attempt at something cooler looking but afaict it ends up converging to (0,0) like a parabola that's attracted to the diagonal line. The code here assumes that you're targeting (0,0) and x and y are both non-negative, because like, whatever. code:
code:
The second version multiplies x by a prime number (mod x+y), which (except for one out of every 773 steps) is relatively prime to (x + y). This means instead of being a line drawing algorithm that goes a little curvy, it's more like something that picks decrementing x with probability x/(x+y). Edit: Pictures. (0, 0) is in the top left corner. Two pictures of the first version, from (30, 49) and (49, 49). And the version that uses 773, starting at (49, 49). shrughes fucked around with this message at 08:28 on Aug 14, 2011 |
# ? Aug 14, 2011 06:46 |
|
I'm having trouble thinking multithreaded. (language happens to be C# but I'm thinking this is mostly conceptual and not language oriented. If I should repost this in the .NET thread then lemme know) I'm talking to an embedded device running Linux via RS232. The serial port class I'm using maintains its own internal thread that fires a "Data Received" event every time it gets a burst of bytes. I have an event handler that actually retrieves the data from the serial port class, shoves it into a byte[], then grabs a thread from a thread pool and tells it to take care of actually handling the data in a Process() function. So far, so good. What I want is to be able to check each line as it comes in from the serial port to see if it matches a regex, and if it does then do something in response. The device is giving me data in unpredictably-lengthed bursts of bytes. If I'm regexing on a string that I construct from the previous step, I could miss matches that happen to be split across two different chunks coming down the wire. I can't just concatenate my strings until I see a newline and then check for matches because in the extremely common case of seeing the shell prompt, there will BE NO newline to check for. So what I've gotta do is split the strings on newlines, then check all those strings for matches, then throw all the strings except for the last one into my "processed" Queue, and hang on to the last string I get so I can concat it with the next string I get off the line before repeating that whole process. The problem here is that this means that I have to check for matches within my Process() function. I want to, in my main thread, just be able to say "WaitFor(some_regex);" and have the main thread block until there's a match. I don't know how to do that. Right now, my WaitFor() function is just spinning until it sees true on a volatile bool that my process sets when it sees a match. This works fine, except that it completely consumes one of my two processor cores. I WANT to have Process() lock on some some "match not yet found" object, and then release the lock when it finds the match, but Process() is running out of a thread pool each time it is called and there might be multiple calls before it finally sees a match. Then I thought I could have another thread lock on an object and then my process thread could tell it to unlock but then I realized I was a moron because then I would just have to have THAT thread spin. What I'm doing right now is just have the main thread sleep 50ms every iteration of its wait loop which seems to keep the cpu usage down but also feels really hacky. So uh basically I don't know what the hell I'm doing here. Is there any way for me to easily achieve this kind of communication between threads, i.e. have one thread sleep until a particular event? Or is there a superior way to design this program to obviate this need?
|
# ? Aug 17, 2011 16:21 |
|
I think the magic term you're looking for is "condition variable". In C#, this is apparently available as methods on Monitor.
|
# ? Aug 17, 2011 18:50 |
|
I believe this site has been previously recommended for all your .NET threading info needs.
|
# ? Aug 17, 2011 19:05 |
|
Mutex?
|
# ? Aug 17, 2011 19:58 |
|
rjmccall posted:I think the magic term you're looking for is "condition variable". In C#, this is apparently available as methods on Monitor. hmm.... I don't think Monitor can do I what I need it to do, but I will read what I can on "condition variables" in general to see if I can figure out how to apply the concepts myself Graviton v2 posted:Mutex? if you're talking about just the concept of mutexes, that's what I wanna do but I just don't know how to apply it, considering that the thread that's generating the condition is transient -- the function that will be finding the regex match is spawning over and over again from a thread pool so it can't just hold onto an object until it finds it. If you mean the .NET class Mutex then I'd need more explanation. Jethro posted:I believe this site has been previously recommended for all your .NET threading info needs. I will read through that, thanks.
|
# ? Aug 17, 2011 20:11 |
|
rjmccall posted:I think the magic term you're looking for is "condition variable". In C#, this is apparently available as methods on Monitor. In other languages/environments this can be called a semaphore.
|
# ? Aug 18, 2011 07:20 |
|
haveblue posted:In other languages/environments this can be called a semaphore. Semaphores are different (perhaps you're thinking of monitors, which are closely related and sometimes used synonymously?) The main distinction is that posting a semaphore will always increment it, and waiting it will block only if has a value <= 0; in contrast, signaling or broadcasting a CV is a no-op if no-one is waiting on it, and waiting will always block. That said, there's a lot of situations where semaphores and condition variables can be used pretty much interchangeably, although often one or the other will result in clearer code or greater efficiency. ToxicFrog fucked around with this message at 16:22 on Aug 18, 2011 |
# ? Aug 18, 2011 07:54 |
|
Is there any reason you have to block the main thread at all? If not you could have a callback method and use WaitFor(some_regex, someCallbackDelegate) to begin waiting for a result and someCallbackDelegate to handle that result when it comes in. The event handler for the SerialPort DataReceived would do all your checks and return a valid result through the callback when one was found. Alternately, if you are able to get away with not-yet-standard code you could check out the new Async CTP. It is made to do just this kind of thing with a cleaner code structure than callbacks provide. I believe the CTP is at a point now where you can use it in production code so long as it isn't for medical devices or other super-critical applications.
|
# ? Aug 18, 2011 14:38 |
|
|
# ? May 18, 2024 05:47 |
|
PDP-1 posted:Is there any reason you have to block the main thread at all? Well, maybe I just don't know what I'm doing with multithreading, but what I want is for the main thread to pause execution until a condition is true, and it seemed the ways to do that are either spinning, blocking, or some combination. I really just want the main thread to completely halt and consume no resources until the condition is true, however it can be accomplished. quote:If not you could have a callback method and use WaitFor(some_regex, someCallbackDelegate) to begin waiting for a result and someCallbackDelegate to handle that result when it comes in. The event handler for the SerialPort DataReceived would do all your checks and return a valid result through the callback when one was found. I don't quite get what you're saying here. The main thread is calling WaitFor(). How is it waiting for a result? How does it get notified? quote:Alternately, if you are able to get away with not-yet-standard code you could check out the new Async CTP. It is made to do just this kind of thing with a cleaner code structure than callbacks provide. I believe the CTP is at a point now where you can use it in production code so long as it isn't for medical devices or other super-critical applications. hm. I doubt this would work because of the execution environment: an absurd internal tool written in VB.net whose source I have no access to that executes C# scripts via reflection. I've been using ILMerge to patch assemblies into the executable so that the scripting engine will be aware of them... maybe I could do that with this, I'll check it out. TasteMyHouse fucked around with this message at 15:07 on Aug 18, 2011 |
# ? Aug 18, 2011 15:04 |