--- Log opened Wed Feb 27 00:00:22 2008 |
00:00 | | You're now known as TheWatcher[zZzZ] |
02:06 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Quit: Z?] |
02:57 | | * Vornicus fiddles with his code, does battle with module divisions. |
02:58 | | * ToxicFrog gnaws on Serah |
04:04 | | MystWork [~0cb374f4@Nightstar-29731.dsl.in-addr.zen.co.uk] has joined #code |
04:04 | | Vornicus is now known as Vornicus-Latens |
04:08 | | * ToxicFrog curries Myst |
04:08 | < MystWork> | meep! |
04:09 | < MystWork> | I have been turned into Indian food! |
04:09 | <@Vornicus-Latens> | No, you've been given some but not all your function arguments. |
04:10 | < MystWork> | ...okay... >.> |
04:10 | < MystWork> | Anyhoo, I have a very elementary question. |
04:10 | | * Vornicus-Latens actually goes to bed now, lets someone who actually know what the hell's going on talk about it. |
04:10 | <@ToxicFrog> | I can explain currying once your question's answered, if you like. |
04:10 | <@ToxicFrog> | Anyway, go ahead. |
04:11 | < MystWork> | is an "instance" the same thing as an "object", in object-oriented programming? |
04:11 | <@ToxicFrog> | Yes. Every object is an instance of a class. |
04:11 | <@ToxicFrog> | Instantiating a class creates a new object. |
04:12 | < MystWork> | ..hence the funny name, 'instantiating'. |
04:12 | < MystWork> | okey, thanks! |
04:13 | | * MystWork pets the Frog |
04:14 | | * ToxicFrog purrs |
04:14 | <@ToxicFrog> | Now, currying... |
04:15 | <@ToxicFrog> | Generally speaking, a curried function is a function where you can supply some, but not all, of its arguments. |
04:15 | <@ToxicFrog> | And it will return a new function that expects the rest of the arguments, and behaves like you'd supplied them all at once when you give it them. |
04:16 | <@ToxicFrog> | As a simple example, say you have a function add(a,b) which returns a+b |
04:16 | < MystWork> | I thought that was ... o, okay |
04:16 | <@ToxicFrog> | So, add(1,1) -> 2 |
04:16 | <@ToxicFrog> | If it's curried, you can also go something like: |
04:16 | <@ToxicFrog> | add2 = add(2) |
04:16 | <@ToxicFrog> | And now add2 is a new function, which takes a single argument |
04:16 | <@ToxicFrog> | And returns 2 + the argument. |
04:17 | <@ToxicFrog> | So you can then do add2(3) -> 5 |
04:18 | <@ToxicFrog> | Some languages have this built in; for example, all functions in Haskell are curried, and you can partially call any function to get a new, half-called function out. |
04:18 | <@ToxicFrog> | In other languages, like Lua, you must make your curry by hand if you want it. |
04:18 | <@ToxicFrog> | (and in some, like C and I believe Java, it's either impossible or more trouble than it's worth) |
04:19 | <@ToxicFrog> | Make sense? |
04:20 | < MystWork> | when you say make it by hand (like Lua), you mean define the function anew like you defined the first function to begin with, or define it like you did in that example? |
04:22 | <@ToxicFrog> | Define it anew. In that example, I already have a curried function; I'm just storing a partially-called version of it in add2 for later use. |
04:22 | <@ToxicFrog> | Doing that in Haskell is just a matter of making a function: |
04:22 | <@ToxicFrog> | add :: Int -> Int -> Int |
04:22 | <@ToxicFrog> | add a b = a + b; |
04:23 | <@ToxicFrog> | And then I can do: |
04:23 | <@ToxicFrog> | add 1 1 => 2 |
04:23 | <@ToxicFrog> | add 2 => function Int -> Int (ie, it takes an int and returns an int) |
04:23 | <@ToxicFrog> | add2 = add 2 |
04:23 | <@ToxicFrog> | add2 3 => 5 |
04:23 | <@ToxicFrog> | add2 7 => 9 |
04:23 | <@ToxicFrog> | Etc. |
04:23 | <@ToxicFrog> | Just by defining the function "add", it becomes curried automatically. |
04:23 | <@ToxicFrog> | In Lua, however: |
04:23 | <@ToxicFrog> | function add(a,b) return a+b end |
04:24 | <@ToxicFrog> | This is not curried; add(1,1) => 2, but add(2) => error |
04:26 | <@ToxicFrog> | If I want a curried version, I have to hand-craft it: |
04:26 | <@ToxicFrog> | function add(a) return function(b) return a+b end end |
04:26 | <@ToxicFrog> | Creating a function that takes a number and returns a function, which takes a number and returns the sum of that number and the earlier one. |
04:27 | <@ToxicFrog> | This is, as it sounds, rather cumbersome :P |
04:27 | | * MystWork nods |
04:38 | | GeekSoldier|bed is now known as GeekSoldier|work |
04:53 | < MystWork> | thanks, ToxicFrog :) |
04:53 | | * MystWork disappears back into the shadows |
04:53 | | MystWork [~0cb374f4@Nightstar-29731.dsl.in-addr.zen.co.uk] has quit [Quit: CGI:IRC] |
04:59 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has quit [Client exited] |
05:02 | | Thaqui [~Thaqui@Nightstar-123.jetstream.xtra.co.nz] has joined #code |
05:02 | | mode/#code [+o Thaqui] by ChanServ |
06:00 | | GeekSoldier|work [~Rob@Nightstar-8840.dip.t-dialin.net] has quit [Ping Timeout] |
06:46 | | GeekSoldier|work [~Rob@Nightstar-8379.dip.t-dialin.net] has joined #code |
07:22 | | ToxicFrog [~ToxicFrog@Admin.Nightstar.Net] has quit [Operation timed out] |
07:22 | | ToxicFrog [~ToxicFrog@Admin.Nightstar.Net] has joined #code |
07:22 | | mode/#code [+o ToxicFrog] by ChanServ |
07:57 | | gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code |
07:57 | | mode/#code [+o gnolam] by ChanServ |
08:33 | | You're now known as TheWatcher |
09:24 | | * EvilDarkLord reads backscroll. Oh, that's what currying is. I missed it when sorting in C the other day. |
09:27 | <@McMartin> | Yeah, it does that. |
09:30 | | Raif [~corvusign@67.161.90.ns-4200] has quit [Killed (NickServ (GHOST command used by Raif_))] |
09:30 | | Raif_ [~corvusign@67.161.90.ns-4200] has joined #Code |
09:30 | | Raif_ is now known as Raif |
09:48 | | Chalcedon [~Forj@Nightstar-10679.ue.woosh.co.nz] has quit [Connection reset by peer] |
10:30 | | Thaqui [~Thaqui@Nightstar-123.jetstream.xtra.co.nz] has left #code [Leaving] |
10:46 | | MyCatVerbs [~mycatverb@Nightstar-13709.lurkingfox.co.uk] has joined #code |
13:02 | | AnnoDomini [AnnoDomini@83.21.62.ns-26198] has quit [Ping Timeout] |
13:09 | | AnnoDomini [AnnoDomini@83.21.70.ns-3684] has joined #Code |
13:09 | | mode/#code [+o AnnoDomini] by ChanServ |
13:58 | | Bellamy [Jennet@Nightstar-20631.216-254-250.iw.net] has quit [Quit: ] |
16:05 | | * Vornicus-Latens gnargs |
17:02 | | * jerith tries to figure out what the hell this code thinks it's doing. |
17:06 | | Vornicus-Latens is now known as Vornicus |
17:07 | | You're now known as TheWatcher[afk] |
17:27 | <@jerith> | Aha! |
17:27 | <@jerith> | Stupid identifier mismatch. |
17:35 | <@jerith> | AARGH! Stupid bloody object identity. |
17:36 | <@jerith> | Why did the other bloody strings work!? |
17:36 | | * jerith kills Java to death with Japanese hornet things. |
17:44 | <@jerith> | Except that wasn't it at all. It was failing on a different line than the one I was looking at. :-( |
17:49 | | GeekSoldier|work is now known as GeekSoldier |
17:58 | | GeekSoldier [~Rob@Nightstar-8379.dip.t-dialin.net] has quit [Ping Timeout] |
17:58 | | * ToxicFrog patpats |
18:00 | <@jerith> | Ah well, I made it work after all. |
18:00 | <@ToxicFrog> | I had some weirdness last night. |
18:01 | <@ToxicFrog> | {{YY,MM,DD},{HH,MM,SS}} = erlang:localtime() |
18:01 | | AnnoDomini is now known as Pete |
18:01 | <@ToxicFrog> | Worked in one module but not in the other. |
18:02 | | GeekSoldier [~Rob@Nightstar-9088.dip.t-dialin.net] has joined #code |
18:03 | <@jerith> | How did it not work? |
18:06 | <@ToxicFrog> | No match for pattern. |
18:06 | <@ToxicFrog> | In practice it should have failed in both modules. |
18:07 | <@jerith> | Were any of those variables bound before the call? |
18:13 | <@ToxicFrog> | No. |
18:14 | <@ToxicFrog> | The problem was that it tried to bind MM in two different places. |
18:15 | <@jerith> | Oh, htere. |
18:15 | <@jerith> | I missed that. |
18:15 | <@jerith> | It will succeed, however, when both values bound to MM are the same. |
18:30 | | You're now known as TheWatcher |
19:33 | | Chalcedon [~Chalcedon@202.74.200.ns-22253] has joined #code |
19:33 | | mode/#code [+o Chalcedon] by ChanServ |
19:45 | <@McMartin> | Traditionally, minutes are "mm'. |
19:45 | <@McMartin> | YMD:hms |
20:05 | <@ToxicFrog> | Erlang mandates that all variables start with a capital letter. |
20:05 | <@ToxicFrog> | Stuff starting with lowercase is a symbol. |
20:16 | <@jerith> | s/symbol/atom/ |
20:16 | <@jerith> | Smae thing, different name. |
20:16 | <@jerith> | *Same |
20:19 | <@ToxicFrog> | jerith: I chose symbol rather than Atom because I don't think McM knows Erlang, and symbol is a more universal term. |
20:19 | | You're now known as TheWatcher[afk] |
20:20 | | * jerith nods. |
20:25 | | GeekSoldier is now known as GeekSoldier|bed |
20:46 | <@McMartin> | Quite. |
20:47 | <@McMartin> | Though I know the term "atom" from LISP. |
21:11 | | You're now known as TheWatcher |
21:48 | <@gnolam> | Argh. |
21:49 | | * gnolam tries to remember how you made Maxima spit out a decimal number. |
21:51 | <@gnolam> | Oh. It was as simple as float(expr). |
23:11 | | Pete is now known as AnnoDomini |
23:31 | | MystUni [~c6b6cdfe@Nightstar-29731.dsl.in-addr.zen.co.uk] has joined #code |
23:48 | | You're now known as TheWatcher[t-2] |
23:52 | | You're now known as TheWatcher[zZzZ] |
--- Log closed Thu Feb 28 00:00:29 2008 |