9 ms·
A Haskell Programmer Tries to Learn Racket
- wglb 12y agoNicely written, and a fun exploration.
- gaigepr 12y ago"...but nothing beyond that. As long as Node.js exists in this world, I can't truly hate anything else." I found this hilarious. I am also rather underwhelmed (to be nice) with Nodejs and a little bothered at its wide adoption. I have also been learning racket recently; my formal language and functional programming class uses it. I had some previous experience with common lisp but the raw nature of scheme still pleasantly surprised me a little bit. EDIT: From what I remember, javascript was "inspired" by scheme. Obviously that when well...
- deleted 12y ago[deleted]
- MichaelGG 12y agoI keep flipping back and forth, thinking I don't get it, then thinking others don't get it. Single-threaded JS with callbacks. OK? What am I missing? The only thing Node has going for it is a lot of networking libraries. It's not fast, the async style leads to callback hell, JS is a terrible language, and their package management system is slow and bloated (or at least the packages are)[1]. Yet people think it's some new kind of thing that's just so awesome, despite MS doing server-side JS in the mid-90s. Sure, people can use whatever makes them happy. I'm just confused as to why anyone is particularly impressed with Node or JS. 1: Seriously, to automate builds, I ended up saving the node_modules directory then symlinking it in to the build environment. Otherwise a simple CSS/JS/etc. grunt build took 15 minutes instead of 1. And it seems every module pulls in its own copy of dependencies, so you end up with 300-character deep paths. There's no apparent reason it needs to be like this.
- mattgreenrocks 12y agoIt's popular because people think other people think it's popular. There's no accounting for taste, but, it won't last. :)
- nly 12y agoMy theories: 1. Using the same programming language on both sides of HTTP often appeals to a developers visceral sense of elegance, or tidiness, even though it this alone inherently solves no existing problems. 2. It's powered by Googles V8 engine, which means people already associate it with this "super fast JIT" thing that lives in their favourite browser. It must be efficient, right? 3. The crowned alternative is PHP which is slowly becoming Java and alienating, with no disrespect to anyone intended, the less experienced, the "let's just hack a script together" crowd.
- tel 12y ago1. There is a concrete advantage of shared code.
- vinceguidry 12y agoHow does one share server HTTP-serving code and client DOM-manipulating code?
- ebiester 12y agoThere's a library called browserify that does it. It's not useful for direct DOM manipulation, but there are other libraries for which it is nice.
- tel 12y agoMost likely by abstracting both into business concerns which appear in the client (manipulation for implementing a UI) and the server (manipulation for persistence and client-to-client communication).
- a8000 12y ago
- anotherevan 12y agoI wasn't going to bother reading the source article, up until I saw this excerpt in your comment. Now it is added to my reader. :-)
- linhmtran168 12y agoI also hate NodeJS for its package manager, NPM. I don't understand the way it manages dependencies and their folder. What the hell is 'node_modules/express/node_modules/connect/node_modules/multiparty/node_modules/readable-stream/node_modules/debuglog/'. As a result, when updating dependencies with npm, a same dependency is downloaded multiple times.
- ludwigvan 12y agoThat is a good thing when multiple libraries you depend on depend on different versions of some other library. See http://blog.izs.me/post/1675072029/10-cool-things-you-probably-didnt-realize-npm-could-do http://blog.izs.me/post/1675072029/10-cool-things-you-probab...
- ripter 12y agoIt solves the nasty versioning issues that plague the other package managers like pip and rubygems. Every package gets the correct versions for all of its dependancies at the cost of taking more hard drive space. Hard drive space is ridiculously cheap so it's a good trade off.
- deleted 12y ago[deleted]
- Zoxo 12y agoI like the approach you took to writing this post. This wasn't the typical attempt to summarize an entire programming language in a page (which IMO is done too often, too poorly), but rather an exploration. As you went through each section, I could see how you were approaching various problems and learned a lot about Racket in the process. I would love to see more of this style of post.
- artyomkazak 12y agoOf course I couldn't summarize Racket in a page – I don't know it! And there's so much to learn about it that I could probably write half a hundred posts of this length and still consider myself a beginner.
- mahmud 12y agoThat was intellectually honest. Good read.
- Strilanc 12y agoIs this... a Let's Play of learning a programming language? Because it's surprisingly effective. I learned and I was entertained.
- gamegoblin 12y agoI would definitely watch a video series in which an experienced and talented programmer tried out various programming languages for an hour and gave first impressions, comparisons, etc as they hacked something together during the video.
- beefsack 12y agoThe idea of a twitch.tv stream sounds interesting, with viewers throwing small problems at the coder to solve as they fumble around with a new language.
- supergauntlet 12y agoIn this vein I've been pondering doing a livestream of a LFS install for a while, just for funsies. I wonder if anyone would actually watch it.
- marktangotango 12y agoDo it!
- MrException 12y agoI'd watch it!
- anon4 12y agoTwitch learns themselves a Haskell for great lulz?
- leoc 12y agoAnything that increases the already considerable weirdness of http://www.twitch.tv/directory/all http://www.twitch.tv/directory/all can't be bad. ;)
- comex 12y agoOne note: > Racket's default IDE is better than GHCi and probably on par with Emacs (you almost certainly can configure Emacs to be better than anything, but it's not trivial and people don't bother, while DrRacket provides autocompletion and documentation out of the box). Last I used it (a few years ago), DrRacket was very laggy, so I would find it very hard to use for a serious project. YMMV, maybe it's improved.
- Crito 12y agoI love Racket but I have only ever had the same experience with DrRacket. I don't know what it is trying to do, but it brings my modest laptop to its knees.
- codygman 12y agoInteresting... I've never had any problems with DrRacket. What qualifies as a "modest laptop"?
- anaphor 12y agoYeah DrRacket is fairly slow unless you have a powerful computer. I recommend just using a text editor and making use of XREPL, see: http://docs.racket-lang.org/xrepl/index.html?q= http://docs.racket-lang.org/xrepl/index.html?q= tl;dr, open up the normal repl by typing "racket" and then type (require xrepl) and then ,install! (leading comma denotes an xrepl command). Then when you want to interact with a file you can do racket -i $file to interact with it using xrepl. If you're wondering why this isn't just the default, I think it has to do with the readline license.
- brudgers 12y agoracket -il xrepl Will launch Racket with already xrepl loaded.
- brudgers 12y agoI find DrRacket sufficiently fast and sufficiently frustrating. It's very useful for interactive debugging but dependent on the mouse and many Emacs key combinations simply cannot be mapped because of it's CUA interface...and so far as I can tell there is no key-combination that switches focus between the REPL pane and the Editor pane short of closing the other pane. The syntax analysis gets to be a bit much too. On the other hand, that's just the price of an IDE over a text editor, and for a batteries included IDE, it's pretty good even if I wish that the effort would have been put into Emacs support while knowing that doing so would not meet the needs of the PLT group's target audience of students.
- SmileyKeith 12y agoI love the play by play of exactly what you're thinking as you're doing something new. I find them quite informative.
- brudgers 12y agoAs others have said, this does justice to the idea of actually learning a new language...or perhaps because it is Racket a new family or ecosystem of languages. Anyway, if you're still curious about pairs verus lists and why anyone would use dotted pairs, I like to think about it as where Lisps show that they are from the age when running close to the metal was a given. And it all goes back to car and cdr and the fact that they are (or rather were) embedded assembly language and there to give raw access to Lisp's linked memory model (as opposed to the sequential memory model of Fortran). A dotted pair has two efficiency advantages over a proper list and both stem from the fact that the last cell of the last pair of a proper list contains 'nil (or 'null in Racket). Storing two values in a proper list requires two cons cells - the first with the first value and a pointer to the second cons cell and a second cons cell containing the second value and a null pointer. In contrast, a dotted pair holds two values in a single cons cell - halving the memory requirement. The second advantage is that when there are only two values there's no need to walk the list and test for 'null (or 'nil) on the cdr. This saves an instruction step. Philosophically, dotted pairs allow for car and cdr to be used symmetrically. Calling cdr on a dotted pair returns the second value directly just as calling car on any list returns the first value directly. Lastly, one of the things that is awesome about Lisp is the way in which lists can model data structures, and in the case of a dotted pairs their efficiencies are available to all those structures which consist of or rely on paired values. Of course, this may be obvious and on a machine with 10+ GB of RAM not really applicable, but I find it fun to think about anyway.
- Sean-Der 12y agoIn some cases it makes more sense to store things as an a-list. A good example would be simple key->value pairs. When working with Hunchentoot it represents HTTP Headers and form POSTs as a-lists. It would be easier to use a hash table though.
- brudgers 12y agoI probably shouldn't have focused on data structures when talking about dotted pairs, but some days it's just hard to be a Lisp head... > (define (f g) ((car g)(cdr g))) > (define my-val (cons sqrt 4)) > (f my-val) 4 ...and go down the rabbit hole where code and data merge.
- deleted 12y ago[deleted]
- charlieflowers 12y agoWeb apps are a hack on a hack, yes. But it's kind of ironic he hates Javascript so much when Javascript is a pretty cool programming language heavily influenced by Scheme, which is awfully similar to Racket. But hey, I like people who call it like they see it, and there certainly are some drawbacks to Javascript too.
- ktg 12y agoJavascript is a pretty cool programming language heavily influenced by Scheme. -> I couldn't agree with you more. There is a Lisp-to-JS compiler (ParenJS). https://bitbucket.org/ktg/parenjs https://bitbucket.org/ktg/parenjs
- derengel 12y agoA friend of a friend has considerably code in Scheme, Common Lisp and Clojure, when you ask him which is the true Lisp, guess what will he answer? Haskell! Haskell does really create a big impact on some developers. Just an anecdote ;)
- dllthomas 12y agoI think it can't be "the true Lisp" without cleaner macros. Of course, that doesn't stop Haskell from being a great Haskell.
- TuringTest 12y agoHaskell is the algebra of programming - the way to handle code expressions as Immutable Truths. I suppose that makes Lisp the Principia Mathematica.
- Tyr42 12y agoI do prefer Racket macros to Template Haskell, but you can do some of the same kind of things in Template Haskell. Go ahead and play with it for it for a bit. Mostly, you need to have the data-structure it defines for the parse tree, and it's harder to convert than syntax->datum. Also there's the Q monad, to generate new safe names. But it works pretty well.
- dllthomas 12y agoI'm not sure there's anything you can't do in TH, but it feels messier than Lisp macros. I'm hoping typed TH will improve things (not in precisely the same direction as lisp, of course).
- nnq 12y agoThis sums up quite a lot about Lisps in general. I'm amazed OP got so fast to this "insight" :) (And this is probably Lisp's greatest weakness as well – with this level of possible diversity, everyone has to use the “common lowest denominator” simply because nobody can agree on what alternative syntax / library / etc. is better and should be used.) Off-topic: it's not enough to give everyone opportunity to improve the language; you have to choose the winners and promote them heavily. The rules of free market don't work here; people won't use the best thing, they'll use the one which is available out of the box and which is used by their peers.
- grn 12y agoThat's very true and I think that it's related to the topic of Rich Hickey's talk Simple Made Easy [1]. Maybe what we need is to study the economics of software and come up with a system in which market outcome is promotion of good libraries. I think that the social/economic dynamics of software development play a huge role in building a successful product, both free and commercial. Has anyone studied the subject in greater detail? [1] http://www.infoq.com/presentations/Simple-Made-Easy http://www.infoq.com/presentations/Simple-Made-Easy
- pavelludiq 12y agoAs a lisper, I can say that this insight is very true, but it is still just a simplification. Most lisps deal with it in different ways. In the scheme world, the way they deal with this is by wasting a decade on making decisions about the language that should have been done in the 80s. The result is that scheme essentially split into scheme and racket. Now we have an awesome language and a nice little ecosystem thats good for teaching and research, and possibly even real work(tm). Classic scheme unfortunately is fragmented into implementations who all do things slightly differently and occupy their own niches. In the clojure world, they have a) a BDFL who sets the course of the language. b) A very strong core community of very smart people who managed to build a nice culture based on common ideas about software and design. In the common lisp world, because we have a very high-quality standard, implementations are almost completely compatible. Compatibility libraries make it easy to write very portable code, avoiding the scheme problem. At the same time implementations are free to experiment. The other problem of everybody developing their own little universe tends to be rare. Because common lisp is so old, we have a long history and traditions that guide future design, but don't constrict it. There is a subtle balance here. We have a lot of old examples to learn from, but we are not locked in by too many bad old decisions(not always the case, but good enough in practice). A few examples where this does not work include utility libraries and things like json libraries, libraries for outputing html etc. Since we don't have a BDFL we are left to figure things out amongst our selves and sometimes, like with utility libraries(there are dozens such, which is ridiculus) it doesn't work. In other cases, it works very well, for example quicklisp, ASDF, bordeaux-threads, closer-mop, hunchentoot etc. are either de-facto standards, or sufficiently popular to be a very good default. As with clojure, there are a lot of common ideas about what is good design in the community, we have a lot of examples to learn from, as I mentioned. In the end, at least in the case of common lisp and clojure, I see it as an advantage to have this "level of possible diversity", it's what has kept lisp alive for 50+ years! The fact that lisp can adopt to each new era of software development philosophy is a great reason to study it. It will be with us for many more decades because of this.
- toolslive 12y agohe will be amazed when he discovers custodians. http://docs.racket-lang.org/reference/eval-model.html#%28part._custodian-model%29 http://docs.racket-lang.org/reference/eval-model.html#%28par...
- klibertp 12y agoThere are many cool features that Racket has out of the box, like very nice module system, delimited continuations, objects and classes and of course macros (both hygienic define-syntax-rule, syntax-case and unhygienic defmacro) and more. But if I had to show one feature of Racked to make someone amazed, it wouldn't be any of those. It would be a simple program composed of a couple of files, and every file would start with different #lang. Like #lang racket, #lang lazy, #lang typed/racket, #lang datalog. It's sufficiently mind-blowing that there are this many languages on top of Racket, but the real "killer app" is how seamlessly they integrate with each other. The next thing I'd show would probably be Danny Yoo tutorial on how you can create even more languages like this: http://hashcollision.org/brainfudge/ http://hashcollision.org/brainfudge/
- nextos 12y agoIt's almost like a practical Mozart/Oz with all Lisp awesomeness. CTM shows how programming with many different paradigms can be extremely powerful.
- JimmyM 12y agoThis is how I usually implemented quicksort in Racket: (define (quicksort xs) (if (null? xs) xs (let* ([hd (car xs)] [tail (cdr xs)] [smaller (filter (lambda (x) (< x hd)) tail)] [bigger (filter (lambda (x) (>= x hd)) tail)]) (append (quicksort smaller) (list hd) (quicksort bigger)))) It's great to see a hugely superior implementation, and I love that people are writing about and using Racket like this because the more people do that the more resources there will be for people like me to learn from.
- deleted 12y ago[deleted]
- nextos 12y agoI love Scheme. And I love Clojure, which is IMHO Scheme plus some great ideas from Haskell. I regret there's no Scheme or Clojure running on LLVM, which I think is a much better platform than the JVM. Julia, that resembles Dylan (another Lisp), is the perfect example.
- saosebastiao 12y agoI too wish there was such a thing as a JIT compiled Clojure on LLVM. The JVM is amazing but it only seems to be amazing for long running processes. LLVM, IMO, is far more versatile in its amazingness.
- pjmlp 12y agoThere was an attempt at it, https://github.com/halgari/clojure-metal https://github.com/halgari/clojure-metal
- ihnorton 12y agoNot sure what Lisp family it compares to, but there is Hylas: https://github.com/eudoxia0/Hylas-Lisp https://github.com/eudoxia0/Hylas-Lisp
- gambogi 12y ago"Someone who knows Haskell learns some Racket" "Tonight at 11: this rose gardener learns to plant tulips"
- artyomkazak 12y agoWhich is exactly why I was very surprised when it got posted to Reddit and wasn't immediately downvoted.
- gambogi 12y ago"Someone who knows Haskell learns some Racket" "Tonight at 11: this rose gardener learns to plant tulips"
- kenko 12y agoIt seems as if several of the author's problems come, oddly for someone who's used both strict (Pascal) and non-strict (Haskell) langauges, from being confused about Racket's strictness. Why is time a special form? Because otherwise (time (expensive)) would just get the result of (expensive). Why doesn't (list 1 (2 3) 4) work? Because list isn't a special form, it's a function. Why doesn't quote turn '(list 1 2 3) into '(1 2 3)? (Well, this one isn't about evaluation order, admittedly.) Because if it did it ... wouldn't be quote.
- artyomkazak 12y agoPascal is strict, but it still has stuff like “move(var1, var2)”, out parameters, etc., so it's also call-by-reference. I didn't know at the time that Racket was call-by-value. Quote was confusing at first, yes.