21:14 (topic) -: Racket -- http://racket-lang.org/ (logs at http://racket-lang.org/irc-logs/ ) 21:14 (names) -: gabot mithos28 lewis1711 Blkt tony_ _danb_ lucian shachaf shofetim askhader evhan coyo abbe rapacity em mattmight Tasser fmu Gwyth clklein _p4bl0 martinhex danking MK_FG drhodes alexsuraci` samth jasond lisppaste tewk stamourv` Lajla cpach eli Fill zakwilson jeapostrophe bremner hyko cky rudybot mario-goulart @ChanServ 21:32 (quit) tony_: Ping timeout: 240 seconds 21:41 (join) mwolfe 21:42 (quit) Blkt: Quit: ERROR: do not makunboud t plese! 21:51 eli: danking: Sounds good -- I'd love to see some examples of how it's used (drracket tools like syntax check, macros, etc). Probably worth a blog post too. 21:52 eli: danking: As for your question, see my interactive hack at http://barzilay.org/misc/interactive.rkt -- gives you exactly this kind of commands. 21:53 eli: (And more.) 22:00 em: look at the second example in section 4.9 here -- http://docs.racket-lang.org/guide/set_.html?q=random 22:00 em: why doesn't that just make n = 0 each time it's called? 22:06 rapacity: it does ? 22:06 em: well obviously it doesn't but im asking why not 22:06 rapacity: no the make-runnint-total function does 22:06 rapacity: but that function returns another function 22:06 rapacity: and the function it returns has its own n 22:08 rapacity: (define x (let ([a 0]) (lambda () (set! a (add1 a)) a))) 22:08 rapacity: rudybot: (define x (let ([a 0]) (lambda () (set! a (add1 a)) a))) 22:08 rudybot: rapacity: Done. 22:08 rapacity: (x) 22:08 rapacity: rudybot: (x) 22:08 rudybot: rapacity: ; Value: 1 22:08 rapacity: rudybot: (x) 22:08 rudybot: rapacity: ; Value: 2 22:10 rapacity: the function that's getting caled is (lambda () (set! n (+ n 1)) n) 22:10 em: yeah i dont get what's going on there becaues i thought let was setting a to be zero through out its scope 22:10 rapacity: as long as you don't mutate it 22:10 rapacity: (set! n 22:10 rapacity: changes its value 22:11 rapacity: rudybot: (let ([n 0]) (set! n 100) n) 22:11 rudybot: rapacity: ; Value: 100 22:15 em: i guess somehow the key to it is that x is returning a function itself. 22:16 em: where is the value of a being stored? 22:16 em: this doesn't seem like functional programming? 22:16 rapacity: it isn't 22:17 rapacity: it isn't functional programming 22:18 em: i dont get why the let is not called each time that your 'x' is called, and so it just puts n back to 0 again. 22:18 rapacity: the let is not wrapped in a function 22:18 em: it's wrapped in the definition of 'x' 22:19 rapacity: the function that x gets was inside the body of the let, that's why it has access to "a" 22:20 rapacity: but let isn't being called inside a function 22:20 rapacity: rudybot: (define y (let ([u 0]) u)) (display y) 22:20 rudybot: rapacity: ; stdout: "0" 22:21 rapacity: "y" isn't a function here 22:21 rapacity: the let is not wrapped in a function 22:22 rapacity: rudybot: (define y (let ([u 0]) (lambda () (set! u (+ 1 u)) u )) 22:22 rudybot: rapacity: error: eval:1:0: read: expected a `)' to close `(' 22:22 rapacity: rudybot: (define y (let ([u 0]) (lambda () (set! u (+ 1 u)) u ))) 22:22 rudybot: rapacity: Done. 22:22 rapacity: the let is wrapping around a function and returning it 22:24 em: so when you call y doesn't it expand to (let ([u 0]) (lambda () (Set! u (+ 1 u)) u)) ? 22:25 rapacity: y is just the procedure (lambda () (set! u (+ 1 u)) u) 22:26 em: why isn't it also the (let .. ) part since that's part of the definition of y ? 22:26 rapacity: the let gets evaluated 22:26 rapacity: returning its body 22:27 rapacity: whose value gets binded to y 22:27 rapacity: is (define x 2) a function ? 22:28 em: well the let is evaluated to (lambda 22:29 rapacity: yeah, it's already evaluated 22:29 rapacity: why would it get evaluated again ? 22:29 rapacity: rudybot: (define x (let ([n 0]) n)) 22:29 rudybot: rapacity: Done. 22:29 rapacity: rudybot: x 22:29 rudybot: rapacity: ; Value: 0 22:29 rapacity: rudybot: x 22:29 rudybot: rapacity: ; Value: 0 22:29 rapacity: rudybot: (x) 22:29 rudybot: rapacity: error: procedure application: expected procedure, given: 0 (no arguments) 22:30 rapacity: rudybot: (define x (let ([n 0]) (set! n (+ n 1)) n)) 22:30 rudybot: rapacity: Done. 22:30 rapacity: rudybot: x 22:30 rudybot: rapacity: ; Value: 1 22:30 rapacity: rudybot: x 22:30 rudybot: rapacity: ; Value: 1 22:30 rapacity: sorry, I'm not good at explaining things 22:31 em: you see it's not just y it's (y) if you get me. 22:33 lewis1711: is there anyway to get racket to print the line number of your errors, instead of just bad syntax? maybe it does it in dr racket but that's not working for me 22:34 rapacity: (define x (let ([n 0]) (lambda () (set! n (add1 n)) n))) => (define x (lambda () (set! n (add1 n)) n)) 22:34 rapacity: that's how it evaluates 22:35 rapacity: now the n is a hidden variable only accessible within that lambda 22:40 em: is there a way to do something like this.. 22:41 em: (define six (lambda () (display "SIX"))) (define SIX (lambda () (display "6"))) 22:41 em: so that you could go ((six)) to return 6 ? 22:42 rapacity: yeah 22:42 rapacity: rudybot: (define six (lambda () (lambda () (display "6")))) 22:42 rudybot: rapacity: Done. 22:42 em: it didn't work when i tried it but maybe it needs something other than display? 22:42 rapacity: rudybot: ((six)) 22:42 rudybot: rapacity: ; stdout: "6" 22:43 rapacity: are you perhaps confused about (define (x) vs (define x ? 22:43 rapacity: rudybot: (define six (lambda () (lambda () 6))) 22:43 rudybot: rapacity: Done. 22:43 rapacity: rudybot: ((six)) 22:43 rudybot: rapacity: ; Value: 6 22:45 em: i dont think that's doig what i have in mind anyway 22:45 em: (six) returns SIX so i thought ((six)) should expand to (SIX) which should then return 6 22:46 rapacity: o_O 22:47 rapacity: it doesn't work like that 22:47 em: isnt that applicative order evaluation? 22:48 rapacity: ah 22:48 rapacity: SIX is another variable? 22:48 rapacity: which is a function? 22:48 rapacity: or is it "SIX" ? 22:48 em: yeah 22:48 rapacity: well if SIX is a function 22:48 rapacity: then it would work 22:49 em: i was saying: (define six (lambda () (display "SIX"))) 22:49 rapacity: rudybot: (define (SIX) 6) (define (six) SIX) 22:49 rudybot: rapacity: Done. 22:49 rapacity: rudybot: (six) 22:49 rudybot: rapacity: ; Value: # 22:49 em: (define SIX (lambda () (display "6"))) 22:49 rapacity: rudybot: ((six)) 22:49 rudybot: rapacity: ; Value: 6 22:49 rapacity: ok 22:49 rapacity: rudybot: (define SIX (lambda () (display "6"))) 22:49 rudybot: rapacity: Done. 22:50 rapacity: rudybot: (define six (lambda () SIX)) 22:50 rudybot: rapacity: Done. 22:50 rapacity: rudybot: (six) 22:50 rudybot: rapacity: ; Value: # 22:50 rapacity: rudybot: ((six)) 22:50 rudybot: rapacity: ; stdout: "6" 23:04 (quit) mithos28: Quit: mithos28 23:58 (part) lewis1711