00:03 (join) waltermai 00:05 (part) waltermai 00:05 (join) waltermai 00:06 waltermai: I'm calling my own predicate procedure with a symbol pointing to a list as the only argument. inside the predicate procedure, the length of the symbol/list evaluates to 1, but the list has 10 elements. anyone know what's going on? 00:27 waltermai: figured it out. thanks for entertaining me. 00:42 (join) jonrafkind 01:27 (join) shkk 01:28 shkk: Hi All, I am writing a program that takes the radius of circle as argument and returns its area and circumference, as a list 01:28 shkk: Here is my code: (define (area-and-circum radius) ((cons '(* 3.14 (* radius radius))) ((cons '(* 2 3.14 radius)) '()))) 01:28 shkk: Its obviously not working .. But I am not able to understand why 01:32 jonrafkind: type in '(+ 1 2) in the repl 01:32 jonrafkind: what do you get? 01:33 shkk: Oopss .. So how should I pass the value as a list element? 01:33 jonrafkind: now type in (+ 1 2) 01:34 jonrafkind: what do you get 01:34 shkk: its 3 . but its a value .. 01:34 jonrafkind: do you see the difference between '(+ 1 2) and (+ 1 2) ? 01:35 shkk: Yes.. the former creates a string and sends it back .. the latter actually computes the value 01:35 jonrafkind: more or less 01:35 jonrafkind: now do you see where you went wrong? 01:35 jonrafkind: well one part of where you went wrong 01:35 shkk: But actually, I had removed the quotes .. And I still got the error 01:36 shkk: I had initially this as the code: (define (area-and-circum radius) ((cons (* 3.14 (* radius radius))) ((cons (* 2 3.14 radius)) '()))) 01:36 jonrafkind: ok i dont know how to lead you to discovering the problem so ill just tell you: you have too many parenthesis. ((cons ..)) will try to invoke the result of (cons ) as a function 01:37 jonrafkind: you want (cons ...) 01:42 shkk: Got it : (define (area-and-circum radius) (cons (* 3.14 (* radius radius)) (cons (* 2 2.14 radius) '()))) 01:43 shkk: Thank you. Just another query: How do we know for sure when a error is related to parenthesis ? 01:44 jonrafkind: usually it will say something like "expected procedure given blah and blah" 01:45 jonrafkind: one way to reduce parenthesis nesting is to bind results to intermediate variables 01:45 jonrafkind: (let ([area (* 3.14 ...)] [circumference (* 3.14 ...)]) (cons area (cons circumference '()))) 01:46 (quit) emma: Remote host closed the connection 01:46 shkk: Aahhhh yes that should simplify things 01:47 shkk: Thank you jonrafkind 01:47 jonrafkind: np 01:47 shkk: There should be some kind of reward system in this community chat !! 01:48 jonrafkind: you can send me money 01:48 shkk: I would for sure .. Once I start earning :) 01:48 jonrafkind: ok well ill be here 01:49 shkk: Me too .. 01:54 (quit) shkk: Quit: Page closed 02:03 (join) emma 02:13 (quit) jonrafkind: Ping timeout: 264 seconds 02:34 (quit) hanDerPeder: Quit: hanDerPeder 02:50 (join) dzhus 03:01 (join) hanDerPeder 03:36 (join) Lajla 03:54 (join) masm 04:33 (quit) waltermai: Ping timeout: 245 seconds 06:18 (join) sunnyps 10:17 (quit) dzhus: Remote host closed the connection 10:28 (join) sstrickl 10:53 (quit) hanDerPeder: Quit: hanDerPeder 11:34 (join) askhader 11:37 (part) jtolds: "Leaving" 11:42 (join) hanDerPeder 11:49 (join) jonrafkind 12:08 (quit) sunnyps: Quit: Ex-Chat 12:16 (quit) hanDerPeder: Quit: hanDerPeder 12:40 (join) jay-mccarthy 12:43 (nick) samth_away -> samth 12:47 jonrafkind: isn't there some way to get a field out of a struct instance given just an instance of the struct and a name of a field (like 'a') ? 12:50 Lajla: jonrafkind, name.a 12:50 Lajla: But that's a huge hack. 12:50 Lajla: Ehh instance.a 12:50 jonrafkind: that doesnt mean anything in racket 12:50 Lajla: Is probably a better way of naming it. 12:50 Lajla: That is correct 12:50 Lajla: that is wh y it's a hack. 12:50 jonrafkind: ok how would you implement that? 12:50 Lajla: Basically the interface makes available a variable 'instance.a' 12:51 Lajla: When you make a struct and give it its values, it makes variables like 'instance-name.password' 12:51 Lajla: I'm just saying something. 12:51 Lajla: Which are just variables like anything else. 12:51 Lajla: (struct-ref instance a) would be much eleganterer 12:51 jonrafkind: well ok but even in that case it wouldn't work, you'd have to override all bindings forms that ever existed. 12:51 Lajla: But also much verboserer 12:51 jonrafkind: (define foo (make-foo 1 2 3)), now you want to bind foo.a 12:51 jonrafkind: ok bad example because i used the smae name 12:51 jonrafkind: (define x (make-foo 1 2 3)); x.a 12:52 jonrafkind: x is not in scope when `foo' was defined 12:52 Lajla: jonrafkind, well, the interface does that. 12:52 Lajla: And I stress that it's a huge hack. 12:52 Lajla: I would really rather have structs be functions that take symbols as arguments really. 12:52 jonrafkind: ok well I need a non-hack (or at least less of a hack way) 12:52 Lajla: Like (name 'field) 12:52 Lajla: jonrafkind, make your own macro I guess. 12:52 jonrafkind: yea, but thats pretty slow 12:53 jonrafkind: I can use classes with get-field I guess 12:53 Lajla: jonrafkind, that's also okay. 12:53 Lajla: I should note that I never used structs though, I think I read this at some point 12:53 Lajla: Let's see if I can get the manual. 12:58 Lajla: jonrafkind, the manual is unresponsive to google chrome I fear. 12:58 Lajla: But let's dance to Mathäus Passion in the mean while. 12:58 jonrafkind: worksf or me in chrome 12:58 Lajla does the robot to Mathäus Passion 12:58 Lajla: Damnit, your chrome outchromes my chrome. 13:03 stamourv: jonrafkind: do you know the # of the field, or just the name? 13:04 Lajla: samth, we must continue our immortal debate by the wy. 13:04 Lajla: way* 13:06 jonrafkind: just the name 13:07 stamourv: ok, so unsafe-struct-ref is no help 13:11 Lajla: jonrafkind: http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-11.html#node_idx_402 13:11 Lajla: I found it here. 13:11 Lajla: But I'm not a fan of TYS, even though it was my first resource on Scheme. 13:12 jonrafkind: that assumes you know the struct name, thats what im missing 13:12 jonrafkind: all they've done is replace - with . 13:13 Lajla: Ohhh, I read 'and the name and a field ..' 13:13 Lajla: Instead of 'and the name of ..' 13:13 Lajla: Pardon. 13:13 jonrafkind: heh 13:15 Lajla: jonrafkind, maybe you could dive in the macro and see if instances store the name of their struct at some point. 13:23 Lajla: If they don't store it you're basically out of luck I guess, because they store it inside in an array. 13:23 Lajla: The refs themselves just translate a symbol to an array index. 13:23 Lajla: vector* 13:24 jonrafkind: i thought they translated a number to a value stored in the vector 13:26 Lajla: That's what the instances do. 13:26 Lajla: The refs translate the symbol to a number. 13:27 Lajla: You could just use hash tables though. 13:33 (join) tov 13:43 Lajla: emma, maybe you know the answer. 13:43 Lajla: After all, being British means you are omniscient. 13:45 emma: I am not British. 13:45 Lajla: emma, why didn't you tell me? 13:46 Lajla: Were you afraid I'd like you less? Because I'm okay with it. 13:46 Lajla: I accept people for what they are. 13:46 emma: Lajla: Are you mindful that this channel is logged so that all manner of silliness will be recorded and archived for as long as you live? 13:47 Lajla: No God, I must stop at once. 13:47 Lajla: emma, it's not that silly is it? 13:47 Lajla: I'm sure there exists at least one prime time animated comedy show on Fox that uses similar humour as a vihicle to let Americans buy things they don't need thereby ensuring the continued existence of Fox. 13:48 (quit) tov: Quit: tov 13:48 emma: Logging channels just makes me very self conscious. 13:48 Lajla: Hmm, afraid you'll say things you'll regret? 13:49 (join) tov 13:55 samth: jonrafkind, there's no way to do that 13:56 samth: tov, ping 13:56 samth: Lajla, i'm now bored of our debate 13:56 tov: samth: ping 13:56 samth: tov, when will you be around the office? 13:56 tov: i am around the office 13:57 samth: you don't appear to be around the office :) 13:57 samth: more seriously, i hope to have comments for you fairly soon 13:58 tov: thanks. 13:58 Lajla: samth, =( 13:58 Lajla: Let's find another thing to debate then. =( 13:58 Lajla: Like if continatuions are lambda abstractions or if they aren't. 13:59 (quit) tov: Quit: tov 14:01 (join) tov 14:41 (join) waltermai 14:57 (join) hanDerPeder 14:59 (join) hepek 14:59 hepek: hello 15:08 (join) mario-go` 15:12 (quit) mario-goulart: Ping timeout: 260 seconds 15:20 Lajla greets hepek by offering her a dead bird. 15:21 (quit) mario-go`: Quit: ERC Version 5.3 (IRC client for Emacs) 15:22 (join) mario-goulart 15:45 (quit) tov: Quit: tov 15:47 (join) tov 15:55 (join) shkk 15:55 shkk: Hi All, my code for reversing a list is : (define (rev lis) (cond ((null? lis) '()) ((null? (cdr lis)) lis) (else (list (rev (cdr lis)) (car lis))))) 15:55 shkk: For input '(1 2 3) the output comes as : (((3) 2) 1) 15:57 shkk: I dont understand which parenthesis is causing this problem 16:01 shkk: Got it .. used append instead of list.. 16:05 Lajla: shkk, hold on. 16:05 Lajla: I will show you a cool trick 16:09 shkk: lajla: What ? 16:09 Lajla: http://codepad.org/ARNiFJLg 16:09 Lajla: shkk, that 16:09 Lajla: It is what we call, proper tail recursion, and it's awesome. 16:09 Lajla: shkk, also, do you know the 'named let' 16:10 shkk: @Lajla: No, I am a beginner .. 16:10 Lajla: shkk, well, it's really handy, like when you have syntax like (let random-name ((variable expressoin) ...) body ...) 16:10 Lajla: It's like a normal let. 16:11 Lajla: ऴहूBut in body, there's available a function now which has body ... as it's body. 16:11 Lajla: So you can easily recurse. 16:11 Lajla: It just basically means it starts the let over again when you call the function 16:11 Lajla: Look how I call inner again at the end of the let. 16:12 Lajla: It just means it starts the let over again basically but with the arguments as the new values for the variables. 16:12 bremner: Lajla: don't you want (display (rev ...) ) on the last line? 16:13 Lajla: bremner, ny function is called reverse, not rev. 16:13 Lajla: shkk: http://codepad.org/baglwqcE 16:13 Lajla: This should simply illustrate how a named-let works 16:13 Lajla: bremner, ehh 16:13 Lajla: yeah, you're right. 16:13 bremner: Lajla: not in your paste it isn't 16:13 Lajla: Pardon 16:13 bremner: a'ok 16:14 Lajla: shkk, have you seen the words 'tail call' or 'tail recursion' come by at some points? 16:14 (join) shkk_ 16:16 Lajla: shkk_, have you seen the words 'tail call' or 'tail recursion' come by at some pints? 16:16 (quit) shkk: Ping timeout: 252 seconds 16:17 shkk_: Why am I getting disconnected 16:17 shkk_: Anyways, Lajla: You have called reverse but the actual function name is rev. I did not understand that. 16:19 Lajla: shkk_, yeah, my mistake. 16:19 Lajla: It still works if youy call rev. 16:19 Lajla: णद्ाCodepad'sscheme has rev built in. 16:21 Lajla: shkk_, but have you ever heard the names 'tail call' and 'tail recursion', because the main essense of my modication is not that it uses a named let, but that it's 'tail recursive' 16:22 shkk_: Yaa I have heard tail recursion 16:22 shkk_: But ur not even calling rev .. ur calling reserve .. What is that ? 16:22 bremner: a typo 16:23 shkk_: But reverse is anyways a built in function right 16:23 bremner: oh, not that. reserve is not a typo, sorry. 16:23 bremner: yes, reverse is built in 16:24 shkk_: so where is the tail recursion .. the function definition is rev .. and its calling reserve 16:25 Lajla: shkk_, no, reserve is asomething different then reverse. 16:25 Lajla: I'm not calling it 16:25 Lajla: It's a value, not a function 16:25 Lajla: It's in the let. 16:25 Lajla: You could have renamed it to 'x' that's not the point, it's a bound variable. 16:26 Lajla: shkk_, but what my implementation basically does is, it creates two stacks, it initizializes one (acc) as empty and the other (reserve) as the original list you want to reverse. 16:26 shkk_: okie 16:27 Lajla: And then, each time, it checks if reserve is empty, if so, it outputs acc, if not, then it basically takes the front element of reserve, and prepends it to the front of acc, and repeats the cycle. 16:27 Lajla: So if they start like () and (1 2 3), then after the first go you have (1) and (2 3), and then (2 1) and (3) and ten (3 2 1) and (), and now reserve is empty, so it outputs (3 2 1) 16:28 Lajla: The point is that this version is tail recursive, so it's going to run _a lot_ faster. 16:31 (join) hepek1 16:31 (quit) hepek: Quit: Page closed 16:32 (nick) hepek1 -> hepek 16:33 shkk_: Okie got it .. thanks a lot lajla 16:37 Lajla: shkk_, http://codepad.org/FPQZez3f 16:41 (quit) hepek: Remote host closed the connection 17:26 (join) Mathew 17:26 Mathew: is anyone there? 17:27 Mathew: anyone? 17:28 jonrafkind: yea 17:29 (quit) Mathew: Client Quit 17:29 jonrafkind: oh wel 17:30 chandler: not enough patience for an asynchronous communications method 17:49 Lajla: Maybe we should call him back with the current continuation and try again. 18:07 (quit) tov: Quit: tov 18:10 (join) tov 18:17 (quit) tov: Quit: tov 18:30 (quit) sstrickl: Quit: sstrickl 18:50 (nick) samth -> samth_vacation 19:28 (quit) masm: Quit: Leaving. 19:43 (join) shofetim 20:27 (quit) jonrafkind: Ping timeout: 240 seconds 20:44 (quit) waltermai: Quit: Leaving 21:46 (join) jeapostrophe 23:40 (quit) jeapostrophe: Quit: jeapostrophe 23:41 (join) jeapostrophe 23:58 (quit) jeapostrophe: Quit: jeapostrophe