--- Log opened Tue Oct 05 00:00:05 2010 |
00:01 | | Kazriko [kaz@Nightstar-e09690fa.client.bresnan.net] has joined #code |
00:01 | | mode/#code [+o Kazriko] by Reiver |
00:01 | | Derakon [Derakon@Nightstar-1ffd02e6.ucsf.edu] has quit [[NS] Quit: Leaving] |
00:04 | | You're now known as TheWatcher[T-2] |
00:09 | | You're now known as TheWatcher[zZzZ] |
00:14 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
00:22 | | McMartin [mcmartin@Nightstar-3c18b210.pltn13.sbcglobal.net] has joined #code |
00:22 | | mode/#code [+o McMartin] by Reiver |
00:54 | | Rhamphoryncus [rhamph@Nightstar-473f8685.abhsia.telus.net] has joined #code |
01:08 | <@Vornicus> | Kaura! |
02:01 | | gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has quit [[NS] Quit: Z?] |
02:16 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Client closed the connection] |
02:21 | | * Vornicus gnaws kaura. |
02:22 | < kaura> | Gaah! |
02:22 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
02:22 | < kaura> | 'allo Vorn |
02:27 | <@Vornicus> | allo! |
02:30 | <@Vornicus> | Today we shall do a Crazy Thing! |
02:32 | < kaura> | Right, pulling out the padded cells. |
02:32 | < celticminstrel> | Noooo! Not the padded cells! |
02:36 | <@Vornicus> | But first, let's see your current code in full |
02:37 | < kaura> | http://pastebin.starforge.co.uk/405 Here it be |
02:39 | <@Vornicus> | All right then. Okay, so tonight's crazy thing is to make it so searching works even when you put the wrong case. |
02:41 | <@Vornicus> | And also so that other things remember the original case as well. |
02:42 | <@Vornicus> | So we can go "top swamp" and it works as well as "top Swamp" |
02:43 | < kaura> | So... something to set all input into the right case, then? |
02:43 | < kaura> | Or make all case equivalent? |
02:44 | <@Vornicus> | Eventually - what we have to do is make a dictionary from the "all lower case" version of a card to its not-all-lower-case version. |
02:46 | | Stalker [Z@26ECB6.A4B64C.298B52.D80DA0] has quit [Ping timeout: 121 seconds] |
02:46 | <@Vornicus> | Which we will do during __init__, and also if we have to, maintain it during top and bottom. |
02:47 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Client closed the connection] |
02:48 | | Derakon[AFK] is now known as Derakon |
02:48 | <@Vornicus> | So start, I guess, by defining a dictionary within self, call it "case_map" or something like that. |
02:48 | <@Vornicus> | (should start empty) |
02:49 | < kaura> | So case_map = {} within __init__(self, deckfile)" |
02:49 | <@Derakon> | Not quite. |
02:49 | <@Derakon> | self.case_map |
02:50 | < kaura> | Ooh, right. That's how to define within self. |
02:50 | <@Vornicus> | Yeah, you have to keep it inside self, or it'll get lost when you're done with the function. |
02:53 | <@Vornicus> | So now: each time we see a new kind of card, we have to add it to the dictionary -- its key should be the lower-case version, and the value should be the normal-case version. |
02:55 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
02:55 | <@Vornicus> | (we... did go over how to add stuff to a dictionary, right?) |
02:56 | < kaura> | It should be similar to how we add stuff to the deck, right? |
02:56 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Client closed the connection] |
02:57 | <@Vornicus> | not really - with a /list/, you have to tell it to add more stuff using a method like insert or append, because if you give it an out-of-range index, it whines. |
02:57 | <@Vornicus> | With a dictionary, you can assign straight to an index/key that doesn't yet exist, and it will happily create that key. |
02:57 | < kaura> | Ah, in that case, we didn't go over how to add stuff to the deck. |
02:58 | < celticminstrel> | What's the disadvantage of auto_ptr again? |
02:58 | < celticminstrel> | Was it just that it can't be used in containers? |
02:58 | <@Vornicus> | To a dictionary, that is? Well, it's pretty simple: my_dict[key] = value |
03:00 | < kaura> | er, dictionary, right. |
03:00 | <@Vornicus> | (you can also use things that look like this to change entries in either a dictionary or list.) |
03:01 | < kaura> | So it would be case_map[entry] = Entry? |
03:02 | | * kaura ponders |
03:02 | <@Vornicus> | you have to make sure that the key has been made lowercase first. |
03:02 | < kaura> | From the .txt file, right? |
03:02 | <@Vornicus> | You can't just make up a name, you have to tell it what to do, it doesn't know what case even means, outside that case function. |
03:03 | < celticminstrel> | Never mind, switching to shared_ptr after all. |
03:06 | < kaura> | Hrn. Am I on the right track here? http://pastebin.starforge.co.uk/406 |
03:10 | <@Vornicus> | you need to define the case_map before the loop; adding stuff to the case_map though is "in the right place" once you move the other line. |
03:11 | <@Vornicus> | (the code as written will give you an indentation error because it sees the case_map definition as ending the loop, and there's no block started on that line.) |
03:11 | < kaura> | Ahh. |
03:12 | < celticminstrel> | ...there's no way to get a FILE* from an istream, is there? |
03:12 | < celticminstrel> | An arbitrary istream. |
03:12 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
03:13 | <@Vornicus> | an arbitrary one? No, as you can define istreams without files in them. |
03:13 | < celticminstrel> | Point. |
03:13 | | Orthia [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Client closed the connection] |
03:13 | < celticminstrel> | Oh, I thought of another way. |
03:14 | < kaura> | So self.case_map = {} before the loop, and case_map[card.lowercase()] = card in the loop after card's been defined. |
03:14 | <@Vornicus> | Right |
03:14 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code |
03:15 | < kaura> | (but outside of the inner loop, obviously) |
03:15 | <@Vornicus> | (indeed.) |
03:17 | <@Vornicus> | Okay, so that's step 1. Now, here's the second bit: when we add a card to the deck, we add the lowercased name instead of the regular one. |
03:18 | <@Vornicus> | (since we're using the lowercased name in two places, we should create it only once.) |
03:18 | <@Vornicus> | (because otherwise we're duplicating work.) |
03:19 | < kaura> | Hah, was wondering why I was getting error messages. lower(), not lowercase() |
03:19 | <@Vornicus> | Heh, I was wondering there, it didn't sound like the right name. |
03:19 | < celticminstrel> | ...I'm going to have to write my own shared_ptr. :( |
03:21 | < kaura> | Alright. So, second bit, you want me to make the cards in self.cards lowercase too, right? So, in the inner loop, "self.cards.append(card.lower())"? |
03:21 | | 963AAAOYA [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
03:21 | | 963AAAOYA [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Connection reset by peer] |
03:22 | <@Vornicus> | Except that we only want to do card.lower() once. |
03:22 | <@Vornicus> | (for each different card) |
03:23 | < kaura> | ...hrn. Oh, change the definition of card to output lowercase? |
03:24 | < celticminstrel> | Is "reference linking" any better than "reference counting"? |
03:24 | < celticminstrel> | It sounds more complicated. |
03:25 | <@Vornicus> | Nope. |
03:25 | <@Vornicus> | YOu still want the original card as well -- but you also want a lowercase version of card. |
03:25 | < celticminstrel> | Was that no to me or Kaura? |
03:25 | <@Vornicus> | kaura. |
03:26 | < kaura> | ...hrn. |
03:27 | | * Vornicus has no idea what reference linking is, and hasn't really been paying attention, because it's C++ and he hasn't used C++ in a while. |
03:27 | < celticminstrel> | I'll go for the ref-counting then. |
03:28 | < kaura> | ...would it be to append the dictionary to the empty deck? That'd get you only one case of card.lower(). |
03:28 | <@Vornicus> | No. |
03:29 | <@Vornicus> | How do you create and hang on to a lowercase version of card? |
03:29 | <@ToxicFrog> | celticminstrel: reference linking is used by smart_ptrs and is similar to refcounting, except rather than maintaining a count, a linked list of references is kept. |
03:30 | | Ortiha [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
03:31 | <@Vornicus> | (you know how to do both, this should be pretty obvious) |
03:31 | | Ortiha [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Connection reset by peer] |
03:33 | < kaura> | Well, my first thought is to separately define the lowercase version of a card. But wasn't that now done with the self.case_map dictionary? |
03:33 | <@Vornicus> | We "did" it, but we kind of used it immediately and didn't really hang on to it. |
03:33 | <@Vornicus> | In order to get that back we'd have to futz with the dictionary, which is more trouble than it's worth to just hang on to one string. |
03:34 | < celticminstrel> | ToxicFrog: But is it better? |
03:36 | < kaura> | So... set a separate definition outside of the dictionary definition, and have both the dictionary and the deck draw from it? |
03:36 | <@Vornicus> | Yes. |
03:37 | | Ortiha [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has joined #code |
03:38 | < kaura> | So before the dictionary definer, card_lc = entry[1].lower() |
03:38 | <@Vornicus> | well, since we already pulled out card as entry[1]... |
03:38 | | Ortiha [orthianz@Nightstar-cfa0d65c.xnet.co.nz] has quit [Client closed the connection] |
03:39 | < kaura> | I thought that would work too. Just wanted to make sure I don't trip over anything. |
03:41 | | Orthia [orthianz@Nightstar-e421f981.xnet.co.nz] has joined #code |
03:45 | <@Vornicus> | Anyway, once you've got that, we'll go on to the things where you receive cards: draw, soft_draw, examine, and peek. |
03:48 | < kaura> | Like so? http://pastebin.starforge.co.uk/407 |
03:48 | <@Vornicus> | Now, you'll notice that in each of these, you're now getting cards in lowercase. |
03:48 | <@Vornicus> | Precisely. |
03:51 | <@Vornicus> | So in draw, and soft_draw, and examine, and peek, we will now need to make sure that we go back to the case_map and look each thing up. |
03:52 | <@Vornicus> | This is really easy in peek, pretty easy in draw and soft_draw, but examine's going to take a bit more wrapping. |
03:57 | <@Vornicus> | So I'm just gonna let you go at peek and draw and soft_draw. |
03:59 | <@Vornicus> | and then when you think you've got those, we'll look at examine together. |
04:01 | | * kaura tilts his head. Right now, peek looks at the top of the deck. What we want... is for it to compare the top card with the dictionary, right? |
04:01 | | Orthia [orthianz@Nightstar-e421f981.xnet.co.nz] has quit [Client closed the connection] |
04:02 | <@Vornicus> | To look up the top card in case_map, yeah |
04:04 | < kaura> | So just replace self.cards with self.case_map? |
04:04 | < kaura> | But I thought that the randomized deck's going to have a different order than the dictionary? |
04:04 | <@Vornicus> | The dictionary isn't in any order. |
04:05 | <@Vornicus> | Take what you get from self.cards and look it up in the case map. |
04:06 | < kaura> | Oh, it was a misread. I read "to look at the top card in case_map," which confused me a bit~ |
04:06 | < kaura> | Sorry about that. |
04:08 | < kaura> | This look about right for peek? http://pastebin.starforge.co.uk/408 |
04:08 | <@Vornicus> | No. |
04:08 | < kaura> | Hrn. |
04:08 | <@Vornicus> | Just look up the value - you don't have to loop to look up. |
04:08 | | Zed [Zed@Nightstar-556ea8b5.or.comcast.net] has joined #code |
04:09 | <@Vornicus> | (indeed, in the original peek you do a lookup) |
04:09 | | Orthia [orthianz@Nightstar-e421f981.xnet.co.nz] has joined #code |
04:11 | <@ToxicFrog> | celticminstrel: no idea, I just use mark and sweep for everything. |
04:11 | | Zed [Zed@Nightstar-556ea8b5.or.comcast.net] has quit [[NS] Quit: Leaving] |
04:12 | < kaura> | Well, the original peek looked up the original deck via its index value. To plug in a check against the dictionary, I'd have to... |
04:14 | <@Vornicus> | ask the dictionary "what do you have for this?" |
04:14 | <@Vornicus> | How do you do that. |
04:16 | < kaura> | ...hrn. self.case_map(self.cards[-1])? |
04:18 | < kaura> | Nope, definitely not. |
04:19 | <@Vornicus> | not () |
04:19 | <@Vornicus> | (but close) |
04:19 | < kaura> | Oh, right, since it references a dictionary, it ought to be {}, right? |
04:19 | < kaura> | Wait, no. []. {} is if you're setting a dictionary directly. |
04:19 | < kaura> | ...works! |
04:19 | <@Vornicus> | [] |
04:20 | <@Vornicus> | There you go. |
04:20 | <@Vornicus> | Now, on to draw and soft_draw, which are very similar to each other. |
04:20 | < kaura> | Now for the two others before examine. |
04:23 | < kaura> | Like so? http://pastebin.starforge.co.uk/409 |
04:23 | <@Vornicus> | Just so. |
04:26 | <@Vornicus> | All right, and now finally on to examine. |
04:28 | <@Vornicus> | Examine's kind of tricky because you want it sorted, but you also want to re-capitalize stuff. |
04:29 | < kaura> | Hrm. Have it sort first, checking against the dictionary, then return as self.cards? |
04:30 | <@Vornicus> | What we're going to want to do is make another list comprehension. |
04:30 | <@Vornicus> | Except this time, instead of iterating over a range, we want to iterate over sorted(self.cards) |
04:32 | < kaura> | Hrn... |
04:35 | <@Vornicus> | Remember: when doing list comprehensions, that thing between "for" and "in" is the thing we've pulled from the starting sequence |
04:40 | <@Vornicus> | Still stick? |
04:41 | < kaura> | A bit, yeah. |
04:41 | < kaura> | Ah, wait, lesse... |
04:47 | < kaura> | Nope! Still doing it wrong. The list comprehension's supposed to start with sorted(self.cards), right? |
04:47 | <@Vornicus> | Nope, it should be the last thing in the comprehension. |
04:48 | <@Vornicus> | (the same way range(x) is in draw) |
04:50 | < kaura> | Whups. |
05:04 | <@Vornicus> | Still not sure. |
05:04 | <@Vornicus> | ? |
05:04 | < kaura> | Trying that list comprehension a dozen ways, but I think I'm getting the very first entry wrong... |
05:05 | <@Vornicus> | Show me one of your attempts |
05:05 | < kaura> | Here was the latest: "return [self.case_map[self.cards] for x in sorted(self.cards)]" |
05:06 | <@Vornicus> | Try "x" instead of "self.cards" inside the [] |
05:06 | < kaura> | ...sorted(x)? Ahhh. |
05:06 | <@Vornicus> | that x takes the value of each ting in sorted(self.cards) in turn |
05:06 | <@Vornicus> | No, no there, the other place. |
05:07 | < kaura> | Oh, whups. |
05:08 | < kaura> | Ah, there we go. Alright, I see where I did wrong by reading it. I'm not sure how this made it so that all the cards were properly capitalized, though. |
05:08 | <@Vornicus> | [what am I doing for with what in from where] |
05:09 | <@Vornicus> | What it's doing is: it goes through the sorted list of cards and processes each one by looking it up and getting its appropriate case. |
05:10 | < kaura> | Oh, I see. The first part isn't the output - it's the action done with the input. The output's whatever it is you've done in the order that you've done it. So it takes the sorted output, then checks it. |
05:10 | <@Vornicus> | sorta, yeah |
05:11 | <@Vornicus> | Anyway, that's examine taken care of. |
05:12 | <@Vornicus> | Okay, now let's do this in the other direction: top and bottom put stuff into self.cards. |
05:12 | <@Vornicus> | (and search will be last) |
05:13 | <@Vornicus> | Now the thing about top and bottom is this: if we add a card that wasn't in the original list, we still want it to work -- while M:tG doesn't do it, other games may! |
05:14 | < kaura> | Nah, M:TG does that. The Wish cycle of cards takes stuff from outside of the game and puts it into your deck, hand, etc. Officially, it's from your sideboard, but people used to handtruck in their entire collections~ |
05:15 | <@Vornicus> | Ah so! |
05:15 | < kaura> | So for top/bottom, the appended card has to also be added to the dictionary as well as deck? |
05:15 | <@Vornicus> | If it doesn't already exist in the dictionary |
05:16 | < kaura> | Ah, so an "if" condition to check first. |
05:16 | <@Vornicus> | We want my_deck.top("swamp") to not change case_map["swamp"] to "swamp" -- we want the case_map to say "Swamp" still. |
05:20 | <@Vornicus> | We've used the appropriate thing before -- somewhere where we needed to check whether something was (or more appropriately was not) in a dictionary. |
05:22 | < kaura> | Yeah, I'm looking through the code right now for reference. I recall an if condition, I think, that used what I'm looking for. |
05:23 | <@Vornicus> | Yep. Where else do you use a dictionary? |
05:23 | < kaura> | search. |
05:23 | <@Vornicus> | Search doesn't use a dictionary. |
05:23 | <@Vornicus> | (yet) |
05:23 | < kaura> | Oh, whoops. |
05:24 | < kaura> | command() |
05:24 | | celticminstrel [celticminst@Nightstar-f8b608eb.cable.rogers.com] has quit [[NS] Quit: And lo! The computer falls into a deep sleep, to awake again some other day!] |
05:25 | <@Vornicus> | All right, so what in there does this? |
05:25 | < kaura> | if function.lower() not in CMND_NAMES: function = "helpinfo" |
05:26 | <@Vornicus> | all right. So, now, we have to check to see if your fresh card is in the case map. |
05:26 | < kaura> | So I think, for this... "if card.lower() not in self.case_map: self.case_map append(card); deck.insert(0, card)" |
05:26 | <@Vornicus> | that's not how you add it to the case map. |
05:27 | < kaura> | Whups. |
05:27 | < kaura> | er, was it the missing period, or something else? |
05:27 | <@Vornicus> | How'd we add stuff to the case map earlier. |
05:27 | < kaura> | Oh, right! |
05:28 | < kaura> | "if card not in self.case_map: self.case_map[card.lower()]; deck.insert(0, card)" |
05:29 | <@Vornicus> | that still hasn't added anything. And note that we want to check if the lowercase version is in the map, and we also want to add the lowercase version to the cards. |
05:30 | <@Vornicus> | and what's deck? |
05:30 | < kaura> | ...hrn. |
05:31 | <@Vornicus> | oh. bottomwise didn't get appropriately updated last time. |
05:31 | < kaura> | Oh, forgot to- yeah, updating. |
05:35 | <@Vornicus> | (and again, since we're using the lowercase version a couple of times -- my version has three uses -- we'll want to only do it once.) |
05:42 | < kaura> | Argh. Stumped again. http://pastebin.starforge.co.uk/411 Here's what I've got so far. |
05:43 | <@Vornicus> | How do you add stuff to case_map? |
05:44 | <@Vornicus> | And you don't need to do that insert twice - just put it outside the if block. |
05:44 | | Orthia [orthianz@Nightstar-e421f981.xnet.co.nz] has quit [Client closed the connection] |
05:45 | | cpux is now known as shade_of_cpux |
05:46 | < kaura> | brb |
05:46 | <@Vornicus> | and why call it k? It can be lc_card or whatever you called it up in __init__ -- it's more meaningful that way. |
05:53 | < kaura> | Alright. Grabbed some bread and some juice. Think I only used "k" because I was losing track of the workflow at that point. Let's see.. |
05:54 | | Orthia [orthianz@Nightstar-e421f981.xnet.co.nz] has joined #code |
05:56 | <@Vornicus> | (and calling it that should make it more clear what you're actually doing, because it now parallels __init__ more directly) |
06:02 | < kaura> | Hrn... TypeError. I think I'm closer, but... http://pastebin.starforge.co.uk/412 |
06:05 | <@Vornicus> | add "self" back in to the signature |
06:06 | <@Vornicus> | And also, remember that we need to put the lowercase version into cards. |
06:07 | < kaura> | ...huh. Didn't notice that the signature was missing that. >_O Dammit. |
06:07 | < kaura> | So change the last line to (0, card.lower())? |
06:08 | <@Vornicus> | Didn't you already make the lowercase version? |
06:09 | < kaura> | Oh, hah. Right. |
06:09 | < kaura> | I need to stop making extra work for myself. |
06:09 | < kaura> | Right, that works. |
06:11 | <@Vornicus> | All right. Same thing for top. |
06:12 | < kaura> | Right, done. |
06:13 | <@Vornicus> | all right. Now we're on to search. |
06:14 | <@Vornicus> | Actually search isn't all that hard; the only real difficulty is that we also have to return the "right" version. |
06:19 | < kaura> | Hrn. Lemme see. For search, we need to have it look up a card in the deck, then compare it to the dictionary, then pull it out, right? |
06:21 | <@Vornicus> | Pretty much - note that the remove just works if it's there. |
06:23 | <@Vornicus> | And alos note that, still, cards only contains lowercase. |
06:28 | < kaura> | ...whoo, that's odd. It finds the card alright. Now it just needs to actually take it out of the deck~ Right, missing a line. |
06:28 | <@Vornicus> | the remove works fine for seeing whether the card is in there at all -- it also happens to remove, that's the point of the try/except block |
06:34 | <@Derakon> | ...are you using try/except with the expectation that the code will throw an exception? |
06:34 | < kaura> | Yep. Ah-hah. Figured out what I was doing wrong by examining the original code~ |
06:35 | <@Vornicus> | Der: yeah, remove throws an exception if it doesn't find it. |
06:35 | <@Derakon> | Ah. |
06:35 | <@Vornicus> | We then catch that exception because it's not that exceptional a condition in this case. |
06:35 | <@Derakon> | I would return None instead, personally. |
06:35 | <@Derakon> | And then check the return value. |
06:35 | <@Vornicus> | That's what we do instead. |
06:39 | < kaura> | ...weird. That shouldn't happen. "Card not found," yet the card count just went from 60 to 58 |
06:39 | < kaura> | Which means I'm making a mistaken on multiple levels that technically shouldn't overlap. |
06:41 | < kaura> | http://pastebin.starforge.co.uk/413 |
06:41 | <@Vornicus> | You don't need to check the case map to see if it's in there, for one thing. |
06:42 | <@Vornicus> | (because if it's in cards it'll also be in case map) |
06:42 | <@Vornicus> | But then you need to look it up /in/ the case map to get the correct case, /and return it/ |
06:42 | <@Vornicus> | and... 60 to 58, shouldn't happen with that code! |
06:43 | < kaura> | Yeah, it really shouldn't. There's nothing in the count code that'd trigger that, I think... |
06:43 | <@Vornicus> | Oh! |
06:43 | <@Vornicus> | user_search calls search twice. |
06:44 | <@Vornicus> | It shouldn't, but we're about to change it so it also returns the case-corrected name of the card. |
06:44 | <@Vornicus> | So we'll kill two birds with one stone over there. |
06:44 | < kaura> | Right, but how the heck is it drawing cards out if it can't find 'em? O_o |
06:45 | <@Vornicus> | It is finding them. |
06:45 | < kaura> | Ah. ...weird. |
06:45 | <@Vornicus> | But it's not /saying/ that it's found them. |
06:46 | <@Vornicus> | That's why we need to return the case-corrected name of the card -- because it needs to return something other than None for its success to register. |
06:46 | <@Vornicus> | (and functions that don't appear to return anything, return None) |
06:50 | | gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has joined #code |
06:52 | <@Vornicus> | See what I mean? |
06:54 | < kaura> | Apparently not. >_< Thought it was something like "self.case_map[self.cards.remove(card_lc)]" but this isn't quite right either. It's not triggering the right user_ result. |
06:55 | < kaura> | Well, wait. I see where that's wrong, just not how that might be rightened... |
06:56 | <@Vornicus> | Look at your original, if you still have it. |
06:57 | <@Vornicus> | (if not, it's here http://pastebin.starforge.co.uk/405 at line 29) |
06:58 | < kaura> | "self.cards.remove(self.case_map[card_lc])" is closer, huh? |
06:58 | <@Vornicus> | Nope. |
06:59 | | * kaura headdesks |
06:59 | <@Vornicus> | Remember: going through case_map gives you a case_corrected thing |
06:59 | <@Vornicus> | but cards has lower case only. |
07:00 | < kaura> | Oh, right. Putting case_map there'll give it a capitalized version, but what we need is all lower-case. |
07:07 | <@Vornicus> | Right. But we do need to return a case-corrected version, so your return at least will have the case mapping. |
07:08 | | Anno[Laptop] [annodomini@Nightstar-fac55151.adsl.tpnet.pl] has joined #code |
07:09 | <@Vornicus> | (my version of this code adds only one line, which happens to be a line that you already added.) |
07:09 | | Derakon is now known as Derakon[AFK] |
07:10 | < kaura> | Oh, duh. Lesse if this works. |
07:10 | < kaura> | ...still getting "card not found." |
07:10 | <@Vornicus> | Show me |
07:10 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [Ping timeout: 121 seconds] |
07:10 | < kaura> | http://pastebin.starforge.co.uk/415 |
07:11 | < kaura> | Actually, maybe that specific bit won't be fixed until we fix the user_ bit as well |
07:11 | <@Vornicus> | ok, line 4 doesn't do what you expect it to. |
07:11 | <@Vornicus> | (it in fact changes the case-mapping that we've stored.) |
07:11 | < kaura> | ... |
07:11 | < kaura> | Oh, right. |
07:11 | <@Vornicus> | instead, put that line after, and return the thing instead of assigning |
07:12 | < kaura> | ...so, wait. "try: self.cards.remove(card); return self.case_map[card_lc]"? |
07:13 | <@Vornicus> | Yep. |
07:13 | <@Vornicus> | er |
07:13 | <@Vornicus> | card_lc, not card, in the first of those. |
07:13 | < kaura> | A, whups. Typed by hand, missed it. |
07:14 | < kaura> | Alright, So... why? It takes first, then checks? |
07:14 | <@Vornicus> | What it does is -- the remove finds and removes a copy of the card from the deck. |
07:14 | <@Vornicus> | But if it can't find one, then it'll raise, we'll drop down to the except clause, and return None. |
07:15 | <@Vornicus> | On the other hand if it /does/ find one, it will return the case-corrected version of the card. |
07:15 | < kaura> | Ah. I was tripping over the order of operations. |
07:17 | < kaura> | And on the user_ side, just delete that first line and write it out as "card_lc = card.lower(); if my_deck.search(card_lc) is not None:" etc, right? |
07:17 | <@Vornicus> | Nope. found_card = my_deck.search(card) |
07:17 | <@Vornicus> | and then if found_card is not None... |
07:18 | <@Vornicus> | and then we should change the return for user_search to something that tells us the case-corrected version. |
07:18 | < kaura> | Ah... |
07:19 | <@Vornicus> | (which is in found_card) |
07:20 | < kaura> | So for a positive find, return found_card + " found and put in hand." |
07:20 | < kaura> | And, yes, it comes out as the case-corrected version. |
07:21 | <@Vornicus> | Yep. |
07:21 | <@Vornicus> | Oh, and |
07:21 | <@Vornicus> | We probably want search to shuffle. |
07:21 | <@Vornicus> | (just use self.shuffle() to shuffle; we don't have to tell it how twice.) |
07:22 | < kaura> | ...can it be shortcuted to self.shuffle()? Thought it was random.shuffle(self.cards) |
07:23 | <@Vornicus> | What's self.shuffle() do? |
07:25 | < kaura> | Was written as shuffle(self): random.shuffle(self.cards) in the class, I think. It works as self.shuffle() as well? |
07:25 | <@Vornicus> | It works like that, yeah. |
07:25 | < kaura> | Ahh, cool. I'll make a note of that. |
07:26 | <@Vornicus> | This way, if we need to change our shuffler out for something more awesome, we can dump it into /that/ shuffle and we don't have to change naything else! |
07:27 | <@Vornicus> | (while we're at it, change __init__ to call self.shuffle() too.) |
07:30 | < kaura> | Done. |
07:30 | <@Vornicus> | All right. Now we have a thing that case-corrects. |
07:32 | <@Vornicus> | This is pretty cool. /complete/ craziness would also make it match by substrings, but we're not going to do that, mostly because I hurt my brain trying to figure out how to make it work nicely. |
07:33 | < kaura> | Substrings? |
07:34 | <@Vornicus> | Like, uh. "science" would give us "Urza's Science Fair Project" |
07:35 | < kaura> | Ahh. |
07:35 | <@jerith> | You'd have to deal with ambiguity, then. |
07:35 | < kaura> | ...I have a vague idea of how that might work, but ow. How would you deal with overlaps? |
07:37 | <@Vornicus> | The real way is -- now that I think about it -- to use case_map's keys, lc your search string, see if it matches exactly one of them ("in" works to match, believe it or not: "science" in "urza's science fair project" returns True), and then search that! |
07:37 | < kaura> | Oh, wait. I guess for overlaps, it'd then call up a separate prompt to ask you if you meant variation a, b or c. |
07:38 | <@Vornicus> | I hurt ;_; |
07:38 | < kaura> | ...so do I. I think the codelength for that might be nearly equivalent to everything we've written so far. |
07:39 | <@Vornicus> | Actually, done right, it's quite short and elegant -- but good god there's a lot to deal with. |
07:40 | <@Vornicus> | I mean, hell: matching_cards = [card for card in self.case_map.keys() if search_string in card] |
07:44 | | kwsn is now known as kwsn\t-2 |
07:50 | | kwsn\t-2 [kwsn@31356A.5FD175.2259B6.DFACD4] has quit [[NS] Quit: and..................................................] |
08:20 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code |
08:35 | | Namegduf [namegduf@Nightstar-5c10d129.beshir.org] has quit [Ping timeout: 121 seconds] |
08:35 | | Namegduf [namegduf@Nightstar-5c10d129.beshir.org] has joined #code |
08:37 | | * gnolam blarghs. |
08:37 | < gnolam> | It shouldn't be this hard to model a plastic bag... |
08:38 | | * Vornicus thinks about that. ...I... don't actually know how you'd do that. |
08:41 | < Anno[Laptop]> | I expect it's pretty hard. You need to take into account that this thing alters its shape very easily when subjected to force. |
08:56 | < gnolam> | Oh, perfectly static is fine. I just need to model it in Sketchup. Wrapped around a B/G probe. |
08:57 | < gnolam> | (Otherwise, aside from the pesky self-intersection problem, you should be able to use any standard cloth simulation with some extra stiffness) |
09:01 | | Orthia [orthianz@Nightstar-e421f981.xnet.co.nz] has quit [Ping timeout: 121 seconds] |
09:15 | | KarmaBot [karma.bot@Nightstar-c8453cc1.80-203-16.nextgentel.com] has quit [Ping timeout: 121 seconds] |
09:19 | | KarmaBot [karma.bot@Nightstar-c8453cc1.80-203-16.nextgentel.com] has joined #code |
09:36 | | You're now known as TheWatcher |
10:01 | | Anno[Laptop] [annodomini@Nightstar-fac55151.adsl.tpnet.pl] has quit [[NS] Quit: leaving] |
10:28 | | kaura [kaura@Nightstar-fd82400d.snfc21.sbcglobal.net] has quit [Ping timeout: 121 seconds] |
10:34 | | kaura [kaura@Nightstar-fd82400d.snfc21.sbcglobal.net] has joined #code |
11:20 | | Orthia [orthianz@Nightstar-10e1ba7d.xnet.co.nz] has joined #code |
11:20 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Client closed the connection] |
11:59 | | Orthia [orthianz@Nightstar-10e1ba7d.xnet.co.nz] has quit [Ping timeout: 121 seconds] |
12:10 | | Orthia [orthianz@Nightstar-7d213778.xnet.co.nz] has joined #code |
12:16 | | Orthia [orthianz@Nightstar-7d213778.xnet.co.nz] has quit [Ping timeout: 121 seconds] |
12:17 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
12:33 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code |
13:18 | | Zed_ [Zed@Nightstar-556ea8b5.or.comcast.net] has quit [Ping timeout: 121 seconds] |
13:29 | | Anno[Laptop] [annodomini@Nightstar-fac55151.adsl.tpnet.pl] has joined #code |
13:44 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [Connection reset by peer] |
13:51 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
14:12 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [Connection reset by peer] |
14:12 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
14:12 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [Connection reset by peer] |
14:13 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
14:18 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [Client closed the connection] |
14:21 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Connection closed] |
14:25 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
14:37 | | kwsn [kwsn@31356A.5FD175.2259B6.DFACD4] has joined #code |
14:38 | | * Anno[Laptop] mumbles. How do I make applications launch themselves when I log in at Gnome? |
14:38 | < Anno[Laptop]> | This is Debian 5. |
14:38 | < Anno[Laptop]> | There are usually options for this in the applications themselves, but after I restored my settings for kAlarm and Pidgin, using those options fails. |
14:46 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [Connection reset by peer] |
14:54 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
14:56 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [Client closed the connection] |
14:59 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has joined #code |
15:01 | | Orthia [orthianz@Nightstar-9ac6cb1e.xnet.co.nz] has quit [[NS] Quit: Going dooooown...] |
15:16 | | kwsn is now known as kwsn\t-something |
15:35 | | kwsn\t-something [kwsn@31356A.5FD175.2259B6.DFACD4] has quit [[NS] Quit: and off to school] |
15:37 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code |
15:40 | | Rhamphoryncus [rhamph@Nightstar-473f8685.abhsia.telus.net] has quit [Client exited] |
16:40 | <@ToxicFrog> | Anno[Laptop]: gnome-session-properties |
16:40 | <@ToxicFrog> | It'll be listed in your preferences menu, if you have one, as either "session properties" or "startup applications". |
16:49 | < Anno[Laptop]> | Thanks. |
17:34 | | Anno[Laptop] is now known as ST |
17:34 | | ST is now known as Adorjan |
17:56 | | Zed_ [Zed@Nightstar-556ea8b5.or.comcast.net] has joined #code |
19:14 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Connection closed] |
20:33 | | Derakon [Derakon@Nightstar-1ffd02e6.ucsf.edu] has joined #code |
20:33 | | mode/#code [+o Derakon] by Reiver |
20:39 | | RichardBarrell [mycatverbs@Nightstar-3b2c2db2.bethere.co.uk] has joined #code |
20:55 | | Adorjan is now known as AnnoDomini |
21:26 | | kaura [kaura@Nightstar-fd82400d.snfc21.sbcglobal.net] has quit [Ping timeout: 121 seconds] |
21:31 | | kaura [kaura@Nightstar-fd82400d.snfc21.sbcglobal.net] has joined #code |
21:48 | | Rhamphoryncus [rhamph@Nightstar-473f8685.abhsia.telus.net] has joined #code |
21:58 | <@McMartin> | o_O |
21:58 | <@McMartin> | OK, here's a question for people who have done serious user-level POSIX stuff |
21:58 | <@McMartin> | Is there any reason changing locale from en_US to de_DE would produce bus errors where there were none before? |
22:01 | <@Derakon> | ... |
22:02 | <@McMartin> | Becuase my comp game entry crashes this one terp, but not when LANG=en_US. |
22:02 | <@Derakon> | Hypothesis: some program somewhere hasn't anticipated that locale strings would contain non-English characters. |
22:02 | <@McMartin> | Dude's default locale is de_DE, but when I run it on a hand-compiled copy in Fedora 12, no crash |
22:04 | < PinkFreud> | McMartin: that's also assuming the problem is entirely in software. faulty memory could produce a similar result. |
22:04 | <@Derakon> | Presumably not consistently. |
22:04 | <@McMartin> | This is reproducible through two levels of virtualization - it's executing a specific instruction inside a VM and regardless of when you issue the command, the fault happens. |
22:05 | < PinkFreud> | Derakon: depends on if the machine was rebooted or not. |
22:05 | < PinkFreud> | McMartin: interiguing |
22:05 | < PinkFreud> | er. |
22:05 | <@Derakon> | PF: more importantly, if he got a crash report from another user, and reproduced it on his own machine, then RAM is not likely to be an issue. |
22:05 | < PinkFreud> | intriguing. |
22:05 | < Alek> | hand-compiled works? perhaps the problem is in the compiler? |
22:05 | < PinkFreud> | Derakon: ahh, I thought he didn't reproduce it. Nevermind, misread. |
22:06 | < PinkFreud> | I'll crawl back into my corner now. |
22:06 | <@McMartin> | Alek: Well. "Distributed as a .deb running on a German Ubuntu system, reproducible. Hand compiled on an en_US Fedora system with half the options disabled, not reproducible." |
22:06 | < RichardBarrell> | I think that the name SIGBUS has been reused for things that aren't actually bus errors, these days (somewhat like now integer division by zero is the only way to generate SIGFPE on linux these days except for kill(2)). |
22:06 | < Alek> | hrm. |
22:06 | <@McMartin> | And it's something in the processing in a command in a text adventure running in a specific Z-Code VM. |
22:07 | <@McMartin> | RB: I'm guessing SIGBUS because he said "corresponds to NULL pointer", and I associate Bus error with NPE and Segfault with wild pointer. |
22:07 | <@McMartin> | He tried to run it in the en_US locale to get errors I could read outright, assuming I knew no German, and immediately failed to repro |
22:08 | < RichardBarrell> | I was under the impression that evaluating *(int*)NULL under Linux/x86 always caused SIGSEGV. |
22:08 | < Alek> | faulty localization code? |
22:08 | < RichardBarrell> | Someone on Stackoverflow points out that you can get SIGBUS on Linux by walking off the end of an mmap()ed file. |
22:09 | <@McMartin> | Alek: Possibly? Initially this was "your game is doing something screwy", which is no longer the case, but I would like people to, you know, be able to reliably play my game. |
22:09 | < Alek> | has it been tested in other localizations? |
22:09 | <@Derakon> | It's being tested in such right now~ |
22:09 | < Alek> | idly, what game? |
22:09 | <@Derakon> | (With "other localizations" being "de_DE") |
22:11 | <@McMartin> | Alek: Flight of the Hummingbird, my entry in this year's Interactive Fiction competition. |
22:11 | < Alek> | I did mean localizations other than English and Deutsch. |
22:11 | <@McMartin> | The terp in question ("Fizmo") appears to only support those. |
22:11 | < Alek> | McM: ahh. nice. |
22:11 | <@McMartin> | My entry has primarily been tested in WinFrotz and Zoom, the standard terps for Windows and Mac hosts. |
22:11 | < RichardBarrell> | You have an infocom file causes the Z-machine to crash when using de_DE? |
22:12 | < Alek> | ah. in that case, you can't test to see if it's something deutsch-specific failing, something us-specific making it work, or other. |
22:12 | < Alek> | well, not easily. |
22:12 | | * Alek shrugs. |
22:12 | <@McMartin> | RichardBarrell: No, I have a Z-Code version 8 (post-Infocom Z-extension) file I wrote myself that crashes a specific implementation of the Z-Machine to crash out-of-band. |
22:13 | < RichardBarrell> | Sorry, yes. When I said "the Z-machine" I mean *his* Z-machine. |
22:13 | <@McMartin> | As part of Z-Code execution. I don't think it's a problem at the Z level of virtualization because I've tried this on seven separate implementations (8-bit Frotz, 16-bit Frotz, Parchment, Flaxo, ZMPP, Zoom, and ZLR) and all work flawlessly |
22:13 | <@McMartin> | In fact, so does Fizmo when I run my own copy in en_US land |
22:13 | < Alek> | so yeah, I suspect a bug in the localization code of the terp. |
22:14 | <@McMartin> | Weirdly, it also works for me when I run my own copy in de_DE, so it might be a problem in termcap. o_O |
22:14 | < Alek> | ... |
22:14 | < RichardBarrell> | Out of curiosity, which Z-Machine is he using? |
22:14 | < Alek> | ok, might be a bug in his version. >_> |
22:14 | < Alek> | if there's different versions of these terps? |
22:15 | | * Alek doesn't know. |
22:15 | | Attilla [Some.Dude@Nightstar-6d27e276.threembb.co.uk] has joined #code |
22:15 | | mode/#code [+o Attilla] by Reiver |
22:15 | < RichardBarrell> | Or he might have built his own binaries with really screwy compiler flags. Apparently SIGBUS gets generated if you violate your CPU's alignment constraints - fussy SSE instruction being given an unaligned address or something mad like that? That's the craziest thing I can think of. |
22:16 | <@McMartin> | He's using the stock debian .deb. |
22:16 | <@McMartin> | I don't know what madness they've inflicted |
22:16 | <@McMartin> | Like I said, though. |
22:16 | < RichardBarrell> | They're usually pretty conservative. |
22:16 | <@McMartin> | This has moved from "oh no, my game doesn't work" to "hey, this bug looks pretty awesome and weird" |
22:22 | < RichardBarrell> | In your shoes, I wouldn't bother fixing it as a matter of principle, but it'd be worth fixing as a fun debugging challenge. |
22:23 | <@McMartin> | Well |
22:23 | <@McMartin> | The former would be because I want to support the Fizmo project |
22:23 | <@McMartin> | Which, as I've been looking into it, I think I do |
22:24 | <@McMartin> | In terms of integration with IF, it's much better than nfrotz because it chucks a lot of legacy crap |
22:24 | <@McMartin> | But it's also clearly not quite there yet in terms of stability; frotz is ages old and rock-solid |
22:24 | <@McMartin> | http://spellbreaker.org/~chrender/fizmo/ |
22:25 | < RichardBarrell> | What is it that the author dislikes about Z-Machine 6? |
22:25 | <@McMartin> | Everyone hates Z6. |
22:25 | <@McMartin> | It's basically a hacked-together fake standard that tries to unify all the random shit Infocom did throughout its entire corporate history to add graphics in different, mutually-incompatible ways to their stories on different platforms. |
22:25 | <@McMartin> | While still having all the various fatal flaws of Z generally. |
22:26 | <@McMartin> | Anyone seriously considering making new Z6 work now is going to get punted up and down the street with the Glulx standard (Z 32-bit, several well-specified multimedia systems it hooks to). |
22:26 | < RichardBarrell> | One would hope that nothing important was ever written in Z6, then. |
22:27 | <@McMartin> | Everything important written in "Z6" shipped with a terp that actually played it. |
22:27 | <@McMartin> | The only exception is in the post-Infocom era and there is exactly one I can think of there. |
22:27 | < RichardBarrell> | Ah! |
22:28 | <@McMartin> | The problem with *modern* Z6 is that "Z6", unlike Z3, Z4, and Z5, were not actual singular VM specs built by Infocom. |
22:28 | <@McMartin> | They're a backpatched multimedia layer onto a slightly modified Z5. |
22:28 | < RichardBarrell> | (Offtopic: the raop-play module is the first thing to have actually made me *like* pulseaudio, as opposed to simply thinking of it as one more point of failure between my programs and my speakers) |
22:28 | <@McMartin> | (That's quite an achievement. I've never heard of it. What does it do?) |
22:29 | <@McMartin> | Oh |
22:29 | <@McMartin> | I misunderstood your real question, incidentally. |
22:29 | <@McMartin> | Your question wasn't "why no love for version 6" |
22:29 | <@McMartin> | It was "why doesn't Fizmo support Version 6" |
22:30 | <@McMartin> | And that's because Version 6 is for semigraphical adventures, which a console terp is obviously not going to support. |
22:30 | < RichardBarrell> | No, you got it right the first time. I was curious as to why-no-Z6-love. |
22:31 | < RichardBarrell> | The no-graphics-either thing hadn't occurred to me. |
22:31 | <@McMartin> | The standard Windows and Mac terps can do V6, but I believe they insist that they be in the DOS or Amiga multimedia formats. I don't recall which. |
22:32 | <@McMartin> | I don't think either will play absolutely any copy of a "V6" game, only the ones pointing at "canonical" platforms. |
22:32 | <@McMartin> | It looks like Fizmo actually supports sound in the earlier Z formats, but I'm going to guess that it will insist on those sounds being packaged in the modern Blorb format. |
22:33 | <@McMartin> | (Which is an IFF variant designed for IF multimedia works) |
22:33 | < RichardBarrell> | I seem to remember you talking about writing some form of Blorb parser. |
22:34 | < RichardBarrell> | Didn't you write a GUI application for launching IF games, which extracted the title screens or something? |
22:34 | <@McMartin> | Yes |
22:35 | <@McMartin> | One of the reasons Fizmo is impressing me is because it builds this functionality into its ncurses interface. |
22:35 | < RichardBarrell> | That is nice. |
22:35 | <@McMartin> | Which is something I had planned to patch into nfrotz, but if he keeps refining his core, I will see no reason to do. |
22:36 | <@McMartin> | The "title screens" are a semi-recent (2-3 years old) extension to the Blorb standard to specify one of the graphical resources as "cover art" and adding an additional text resource that carries an XML "Library card" of sorts. |
22:38 | < RichardBarrell> | Cool. |
22:42 | <@McMartin> | Some of it is just that 2010 appears to be a Very Good Year, but damn near everyone had some decent cover art this year. |
22:43 | < gnolam> | Hah! The cps/(Gy/h) sensitivity /was/ in the datasheet after all! Eureka! |
22:43 | < RichardBarrell> | gnolam: Geiger-Muller counter? :D |
22:43 | < gnolam> | Yeah. |
22:44 | < RichardBarrell> | (I don't know what those units are, but "cps" sounds like CsomethingPerSecond so I guessed) |
22:44 | < gnolam> | Counts per second. |
22:44 | < gnolam> | (Which, BTW, should also be the time derivative of nobility) |
22:45 | < gnolam> | (Or vampirism) |
22:45 | < RichardBarrell> | Teehee. |
22:45 | < RichardBarrell> | Since a king outranks a count, does one king count as multiple counts? |
22:46 | < gnolam> | A king should be a couple of hectocounts, at the very least. |
22:52 | < gnolam> | Heh. These manuals are interesting, sometimes. |
22:52 | < gnolam> | "For Operation Under Normal Conditions refer to Chapter 2, Section I. |
22:52 | < gnolam> | For Operation Under Unusual Conditions refer to Chapter 2, Section II. |
22:53 | < RichardBarrell> | Those must *implode* under gzip. |
22:54 | < gnolam> | "NOTE: When a nuclear weapon has been detonated it may remain in the "blinking" state for up to 10 minutes while processing the total dose measurement." |
22:54 | <@Attilla> | I'm sure your burnt-on shadow will be appreciative of that advice! |
22:59 | < gnolam> | I wonder how they test that. |
23:00 | < gnolam> | Also: don't you have bigger concerns within 10 minutes of a nuclear weapons detonation close enough to spazz out your radiation hardened, EMP hardened pocket radiac? :) |
23:06 | | celticminstrel [celticminstre@Nightstar-f8b608eb.cable.rogers.com] has joined #code |
23:11 | < RichardBarrell> | Oh God I so want to be in on calibrating that. |
23:14 | < celticminstrel> | Whose bright idea was it to define gzFile as a pointer to void? 9_9 |
23:16 | < gnolam> | I'm not so sure I would be. |
23:16 | < gnolam> | "Here, hold this in one hand, this mechanical stopwatch in the other, face away from the blast and tell us when the display starts working again." |
23:19 | <@ToxicFrog> | celticminstrel: so that it's opaque and you can't crack it open and see what's inside and possibly break things. |
23:19 | < RichardBarrell> | And do NOT remove your goggles! |
23:19 | <@ToxicFrog> | That said, there's a much better way of doing this. |
23:20 | < RichardBarrell> | struct cheshire; struct myOpaqueClass { cheshire const* smile; }; |
23:20 | < celticminstrel> | But it's not particularly good for overload resolution. |
23:20 | <@ToxicFrog> | celticminstrel: I didn't say it was a good idea, just that the reason they did it isn't a bad one. |
23:20 | < RichardBarrell> | That pattern made me giggle like the Dickens when I first saw it in Bruce Eckel's C++ book. :) |
23:21 | < celticminstrel> | Yeah, what RB said would be much preferable. You could even just make a struct containing a void pointer, for goodness's sake. |
23:21 | < RichardBarrell> | Or actually my example was overkill. |
23:21 | < celticminstrel> | ...ohhh, that's opaque because it's a pointer to an incomplete type! |
23:21 | < RichardBarrell> | You just provide the opaque declaration "struct cheshire;" and don't give the definition at all. |
23:22 | <@ToxicFrog> | For example, you can do something like: struct Foo { uint8_t opaque_data[STRUCT_FOO_SIZE]; } |
23:22 | <@ToxicFrog> | And that way sizeof and whatnot will behave correctly while still not letting the end user get guts all over the table. |
23:23 | < RichardBarrell> | That's a good idea, except how do you keep STRUCT_FOO_SIZE exactly in-sync with the real sizeof(struct Foo)? |
23:24 | <@ToxicFrog> | Well, that's where the wheels come off, sadly~ |
23:24 | < RichardBarrell> | You shouldn't hardcode STRUCT_FOO_SIZE; your program might get moved to a CPU with tougher alignment restrictions than your current CPU, making your compiler need to add more padding. :( |
23:24 | <@ToxicFrog> | And sizeof requires struct Foo_private to be in scope |
23:25 | <@ToxicFrog> | Which I guess isn't so bad |
23:25 | <@ToxicFrog> | I mean, yeah, people can still cast it to Foo_private and abuse it, but if they really want to abuse the library they'll manage it somehow |
23:25 | < RichardBarrell> | I guess it wouldn't be *totally* immoral to introduce an extra build step in order to extract sizeof(struct Foo). |
23:25 | <@ToxicFrog> | This is just meant to avoid the sort of casual cross-version-compatibility breaking abuse that comes when people start adjusting the struct interior because it's easier than using the documented API. |
23:26 | < RichardBarrell> | In open-source code, I'd rather just leave struct Foo public and have the documentation tell people not to mess with it. |
23:26 | < RichardBarrell> | Or defining struct Foo { struct Foo_private x; }; if you want to really ram it down peoples' throats. |
23:28 | <@ToxicFrog> | Yeah, that's what SDL does |
23:28 | | AnnoDomini [annodomini@Nightstar-fac55151.adsl.tpnet.pl] has quit [[NS] Quit: leaving] |
23:29 | < RichardBarrell> | A guy I know has a more reliable trick; his buildout configs, source comments and deprecation warnings often bear threats of grievous bodily harm by application of thrown ignited badgers. |
23:29 | <@ToxicFrog> | Eg, struct Foo { /* public stuff */ int x; int y; /* don't touch this */ struct Foo_private_data private; } |
23:29 | <@ToxicFrog> | Yeah, see, that doesn't strike me as more reliable, because all you need to do to break things is ignore that warning |
23:29 | <@ToxicFrog> | Whereas with private stuff you need to actually work for it. |
23:30 | <@Derakon> | If someone feels inclined to ignore the public/private system, why should you stop them? |
23:30 | <@Derakon> | So long as they know that they're violating the warranty. |
23:30 | < RichardBarrell> | struct Foo { /* public stuff */ int x; int y; /* don't touch this or I WILL THROW FLAMING BADGERS AT YOU. MANY FLAMING BADGERS. */ float z; }; |
23:31 | <@ToxicFrog> | Derakon: the main thing is so that people don't go "oh, using foo_set_coordinates is a pain, I'll just twiddle obj->x and obj->y directly" |
23:31 | < RichardBarrell> | If the only place where you can physically see that float z exists is by looking in the source code and the source has a comment explicitly telling you not to mess with z right above it then any negative outcome of messing with z can only be downstream's fault. I think I'm happy with that standard. |
23:32 | <@ToxicFrog> | And then the next release changes how the struct is organized and suddenly none of their code compiles and they bitch about it on the mailing list. |
23:32 | <@Derakon> | And then you kick them off for complaining after they broke the warranty~ |
23:32 | <@ToxicFrog> | Yeah, "hiding" the struct interior won't stop people if they really want or need to do this, but it does make it really obvious that they're doing something stupid and fragile. |
23:32 | <@ToxicFrog> | Which in turn cuts down on how often it happens. |
23:33 | < RichardBarrell> | On reflection, I'm with you on this. |
23:33 | <@ToxicFrog> | (you might as well ask "why do OO languages have a 'private' scope, just let it all hang out") |
23:33 | < RichardBarrell> | Having to type "foo.private.z" all over the place makes it much more obvious that you are doing something questionable than merely having the only documentation for "foo.z" be a comment saying "this is private, don't touch it." |
23:34 | < RichardBarrell> | I write Python. Letting it all hang out is a major win. ;) |
23:34 | <@Derakon> | TF: no, the private scope is the convenient way to say "Hey look, if you muck with this, all bets are off." |
23:34 | <@Derakon> | It's more elegant than Python's "put two underscores in front of the variable name" tradition, anyway. |
23:35 | <@ToxicFrog> | Derakon: yeah, and this is a way of doing the same thing in a language that doesn't have private. |
23:36 | <@Derakon> | ...oh, I missed that. |
23:36 | <@Derakon> | I thought we were talking about C++. |
23:36 | <@ToxicFrog> | I've only ever seen this in plain C. |
23:36 | <@Derakon> | Though on reflection, the overuse of structs should have been a giveaway~ |
23:37 | < RichardBarrell> | There isn't actually any restriction on *where* you can define friend methods in C++, is there? |
23:37 | <@ToxicFrog> | (also, I thought python had private and __ was "this is special", not "this is private"?) |
23:37 | < RichardBarrell> | No, Python does not have private. __ means "this is private." |
23:38 | <@Derakon> | __foo is "private foo", while __foo__ is "Python's foo". |
23:38 | < RichardBarrell> | If I define MyClass.__frobnicate() then I can call the frobnicate method as self.__frobnicate() from inside MyClass, but from outside MyClass (or is it outside the module? I never bothered to check) it gets forcibly name mangled to myobject.__MyClass_frobnicate(). |
23:39 | < RichardBarrell> | I think the same happens with attribute names. |
23:39 | < RichardBarrell> | So it's roughly identically as forceful as making people type "somestruct.private.fronicate". Perhaps a little more so. |
23:40 | <@ToxicFrog> | Aah. |
23:40 | < celticminstrel> | I seem to have started something. <_< |
23:40 | | * ToxicFrog , as you can probably tell, doesn't do a lot of Python~ |
23:40 | < RichardBarrell> | To be fair, you *can* make *truly* private variables in Python by making use of lexical closures. |
23:40 | < celticminstrel> | I suppose there's little chance of ever getting zlib to change their policy, though. |
23:42 | < celticminstrel> | Okay... if I have a variable of type iostream, I guess I can't assign an istream or ostream to it? |
23:42 | < RichardBarrell> | That's considered pretty evil. Normal Python niceties like the built-in serialization ("pickle", which rocks) won't work for your class if you do this, because it requires you to tack closures onto your object. |
23:43 | < RichardBarrell> | IIRC no. iostream multiply-inherits from istream and ostream, doesn't it? |
23:43 | < celticminstrel> | I think so, yeah. |
23:44 | < RichardBarrell> | You can only go in the other direction, then. Feel free to assign an iostream* to an istream* or an ostream*. |
23:44 | < RichardBarrell> | There's a common superclass called "ios". http://www.cplusplus.com/reference/iostream/ios/ |
23:44 | < RichardBarrell> | Common to istream and ostream, I mean. |
23:45 | < celticminstrel> | But I can't use read or write on that, can I. |
23:45 | < RichardBarrell> | No. |
23:45 | < RichardBarrell> | What are you trying to do? It sounds more like you want an istream* and an ostream* instead of one iostream*? |
23:49 | < celticminstrel> | I'm trying to make SDL work with C++ streams. <_< |
23:49 | | shade_of_cpux is now known as cpux |
23:53 | < celticminstrel> | If I have an iostream, is it safe to static_cast it to either istream or ostream? |
23:54 | | Syloqs-AFH [Syloq@NetworkAdministrator.Nightstar.Net] has quit [[NS] Quit: ] |
23:59 | < RichardBarrell> | Sure. |
23:59 | < RichardBarrell> | Well. |
23:59 | | Syloqs_AFH [Syloq@NetworkAdministrator.Nightstar.Net] has joined #code |
23:59 | < RichardBarrell> | static_cast an iostream* to an istream* or an ostream*. |
23:59 | < celticminstrel> | Right, of course. |
23:59 | < celticminstrel> | What about dynamic_cast? |
--- Log closed Wed Oct 06 00:00:06 2010 |