#racket

/

      • Ven`` joined the channel
      • bthesorceror has quit
      • bwv joined the channel
      • davidl has quit
      • bthesorceror joined the channel
      • Ven`` has quit
      • Ven`` joined the channel
      • orivej joined the channel
      • davidl joined the channel
      • Exuma joined the channel
      • Exuma
        (map (lambda (number) (+ 1 number)) '(1 2 3 4)) Can someone explain how exactly "quoting" works. I'm learning racket and I'm confused how '(1 2 3 4) is different from (list 1 2 3 4)
      • I understand (list 1 2 3 4) because thats similar to an array (sort of). but from what i see.. quoting just converts every item to a symbol
      • so how is it adding symbols?
      • bremner
        Exuma: define x, then try (list 1 2 x) vs '(1 2 x)
      • xedrac joined the channel
      • Exuma
        hahaha
      • ahhh, im not sure if that makes it more or less confusing
      • hmm
      • so in the second list... the quoted one.. are 1 and 2 symbols? or integers
      • @bremner
      • Ven`` has quit
      • aeth
        Exuma: look at what '1 does
      • Exuma
        hmm i see
      • aeth
        You can think of '(1 2 3) as (list '1 '2 '3) and it's not exactly correct, but it sort of shows what's going on.
      • Exuma
        so really it only escapes functions and lists, but leaves normal data types alone
      • aeth
        and '1 '2 '3 becomes 1 2 3
      • It is quoting the numbers, it just makes no difference
      • Actually, they have identical REPL results for me. '(1 2 3) and (list '1 '2 '3) both produce '(1 2 3)
      • Exuma
        sorry, what i mean is .. its attempting to quote the integers, but it just returns the integer
      • it seems the only thing that gets quoted are "variables" (bound or unbound) .. they get converted to symbols
      • Ven`` joined the channel
      • and also functions, and other lists
      • everything else seems to just return itself into the list
      • so like (1 1.5 "hello" #t #f)
      • if quoted, would return an identical list of items
      • but `(abcd (circle 10)` would return 2 quoted symbols (if im not mistaken)
      • im... pretty sure that is right. trying to follow along here
      • (length '(abcd (circle 10))) #=> 2
      • xedrac
        I'm new here, but doesn't quoting a list just prevent it from being evaluated?
      • aeth
        Exuma: Everything is quoted, it's just that quoting some things (like numbers and booleans and strings) makes no difference.
      • Exuma
        I am not sure, but more specifically im trying to figure out what gets returned from a quoted list of various data types. it seems from my experimenting that some things get converted to symbols, and others remain as the original data types
      • ok thats what i mean
      • so '#f === #f
      • '(circle 10) !== (circle 10)
      • aeth
        (circle 10) will evaluate the procedure circle wiith the evaluated argument 10. '(circle 10) is a list of two elements, 'circle and 10
      • (It's not quite that simple because there are things like macros.)
      • Exuma
        ok, makes sense
      • How can i make a lambda with no arguments?
      • aeth
        (circle 10) is equivalent to circle(10) in most syntaxes
      • Exuma
        i just did this (lambda (_) circle)
      • aeth
        No arguments is just (), e.g. (lambda () 42)
      • Exuma
        ok thanks
      • aeth
        And you can test that by calling it, in this case: ((lambda () 42))
      • Exuma
        oooo right
      • i forgot you coudl just execurte it like that
      • aeth
        compare that with: ((lambda (x) x) 42)
      • Exuma
        god this is ridiculous. i feel like ive regressed 10 years in programming
      • xedrac
        Or how about (eval '(lambda () 42)) :)
      • just to illustrate how quoted lists can still be used as code
      • bthesorceror has quit
      • aeth
        Racket is in the Lisp family of languages. Interactive use is encouraged in these languages. Experiment and see what you get. DrRacket or GNU Emacs with racket-mode or geiser-mode are better ways to do this than using the terminal REPL.
      • Exuma
        (10 20 (lambda (n) (+ 1 n)) 30)
      • aeth
        Try to think up little test cases and run them in the REPL, if you're not doing that already.
      • Exuma
        how come the #<procedure> wont go into the list?
      • aeth
        Exuma: It will, but you're not creating a list, you're calling the procedure 10
      • Exuma
        OH
      • crap
      • damn ok, i kenw that
      • aeth
        Remember, (foo 42) is foo(42) in most other syntaxes
      • and foo[42] is (vector-ref foo 42) or (list-ref foo 42) depending on if you are using a vector (random access) or a list (sequential access).
      • bthesorceror joined the channel
      • Exuma
        @xedrac what does eval do in your example
      • @aeth btw I'm currently using Dr Racket
      • xedrac
        @Exuma it just executes the quoted list as code
      • or evaluates it rather. It's basically the opposite of quoting a list.
      • aeth
        Exuma: Good.
      • Exuma: Try (apply + '(1 2 3)) after you've played around with eval a bit
      • Exuma
        i was literally JUST on the apply chapter of dr racket introduction :D
      • i was trying to figure out what the hell it did
      • its almost like... the splat operator in ruby or something
      • or unpacking an array, like
      • ahh thats so cool
      • (apply vc-append (rainbow (square 10)))
      • it basically inserts each list item as an argument
      • aeth
        The list becomes the argument list of the procedure
      • Exuma
        ahhh ok, so its not really like it "passes each item in" as the arguments, but rather some kind of internal construct in racket has an argument list for each function and it just replaces that
      • ok I have a question.. lets say someone is writing a complicated modele.. for example this entire #lang slideshow module. is it common for the entire file of code to be in a single list at its root
      • or, is there often cases where its a lot of (define (x y) (...)) forms, then some empty line,s and more forms
      • and it reads down the page like more imperitive code
      • or.. do most scripts try to funnel everything into one massive insane form that at its root is a single (...)
      • nevermind, that answers that Q
      • O_O
      • aeth
        You generally want lots of defines at the top level
      • The main difference with a typical programming language is that everything is an expression that returns something and most things return useful values, so the way you actually write code, even imperative-style code, is different.
      • You can use ifs just like the ternary operator in most programming languages. The equivalent to if/else if/else blocks is cond, and that's an expression, so you can use it for its return values instead of doing things directly in cond. And those are just two simple examples.
      • This actually makes it quite easy to break things up into smaller procedures.
      • Exuma
        ah yes, from what ive seen i definitely see how that is true. good explanation
      • aeth
        It's trivial to reformat a cond that's used for its return value into a separate procedure as long as you pass the variables it expects to that procedure.
      • Exuma
        the further i go into this, the more scared i am to proceed because i expect some complicated recursion or really complex things to be right around the corner
      • so far everything makes sense, but then again im doing like this basic noob tutorial
      • aeth
        In C, you might have to change an if/else if/else block from setting a value to returning a value if you do that refactor.
      • Exuma: You don't have to use tail recursion at all. At least, not directly. A lot of abstractions are built on top of tail recursive things.
      • There are lots of ways to iterate.
      • TCZ joined the channel
      • Exuma
        yes, thankfully I noticed that within rack im able to call a recursive function... theres none of this...
      • haha
      • aeth
        One of the key Scheme ideas is that optimized tail recursion is an alternative to goto... but in languages where iteration is built on top of goto (such as Common Lisp!) you rarely if ever use gotos directly.
      • cemerick joined the channel
      • TCZ has quit
      • Exuma
        ok, i see
      • what do you mostly use lisp for?
      • Like in your own projects i mean, what type of projects
      • aeth
        Tail recursion is a bit tricky. You have to make sure you're actually doing tail recursion and not something that looks like tail recursion that's not actually being optimized.
      • Usually, different ways to define a fibonacci procedure are used as examples of this.
      • Exuma: Most programming languages are used on servers because you have more of a choice of languages there. https://racket-lang.org/ probably uses Racket.
      • But you can use Racket for anything that there's libraries for.
      • Exuma
        Ok, so people do use it on the web then, for apps and such?
      • I come from ruby/elixir bg, so I am getting my feet wet with other stuff
      • aeth
        You can use it for anything, though, e.g. all you need is OpenGL and SDL bindings in a language and then you can use it for games. e.g. https://pkgd.racket-lang.org/pkgn/search?tags=g...
      • Exuma
        very cool
      • aeth
        There's even a channel called #lispgames for games written in the Lisp family of languages. Most active people there use Common Lisp, though. One regular uses Guile (a Scheme). People have used Racket before for game jams sponsored by that channel.
      • If you're interested in Racket entries in particular, it might be hard to find them. They don't seem to be marked by language.
      • Scheme resources are here if that interests you: https://github.com/lispgames/lispgames.github.i...
      • Exuma
        holy crap at that space game
      • cemerick_ joined the channel
      • aeth
        Most games are still written in C++ (usually using someone else's engine because C++ is hard), but you don't need to do that, especially if you don't plan on porting to consoles and you're making something in 2D.
      • There is an effort to compile Racket to JavaScript, so some Racket game engines or game frameworks might work in the browser (or maybe Racket-in-JS could foreign interface with JavaScript game engines or game frameworks).
      • Exuma
        this is all super fascinating, thanks
      • aeth
        The space game on Twitter by davexunit is written in Guile, a different Scheme language. (There really isn't much portability between Schemes, unlike with Common Lisp.)
      • The Lisp family is mostly: Common Lisp (multiple implementations, one language), Scheme (which is like a family of closely related languages, each with one implementation), Racket (sort of Scheme, sort of not Scheme), and Clojure (way off on its own with very strange ideas about how to do things)
      • I sort of put them in chronological order, but Scheme actually predates Common Lisp even though Common Lisp *feels* older because Scheme breaks compatibility (e.g. Scheme has a more consistent API) with old Lisps and Common Lisp is mostly compatibile with old Lisps.
      • Traditionally, industry used Common Lisp and academia used Scheme or Racket.
      • Exuma
        ahhh i see.. which is the one that most large sites are written in
      • web sites.. i want to say scheme?
      • aeth
        The most popular Lisp site that I'm aware of, Hacker News (essentially a reddit clone), is actually written in its own dialect of Lisp called Arc. But pretty much only that one website uses Arc because it flopped.
      • Exuma
        i remember seeing on highavailability.com they always are talking about lisp
      • aeth
        Arc actually runs on top of Racket, iirc.
      • Exuma
        i cant remember what flavor of lisp though. i believe it had lots of good web libraries
      • aeth
        If people talk about "Lisp" without qualification, they're probably talking about "Common Lisp".
      • "Lisp" can mean both the "Lisp family" and "Common Lisp". This is mainly because the Lisp languages that branded themselves as "Lisp" are mostly dead. Emacs Lisp (in GNU Emacs) and AutoLISP (in AutoCAD) are probably the most alive of the non-Common Lisp Lisps calling themselves "Lisp", but they're both tied to a specific application as a scripting language.
      • orivej has quit
      • bremner
        I use more applications written in emacs-lisp than in scheme or common-lisp.
      • aeth
        Most living Lisps are Schemes (e.g. Guile or Chicken) or at least descended from Schemes (Racket, formerly PLT Scheme).
      • Exuma
        ah i see
      • aeth
        The Scheme standards are tiny, though, so it's easy to write your own Scheme.
      • jao joined the channel