code logs -> 2012 -> Sun, 04 Nov 2012< code.20121103.log - code.20121105.log >
--- Log opened Sun Nov 04 00:00:32 2012
00:23
< celticminstrel>
Is there any way to view a unicode string in Python so that it's indexed according to logical characters rather than actual characters? For example, in a string such as x = "h??t" with a combining diacritic, I'd want to be able to treat it as ['h', '??', 't'] for the purposes of indexing, rather than as ['h', '?', '\u0304', 't'].
00:27
<&Derakon>
foo = u'h\u03bct'; print foo[1]
00:27
<&Derakon>
?
00:27
< celticminstrel>
Huh?
00:27
<&Derakon>
I used a different unicode character.
00:27
<&Derakon>
But note that there's a difference between "print foo[1]" and just "foo[1]" on the REPL.
00:28
<&Derakon>
The latter would output "u'\u03bc'"
00:28
< celticminstrel>
Yours doesn't have a combining diacritic.
00:28
<&Derakon>
Oh, sorry, I misread.
00:28
< celticminstrel>
Maybe I was unclear too.
00:29
<&Derakon>
Um, I honestly don't know in that case.
00:29
< celticminstrel>
The one thing I've thought of so far is a regex that enumerates every possible combining diacritic.
00:30
< celticminstrel>
And then findall.
00:38 Vash [Vash@Nightstar-b43e074a.wlfrct.sbcglobal.net] has joined #code
00:38 mode/#code [+o Vash] by ChanServ
00:38
< celticminstrel>
...wait a second. Do I need to do something special to get unicode strings from a file?
00:38
<&Derakon>
Not as far as I'm aware.
00:38
< celticminstrel>
Okay good.
00:39
<&Derakon>
...hm, maybe you do.
00:39
<&Derakon>
I just wrote a bunch of mu to a file, and when I do open(filename, 'r').read(), I got this:
00:40
<&Derakon>
'\xce\xbc\xce\xbc\xce\xbc\xce\xbc\xce\xbc\xce\xbc\xce\xbc\xce\xbc\xce\xbc\xce\xb c\xce\xbc\xce\xbc\n'
00:40
< celticminstrel>
Maybe it's in the modestring.
00:42
<&Derakon>
Ah, the codecs module can read Unicode files.
00:42
<&Derakon>
http://stackoverflow.com/questions/147741/character-reading-from-file-in-python
00:42
<&Derakon>
codecs.open(filename, encoding = 'utf-8')
00:42
<&Derakon>
Gets you a filehandle that does unicode properly.
00:44
<&McMartin>
The other thing you can do is take that bytestring you got and call .encode('utf-8') on it.
00:44
<&McMartin>
Er
00:44
<&McMartin>
no
00:44
<&McMartin>
*de*code
00:44
< celticminstrel>
Eh, that'll work.
00:44 * celticminstrel uses codecs module, with mode='w' where necessary.
00:44 * McMartin has recently had to do encoding shenanigans across various codepages that aren't compatible directly.
00:44 * McMartin nods
00:45
< celticminstrel>
I'm thinking update mode isn't ideal when I'm processing it line-by-line...
00:45
< celticminstrel>
(mode='w+')
00:46
<&McMartin>
That'll erase it on open, won't it?
00:46
< celticminstrel>
'w' yes, 'w+' I wouldn't think so.
00:46
<&McMartin>
I think + is "for reading and writing"
00:46
<&McMartin>
I think you want a+ for "and write at the end, do not truncate"
00:46
<&McMartin>
That's how it works with fopen(3), anyway.
00:47
< celticminstrel>
Maybe I should use the os module to rename the file (for backup) rather than reading in and writing back out...
00:47
< celticminstrel>
(I'm just using 'w'.)
00:47
<&McMartin>
If you plan on producing the illusion of update in place, you *must* read the whole file into memory first or it will trash the read file before you're ready for it
00:48
<&McMartin>
That's one of the standard rookie mistakes in shell scripts.
00:48
<&McMartin>
foo < a.txt > a.txt ends up processing an empty file.
00:48
<&McMartin>
You can make a pretty good case this is the wrong thing to do, but it's tradition~
00:48
< celticminstrel>
I'm going to just rename the file, then process it back into the old name.
00:49
<&McMartin>
That's a good move.
00:49
<&McMartin>
Heck
00:49
<&Derakon>
Alternately, write to a different file, then move the new file over the old one.
00:49
<&McMartin>
Yeah that
00:49
<&McMartin>
Which gives you "atomic update"
00:50
<&McMartin>
though then you can't tail it easily as it builds.
00:51
< celticminstrel>
Only thing left to remember is whether 'for line in file' includes the line breaks...
00:53
<&McMartin>
I believe it does, but this calls for SCIENCE
00:54
<&McMartin>
Man, it's been a while since I've coded up a state machine by hand.
00:55
<&McMartin>
I'm not sure whether to be pleased or vaguely horrified that I seem to be able to do the NFA-to-DFA conversion in my head.
00:55
< celticminstrel>
Doesn't seem like Python regex has character classes for Unicode blocks.
00:58
< celticminstrel>
Presumably I can do it with [x-y] type ranges though...
01:03
<&McMartin>
Let me know what you discover; this is relevant to my interests these days
01:03
< celticminstrel>
x = 'o\u0310o\u0311u\u0310u\u0311'; pat = re.compile('.[\u0300-\u036f]*'); print pat.findall(x)
01:03
< celticminstrel>
Result: [u'o', u'\u0310o', u'\u0311u', u'\u0310u', u'\u0311']
01:03
< celticminstrel>
Did I do my pattern wrong or something? :|
01:04
<&McMartin>
Your pattern looks like it it will, among other things, match any one-character string?
01:04
< celticminstrel>
Yes, it would.
01:05
<&McMartin>
I am a bit surprised it would match things with o or u at the end.
01:05
< celticminstrel>
But * is greedy, isn't it? So it should match as much as possible.
01:05
< celticminstrel>
Me too.
01:05
<&McMartin>
wait
01:05
<&McMartin>
what if you make the compile argument a unicode string
01:05
<&McMartin>
since \u is meaningless in normal strings
01:05
< celticminstrel>
Hm. That sounds like a good idea. :P
01:06
< celticminstrel>
print pat.findall(x)
01:06
< celticminstrel>
[u'o\u0310', u'o\u0311', u'u\u0310', u'u\u0311']
01:06
< celticminstrel>
Works.
01:06
<&McMartin>
Sweet
01:06
<&McMartin>
Except for the lack of one-character results
01:06
<&McMartin>
Or did you make it +?
01:07
<&McMartin>
(That is, shouldn't there also be results for just \u0310 and \u0311)
01:07
< celticminstrel>
The pattern is still the same...
01:07
<&McMartin>
Does . only match \u0000-\u007F then or something
01:08
< celticminstrel>
It shouldn't get a chance to match the diacritics, since they're matched by the *.
01:08
<&McMartin>
Or does findall not do what I expect
01:08
<&McMartin>
Oh geeze, I'd missed that these were combining characters
01:09
< celticminstrel>
pat.findall(u'\u00c0po\u0310z0301')
01:09
< celticminstrel>
[u'\xc0', u'p', u'o\u0310', u'z', u'0', u'3', u'0', u'1']
01:09
<&McMartin>
Oh, OK, it looks like findall doesn't do what I naively expected~
01:10
< celticminstrel>
Oh, I forgot the \u on the last one. <_<
01:10
< celticminstrel>
findall returns all matches.
01:10
< celticminstrel>
Non-overlapping matches.
01:10
<&McMartin>
Right, it's "match, print, then match on remaining substring"
01:10
< celticminstrel>
Yeah.
01:10
< celticminstrel>
More or less.
01:10
<&McMartin>
Not "match on location past where last match started"
01:11
< celticminstrel>
Which for me is exactly the desired behaviour.
01:11
<&McMartin>
Yeah
01:11
<&McMartin>
What language are you dealing with here? I'm not used to dealing with combiners
01:11
< celticminstrel>
Conlang
01:18
<&McMartin>
OK, my lexer works
01:18
<&McMartin>
Now to do something with that.
01:18
<&McMartin>
Then to refactor it to have consistent function naming schemes and maybe actually use objects where appropriate instead of indulging my functional accent
01:19
<&McMartin>
("Oh, I can't bundle this into the function? I guess I'd better pass a reference to it as an argument everywhere that needs it")
01:19
<&McMartin>
(Or I could be lame and make it a field, whatever)
01:19
<&McMartin>
(And by "lame" I mean "correct")
01:20
< celticminstrel>
Pfffft.
01:20
< Noah>
(And by "correct" he means "boooooooriiiiiiing")
01:25
<&McMartin>
But wait!
01:25
<&McMartin>
I get to do horrible things after all.
01:25
<&McMartin>
In particular, it looks like this is actually a job for "protected", the worst of all permissions classes.
01:26
<&McMartin>
Hm, no
01:26
<&McMartin>
Let
01:26
<&McMartin>
Let's do it actually right.
01:40 * McMartin reorganizes it around a callback class.
01:44
<&McMartin>
OK!
01:44
<&McMartin>
The core logic now works
01:44
<&McMartin>
The only thing left is to organize it more sensibly.
01:50 Noah [nbarr@Nightstar-e4b6966f.tn.comcast.net] has quit [Ping timeout: 121 seconds]
01:54
<&McMartin>
... huh
01:54
<&McMartin>
I thought I was using some 1.2-specific stuff in Sable. Guess not.
01:57 * McMartin also does some quick scans of that "modern OpenGL" tutorial he'd been using.
01:57
<&McMartin>
It looks like, shader language dialects aside, the main thing he was using was UBOs.
01:57
<&McMartin>
And VBOs.
01:57
<&McMartin>
Er
01:57
<&McMartin>
VAOs.
01:57
<&McMartin>
VBOs being 2.0
01:57
<&McMartin>
Er, no
01:58
<&McMartin>
VBOs being 1.5
01:58 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Ping timeout: 121 seconds]
01:59
<&McMartin>
Sadly for me, Osmium has VAOs but not UBOs.
02:12
<&McMartin>
OK!
02:12
<&McMartin>
I think ARGLE 1.0 is basically done.
02:12 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
02:12 mode/#code [+o himi] by ChanServ
02:12
<&McMartin>
I just need to do some cleanups on the Makefile and maybe throw together an easily-redistributable Windows build.
02:13
<&McMartin>
Then I can learn about importing pre-existing projects into GitHub. -_-
02:14 Noah [nbarr@Nightstar-e4b6966f.tn.comcast.net] has joined #code
02:27
< celticminstrel>
Okay... else with a for-loop... executes if no break happened?
02:30
<&Derakon>
Looks like it.
02:31
<&Derakon>
TBQH I still have to look up what "else" attached to things other than if statements does.
02:32
< celticminstrel>
Heh.
02:54
<&McMartin>
Oh hey, cool, just what I needed
02:54
<&McMartin>
https://help.github.com/articles/duplicating-a-repo
02:56
<&McMartin>
OK, OpenGL programmers, I'd like some input here
02:56
<&McMartin>
This includes, I think, mostly Derakon and TheWatcher but possibly others by now
02:56
<&McMartin>
I've written a dependency analyzer and am working on presenting the results sensibly
02:57
<&McMartin>
There's the verbose output, which right now is all there is. That's "you use these functions in this program", grouped by either OpenGL version or the relevant extension - that is, grouped by the Thing You Check For In GLEW to see if it's allowed.
02:57
<&McMartin>
I'm trying to come up with a good Executive Summary.
02:57
<&McMartin>
My first pass is:
02:58
<&McMartin>
Minimum Required OpenGL version: X.Y
02:58
<&McMartin>
Required OpenGL Extensions: GL_ARB_omg, GL_ARB_wtf, GL_ARB_bbq
02:59
<&McMartin>
It would be some extra work to make this happen, since I have to draw inferences from comments in glext.h to really do it, but I'm considering also adding:
02:59
<&McMartin>
Some/All required extensions present at OpenGL version: Z.W
02:59
<&McMartin>
Remaining Required Extensions: GL_ARB_bbq
02:59
<&McMartin>
Would those last be a useful thing?
03:00
<&McMartin>
(In particular, I have not convinced myself of how useful a thing it is if "Remaining Required Extensions" is not empty)
03:01
< gnolam>
How are you going to handle extensions that got merged into core?
03:03
<&McMartin>
That's exactly what those last two lines are part of
03:03
<&McMartin>
The first two lines are for GLEW users, where the right thing to do if you, say, are using VAOs but those are the only part of 3.0 you're using, is to check for version 2.1 and then independently check for GL_ARB_vertex_array_obect
03:03
< gnolam>
Ah. I had trouble parsing that bit.
03:04
<&McMartin>
Yeah, I don't like it as phrased~ This is why I'm fishing for suggestions
03:04
<&McMartin>
Maybe it would be better with an example from that arcsynthesis tutorial
03:04
<&McMartin>
That would produce:
03:04
<&McMartin>
Minimum Required OpenGL version: 2.1
03:04
<&McMartin>
Oops, wait
03:04
<&McMartin>
Minimum Required OpenGL version: 2.0
03:05
<&McMartin>
Required OpenGL Extensions: GL_ARB_vertex_array_object, GL_ARB_uniform_buffer_object
03:05
<&McMartin>
All required extensions present at OpenGL version: 3.2
03:05
<&McMartin>
(Then, if it, say, also used some GL_NV_* extension, that "all" would be "some" and it would list the NV one afterwards as a leftover.)
03:07
<&McMartin>
Hm.
03:07
<&McMartin>
I guess that produces slightly silly results when the extensions were folded in before your Minimum Required Version.
03:08
<&McMartin>
Since I need to build another map to do either of those last two, though, I think I'm going to stick with "have GLEW check for these things" as the first release version.
03:11
<~Vornicus>
Hoorargle
03:16
<&McMartin>
gnolam: It's worth noting I'm taking extreme advantage of the fact that GLEW deduces extension compliance based on presence of the relevant functions here.
03:17
<&McMartin>
So the minimum required OpenGL version is the lowest version in which every function you use that is not part of some extension is available.
03:18
<&McMartin>
A lot of the older extensions seem to have mutated a little bit on their way to the core, so, for instance, despite there being a ARB_vertex_buffer_object, actually using VBOs shows up to GLEW as a test against GL_VERSION_1_5.
03:18 * Vornicus pokes vaguely at vornda. How to organize input and entities
03:21 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Ping timeout: 121 seconds]
03:32
<~Vornicus>
well, whichever. First things first let me get an entity drawn and keyboard controls working at all.
03:32
<&McMartin>
Heh
03:33
<&McMartin>
You're using pygame and direct framebuffer access, right?
03:33
<~Vornicus>
yes.
03:33
<&McMartin>
OK
03:33
<&McMartin>
Drawing at least should be easy
03:34
<&Derakon>
Depending on how many dynamic entities you want, I tend to favor quadtrees for organizing entities.
03:34
<&Derakon>
I have a Python quadtree implementation that you're welcome to pillage, though it uses a custom 2D vector object that should probably be replaced by numpy or something.
03:35
<~Vornicus>
I would do this in GM or GMS but the free versions are limited in ways that I can't really get around.
03:35 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
03:35 mode/#code [+o himi] by ChanServ
03:35
<~Vornicus>
External file usage and object count, respectively.
03:38 Kindamoody[zZz] is now known as Kindamoody
03:39
<~Vornicus>
though lack of array literals is an amazing problem too.
03:39
<&McMartin>
If you're being Zeldalike, you probably don't want a quadtree you probably want to link entities to rooms.
03:39
<~Vornicus>
Yeah, I don't think I'll have that many entities.
03:39
<&Derakon>
Then a quadtree's overkill, yeah.
03:39
<&Derakon>
I'd say just start with a list then. *shrug*
03:40
<&Derakon>
If it ends up not being performant for some strange reason, you can X-sort the list.
03:40
<~Vornicus>
I meant more "how do I organize the code that handles individual entities"
03:40
<&McMartin>
List of objects with methods in them that look A Whole Lot like GM/GMS event handlers. -_-
03:40
<&Derakon>
Heh.
03:41
<&McMartin>
(GM's engine model as exposed to the programmer is Really Quite Good.)
03:52 * Vornicus examines
03:54
<~Vornicus>
yeah, all right.
04:15 Nemu [NeophoxProd@Nightstar-eaf2051a.asahi-net.or.jp] has joined #code
04:36
<~Vornicus>
Actually regarding "zeldalike", the actual goal as far as rooms go is something like LttP or Minish Cap: individual rooms are big enough to scroll.
05:05 VirusJTG [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has quit [[NS] Quit: Program Shutting down]
05:11 Derakon is now known as Derakon[AFK]
05:25 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Ping timeout: 121 seconds]
05:35 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
05:35 mode/#code [+o himi] by ChanServ
05:44 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Connection closed]
05:45 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
05:45 mode/#code [+o himi] by ChanServ
06:14 Syloq_Home [Syloq@NetworkAdministrator.Nightstar.Net] has quit [Client closed the connection]
07:09 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Ping timeout: 121 seconds]
07:23 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
07:23 mode/#code [+o himi] by ChanServ
07:27 celticminstrel [celticminst@Nightstar-05d23b97.cable.rogers.com] has quit [[NS] Quit: And lo! The computer falls into a deep sleep, to awake again some other day!]
07:30
< Syk>
welp
07:30 * Syk is gonna be a startup soon, it looks
07:33 Kindamoody [Kindamoody@Nightstar-05577424.tbcn.telia.com] has quit [Client exited]
07:36 Kindamoody|afk [Kindamoody@Nightstar-05577424.tbcn.telia.com] has joined #code
07:36 mode/#code [+o Kindamoody|afk] by ChanServ
07:38 Kindamoody|afk is now known as Kindamoody
07:45 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Ping timeout: 121 seconds]
07:46 Vash [Vash@Nightstar-b43e074a.wlfrct.sbcglobal.net] has quit [[NS] Quit: I lovecraft Vorn!]
07:58 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
07:58 mode/#code [+o himi] by ChanServ
08:06 Kindamoody is now known as Kindamoody|out
09:33
<@Azash>
Syk: Nice
09:40
< Syk>
Azash: for certain varieties of nice
09:40
< Syk>
:P
09:40
<@Azash>
Startup = nice for large values of startup
09:41
< Syk>
i mean the terrible, single-person kind of startup
09:41
<@Azash>
Ah
10:41 A_A [A_A@Nightstar-3f9f1edd.res.rr.com] has joined #code
10:49 A_A [A_A@Nightstar-3f9f1edd.res.rr.com] has quit [[NS] Quit: ]
11:24 Attilla [Obsolete@Nightstar-2ce4ad66.as43234.net] has joined #code
11:26 Attilla_ [Obsolete@Nightstar-c5d070c2.as43234.net] has quit [Ping timeout: 121 seconds]
11:49 himi [fow035@Nightstar-5d05bada.internode.on.net] has quit [Ping timeout: 121 seconds]
12:16 himi [fow035@Nightstar-5d05bada.internode.on.net] has joined #code
12:16 mode/#code [+o himi] by ChanServ
12:48 ErikMesoy|sleep is now known as ErikMesoy
12:49 VirusJTG [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has joined #code
13:56 Nemu [NeophoxProd@Nightstar-eaf2051a.asahi-net.or.jp] has quit [Client closed the connection]
14:07 Syloq_Home [Syloq@NetworkAdministrator.Nightstar.Net] has joined #code
14:22
< rms>
Syk: what is it going to focus on?
14:22 * AnnoDomini crackles with power, gets Opera to open PDFs with the proper application!
14:24
< Syk>
rms: cloud and uh
14:24
< Syk>
stuff
14:24 * Syk violently flails arms
14:25
< Syk>
nah, some software I'm writing
14:25
< Syk>
SaaS/self-hosted web app or something
14:25
< Syk>
I haven't come up with it all yet
14:25
< Syk>
:P
14:35 * iospace makes Syk's code segfault
14:35 * Syk blinks
14:35
< Syk>
D:
14:40 celticminstrel [celticminst@Nightstar-05d23b97.cable.rogers.com] has joined #code
14:47 celticminstrel [celticminst@Nightstar-05d23b97.cable.rogers.com] has quit [[NS] Quit: KABOOM! It seems that I have exploded. Please wait while I reinstall the universe.]
14:48 celticminstrel [celticminst@Nightstar-05d23b97.cable.rogers.com] has joined #code
14:58
< celticminstrel>
So I discovered Word actually supports a form of regular expressions which has nearly everything basic standard regex has.
14:58 Attilla_ [Obsolete@Nightstar-a983cd98.as43234.net] has joined #code
14:58
< celticminstrel>
Only seems to lack an alternation operator...
15:00 Attilla [Obsolete@Nightstar-2ce4ad66.as43234.net] has quit [Ping timeout: 121 seconds]
15:02
< AnnoDomini>
How does one take the first word from the output of a command line application?
15:03
< AnnoDomini>
I mean, I do "wc -w file.txt" and it brings me the word count and the name of the file. I just want the wordcount.
15:03
< Syk>
um
15:03
< Syk>
in linux?
15:03
< Syk>
well bash
15:04
< celticminstrel>
The example I saw for that somewhere used awk, I think.
15:04
< celticminstrel>
Unless wc has an option to exclude the filename?
15:04
< celticminstrel>
3
15:04
< rms>
$ wc -w notes.txt | cut -f 1 -d ' '
15:04
< rms>
1036
15:04
< Syk>
dammit rms beat me to it
15:04
< celticminstrel>
cut?
15:04
< rms>
$ wc -w notes.txt | awk '{ print $1 }'
15:04
< rms>
1036
15:04
< AnnoDomini>
Exgellend! Thank you.
15:06
< rms>
Once upon a time, when I had free time, I read the entire man page of every single binary in GNU core-utils.
15:06
< rms>
I do not regret such an act.
15:06
< celticminstrel>
I usually don't remember what I read in man pages. <_<
15:10 * AnnoDomini unleashes the power of backup.sh: http://pastie.org/5181377
15:12
<@Tamber>
rms: Considering it's GNU utils, doesn't the man-page normally consist of, summarised: "Go read the info page"? :p
15:13
< rms>
Nah, they fixed that a while ago
15:14
< celticminstrel>
Pffft.
15:31 VirusJTG_ [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has joined #code
15:33 VirusJTG [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has quit [Ping timeout: 121 seconds]
16:19
<&ToxicFrog>
celticminstrel: that's a pretty big lack
16:20
< celticminstrel>
True.
16:20
< celticminstrel>
Someone should complain to Microsoft. :P
16:21
<&ToxicFrog>
AnnoDomini: I note that for wc specifically, you can also just do: wc -w < file
16:21
<&ToxicFrog>
It won't output the filename if there's no filename!
16:21
<&ToxicFrog>
$ wc -l <broadcast.txt
16:21
<&ToxicFrog>
65
16:21
< celticminstrel>
You can't get a filename from a file handle?
16:24
<@froztbyte>
no, it's just stdin in that operation
16:24
< celticminstrel>
stdin is a file handle!
16:35
<&ToxicFrog>
No, you can't (what if there's no filename associated with it? Or multiple filenames?)
16:36
< celticminstrel>
Ah well. Thought so.
16:43 gnolam [lenin@Nightstar-ccbf4b44.cust.bredbandsbolaget.se] has quit [[NS] Quit: Reboot]
16:46 gnolam [lenin@Nightstar-ccbf4b44.cust.bredbandsbolaget.se] has joined #code
17:40 iospace is now known as io|PACKERS
18:15 rms is now known as Vasi
20:35
< ErikMesoy>
My current Python exercise says to define a class GraphApproximation which takes two point arryas (x_values, y_values) as parameters, then I am to call GraphApproximation(x) to get the approximate y-value for that x-value. How do I name a function or whatever inside the class to get this to work?
20:44
< ErikMesoy>
I feel there's something obvious I'm missing
20:46 Moltare [Moltare@583787.FF2A18.190FE2.4D81A1] has quit [Ping timeout: 121 seconds]
20:46
<&McMartin>
As written, that is a constructor
20:47
<&McMartin>
Is that latter thing supposed to be f = GraphApproximation(x_values, y_values), and you're supposed to call f(x)?
20:47
<&McMartin>
Otherwise you're doing some kind of heinous constructor abuse.
20:47
< ErikMesoy>
Yes.
20:47
< ErikMesoy>
Probably.
20:47
<&jerith>
That's how I read it.
20:47
< ErikMesoy>
I am going a little cross-eyed trying to make sense of this.
20:47
<&McMartin>
Look up operator overloading
20:48
<&McMartin>
You should find what you need in there
20:48
< ErikMesoy>
I don't think this is supposed to be abusive. >_>
20:48
<&jerith>
They method you want is __call__(), but I'll find you the docs for these things.
20:49
< ErikMesoy>
So yes, f = GraphApproximation(x_values, y_values), then f(x) which looked funny to me because f was an object behaving like a method.
20:49
<&jerith>
http://docs.python.org/2/reference/datamodel.html#emulating-callable-objects
20:49
<&jerith>
That page has the rest of the magic methods on it as well.
20:49
<&McMartin>
Objects that behave like methods are not uncommon
20:49
<&McMartin>
They're what Python uses instead of Proper Closures
20:50
< ErikMesoy>
Thanks for the magic. :)
20:50
<&jerith>
Python has Mostly-Proper Closures, though.
20:50
<&jerith>
I think we established that last time. ;-)
20:51 Moltare [Moltare@583787.FF2A18.190FE2.4D81A1] has joined #code
20:51
<&McMartin>
jerith: Yes, but it also has Actually Proper Closures, it just represents them in-code as object instances
20:55
< ErikMesoy>
Did I miss this "last time"?
20:56
<&jerith>
ErikMesoy: It was quite a while ago, and we ended up discussing closures from some other direction.
20:58 Vasi is now known as rms
21:00
< ErikMesoy>
OK this makes no sense.
21:00
< ErikMesoy>
print 'f(%g)=g' (x, f(x))
21:00
< ErikMesoy>
Even accounting for a missing % to pass the last part as printing argument, it still doesn't work.
21:01
<&jerith>
print 'f(%g)=%g' % (x, f(x))
21:02
<&jerith>
The % operator is overloaded to do formatting stuff for strings.
21:02
< ErikMesoy>
So two missing %s? That seems to work
21:03
<&jerith>
The formatting specifiers are similar (but not identical) to printf() in C.
21:04 * ErikMesoy mumbles about tracking down fiddlybits
21:04
< ErikMesoy>
I have this neat giant structure in the background for doing approximations and plotting them, and I'm left chasing missing percentage signs. :p
21:22 Kindamoody|out is now known as Kindamoody
21:44 io|PACKERS is now known as iospace
21:45 Kindamoody is now known as Kindamoody[zZz]
21:50
< ErikMesoy>
Am I a terrible person for writing "coefficients = [[],[],[],[],[]]" and populating with two nested loops afterwards? I can't quite seem to get the hang of list comprehensions. >_>
21:51
<&McMartin>
PROCEDURAL PROGRAMMING
21:51
<&McMartin>
UNCLEAN, UNCLEAN
21:51
<&McMartin>
More seriously, comment the shit out of that
21:51
<&McMartin>
Oh wait, no
21:51
<&McMartin>
You're only a moderately terrible person
21:52
<&McMartin>
You are presumably populating those internal lists by repeatedly calling "append" in the inner loop, right?
21:52
<&McMartin>
Or extend, or w/e
21:52
< ErikMesoy>
for i in range: for j in range: coefficients[i].append(stuff relating to j)
21:52
<&McMartin>
Right.
21:52
<&McMartin>
So.
21:52
<&McMartin>
Instead do something like:
21:53
<&McMartin>
coefficients = []; for i in range: x = []; for j in range: x.append(blah); next j; coefficients.append(x); next i
21:53
<&McMartin>
(next * used here to mark ends of loops)
21:53
<&McMartin>
(Not actual python as far as I know)(
21:53
<&McMartin>
This way you don't have to rewrite your initializer of coefficients should the range i goes over change
21:57
<&McMartin>
Also, it puts your code more in harmony with the dictates of Hermes Tresmegistus: as above, so below
22:00 * McMartin is maybe half kidding with that one, but it's also a good thing to have your code do similar things at each level because it makes the routine as a whole more coherent.
22:02 Derakon[AFK] is now known as Derakon
22:02
< Noah>
List comps are the best
22:02
<&McMartin>
I agree, but if you're going to avoid them, there are better and worse ways to do so.
22:03
<&McMartin>
In this case that would also be [[(stuff relating to j) for j in range] for i in range]
22:04
<&jerith>
I find it's eaiser to read nested listcomps if they're multi-line.
22:13
< ErikMesoy>
Happiness of the moment: that Python lets me create a thing by different methods inside an if-else block and keep using it afterwards. (Older languages would have required me to declare the thing before the block and give it a value in there, because creating it in the block would destroy it when the block ended.)
22:14
< celticminstrel>
Of course, you have to make sure it's initialized on every branch.
22:44
< Moltare>
(Other languages would, at least, allow you to create it in the block if you only required it in the block ?? cf my usual lament re: runescript and its need to be sodomised by angry floats)
22:45
< gnolam>
It's a Fffffffffffffuuuuuuuuuuuuuuuuthark?
22:45
< Moltare>
Great at runeing people's day, yes
22:46
< Syk>
sodomised by angry floats sounds like a regular game of XCOM
22:50 Reiv [NSwebIRC@D4E70A.D52DB0.820B13.98C775] has joined #code
23:02
<&ToxicFrog>
ErikMesoy: conversely, function scope drives me kind of crazy~
23:25 Noah [nbarr@Nightstar-e4b6966f.tn.comcast.net] has quit [Ping timeout: 121 seconds]
23:27 Kindamoody[zZz] [Kindamoody@Nightstar-05577424.tbcn.telia.com] has quit [Ping timeout: 121 seconds]
23:29 Kindamoody|afk [Kindamoody@Nightstar-05577424.tbcn.telia.com] has joined #code
23:29 mode/#code [+o Kindamoody|afk] by ChanServ
23:31 ErikMesoy is now known as ErikMesoy|sleep
23:36 Pandemic [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has quit [Client closed the connection]
23:36 Pandemic [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has joined #code
23:37 VirusJTG__ [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has joined #code
23:37 VirusJTG__ [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has quit [[NS] Quit: Program Shutting down]
23:38 VirusJTG [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has joined #code
23:39 VirusJTG_ [VirusJTG@Nightstar-09c31e7a.sta.comporium.net] has quit [Ping timeout: 121 seconds]
--- Log closed Mon Nov 05 00:00:47 2012
code logs -> 2012 -> Sun, 04 Nov 2012< code.20121103.log - code.20121105.log >

[ Latest log file ]