#racket

/

      • mrmyers
        odds: (let sum ([lst '(1 (2) ((3 4)) 5)])(cond [(number? lst) lst][(null? lst) 0][else (+ (sum (car lst)) (sum (cdr lst)))]))
      • rexbutler has quit
      • tahon__ joined the channel
      • baldfat has quit
      • tahon__ has quit
      • ben-o_ has quit
      • ben-o joined the channel
      • tahon_ joined the channel
      • badkins has quit
      • dsantiago joined the channel
      • odds
        mrmyers: Interesting. Thanks! That helped me define a procedure that meets the requirements. I appreciate that. :)
      • jonh joined the channel
      • cemerick joined the channel
      • vraid
      • lexi-lambda joined the channel
      • odds
        vraid: Oh ok, foldl. I will learn what that procedure does.
      • Is it kind of like map?
      • vraid
        not really :)
      • foldl takes a list and turns it into one element
      • whereas map applies a function to each element in a list, making a new list
      • rudybot: (foldl + 2 '())
      • rudybot
        vraid: your sandbox is ready
      • vraid: ; Value: 2
      • lexi-lambda
        odds: It's sometimes called "reduce".
      • vraid
        rudybot: (foldl + 2 '(4 5))
      • rudybot
        vraid: ; Value: 11
      • lexi-lambda
        Map takes a list and gives you a new list.
      • fold/reduce take a list and compound all the values into a single value.
      • odds
        Weird.
      • vraid
        odds: map, fold and filter are quite fundamental
      • odds
        Best documentation on them?
      • bremner
        docs.racket-lang.org has pointers to the "guide" and "reference"
      • lexi-lambda
        vraid: Of course, in Racket, we have for/list and for/fold for map and foldl. ;)
      • bremner
        the former is a good place to start.
      • don't scare the beginner ;)
      • lexi-lambda
        The relevant section of the guide is here, fyi: http://docs.racket-lang.org/guide/Lists__Iterat...
      • odds
        Nice, thanks lexi-lambda.
      • vraid
        lexi-lambda: i shall never succumb to for loops!
      • lexi-lambda
        vraid: I write very functional-y Racket, and its for loops are still <3
      • odds
        Writing things in Lisp is fairly challenging-- nice brain-teasers so far.
      • lexi-lambda
        I basically never use plain old "for", which isn't functional at all.
      • for/list, for/fold, for/and and the like are all very nice :)
      • technomancy
        the regularity of for is really nice
      • and the genericity of it
      • lexi-lambda
        odds: You may find that writing things in Lisp is less challenging than in other languages once you get used to it. ;)
      • vraid
        odds: this one looks decent if you can read haskell http://jwb.io/20121224-understanding-map-filter...
      • odds
        lexi-lambda: Hope so haha!
      • vraid: Can't read Haskell.. :P
      • bremner
        yeah, I'm afraid I've fully succumbed to the temptation the for/fold etc... Probably I can't write normal scheme at all anymore.
      • except I still use let most of the time because I'm a rebel.
      • lexi-lambda
        bremner: "let" is the master race binding form; don't let those crazy racketeers sway you from The Path >:D
      • bremner
        well, I appreciate the sentiment, even if your phrasing is probably illegal in Germany.
      • odds
        Ok, how about this one? "Write a Scheme function named elements that counts the number of elements in a list. For example, (elements '(1 (2 3) (4 5))) is 5 even though the length of it is 3."
      • bremner
        I'd start from my sum function and try to change as little as possible ;)
      • odds
        I have written a function to get the length... getting the number of elements is tricky though!
      • Yep bremner, that's what I'm doing heh.
      • vraid
        odds: spot the difference http://pasterack.org/pastes/30146
      • emanuelz joined the channel
      • odds
        Let's see here...
      • vraid
        but it only works on number elements, you'll have to do the check differently if you want any kind of elements
      • odds
        Ah, right.
      • This is insane. My mind is being blown.
      • vraid
        there's also the possibility of using flatten, of course
      • rudybot: (flatten '(1 (2) ((3 4)) 5))
      • rudybot
        vraid: ; Value: '(1 2 3 4 5)
      • odds
        I'm using plt-racket from homebrew repos in my OS X Terminal btw guys, what is the command to clear the interpreter?
      • vraid
        rudybot: (foldl + 0 (flatten '(1 (2) ((3 4)) 5)))
      • rudybot
        vraid: ; Value: 15
      • odds
        Oooh, I like flatten! Is that part of default Racket?
      • vraid
        yep, though it defeats the purpose of the exercise ^^
      • hongminhee_ has left the channel
      • mizu_no_oto joined the channel
      • acarrico
        That question is strangely worded. Elements is counting five leaves, there are only three elements in that list.
      • vraid
        perhaps it should say atoms
      • acarrico
        the problem is the "in a list" part.
      • There is only one atom in the list.
      • odds
        '(1 (2 3) (4 5)) has 3 atoms and 5 elements right?
      • acarrico
        The list (* * *) has three elements, I don't care if they are atoms or not.
      • hongminhee joined the channel
      • hongminhee has left the channel
      • The tree (1 (2 3) (4 5)) has five leaves.
      • Something like that.
      • jeapostrophe has quit
      • But don't let me confuse you. I've just never heard the phrase "elements of a list" used refer to the "fringe" of nested lists.
      • odds
        It's from my book, which my professor admits is bad, so don't worry about it.
      • rudybot: (length '(1 (2) (3, 4) (5)))
      • rudybot
        odds: (in this case, probably that subproblem is the problem of placing `k' queens in the first `k' rows of a square board with side length `board-size')
      • odds
        Who and what now? There's no (length) is there? :P
      • lexi-lambda whacks rudybot
      • lexi-lambda
        odds: Your syntax is off, though. You have a comma in there. :p
      • You can force evaluation with eval, though.
      • acarrico
        rudybot: (length '(1 (2) (3 4) (5)))
      • lexi-lambda
        rudybot: eval (length '(1 (2) (3 4) (5)))
      • rudybot
        acarrico: your sandbox is ready
      • acarrico: ; Value: 4
      • lexi-lambda: your sandbox is ready
      • lexi-lambda: ; Value: 4
      • acarrico
        jinx.
      • lexi-lambda
        >:|
      • odds
        rudybot: (length '(1 (2) (3 4) (5)))
      • rudybot
        odds: your sandbox is ready
      • odds: ; Value: 4
      • odds
        lexi-lambda: Haha thanks. I was writing some Python immediately before that line.
      • lexi-lambda
        In Clojure, commas are treated as whitespace, and it's weird as hell to me. o.O
      • It uses ~ for unquote.
      • acarrico
        The only time I do that is when I'm using the FFI :).
      • ArneBab joined the channel
      • ArneBab_ has quit
      • odds
        vraid: Pretty nice, just had to change "n" in line 4 to "1"!
      • Re: sum of elements vs # of elements.
      • Oh yea, how do I clear the interpreter when using plt-racket?
      • lexi-lambda
        odds: FWIW, I'd recommend against the plt-racket package. It's minimal Racket instead of full Racket, so it doesn't have all the goodies. :p
      • You can use the Caskroom package instead, though.
      • mizu_no_oto has quit
      • odds
        Thanks lexi-lambda.
      • I'm on OS X and using Homebrew to install packages.
      • ben-o has quit
      • ben-o joined the channel
      • lexi-lambda: Installing Caskroom now... Thanks.
      • lexi-lambda
        Caskroom is nice. It basically just extends Homebrew to be able to install other apps. :)
      • odds
        Will I be able to use a cli full racket interpreter now?
      • Just ran "brew install Caskroom/cask/racket".
      • lexi-lambda
        odds: You should probably do `brew cask install racket` instead, but that might work too.
      • odds
        Oh ok, thanks.
      • It seems to be doing the same thing.
      • lexi-lambda
        odds: Anyway, you can evaluate (require xrepl) in the repl to get readline support, or you can launch the interpreter with `racket -il xrepl`.
      • You can also but (require xrepl) in your ~/.racketrc to have it automatically executed on startup.
      • *put
      • odds
        Nice. What would the bash command be for setting it to run 'racket -il xrepl' after just inputting 'racket'?
      • Let me look that up, it's basic I think.
      • Ah, well, I uninstalled plt-racket and when I run 'racket' I still get Racket v6.1.1.
      • I guess I'm good to go? (sorry)
      • lexi-lambda
        odds: Probably, yes. :) You should likely put (require xrepl) in your ~/.racketrc instead of aliasing.
      • (You might want to use `racket` without running a repl.)
      • odds
        Ah, great. What is xrepl?
      • lexi-lambda
      • odds
        Nice, and does it work like with ~/.vimrc in that all I need to do is create my own ~/.racketrc and racket will automatically load it?
      • lexi-lambda
        Yep.
      • odds
        Great, thanks a bunch. Have an Internet point.
      • {[]}grant has quit
      • lexi-lambda
        Actually, I think xrepl has a command for automatically installing itself into your racketrc file.
      • Just to make it even easier. :p
      • odds
        Yep, that worked. Created my ~/.racketrc and added "(require xrepl)" to it.
      • vendethiel joined the channel
      • A-w-e-s-o-m-e. I hope that Caskroom pkg wasn't too large though! I'd like to uninstall Dr. Racket I guess...
      • lexi-lambda
        But DrRacket is great! D:
      • :p
      • odds
        Al---right. :P