Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Beautiful Racket (beautifulracket.com)
225 points by samth on March 4, 2016 | hide | past | favorite | 53 comments


One of my favorite classes in college was designed around building a C-like language interpreter (not compiler, I know, but the syntax was C-like) in Racket. It was a fantastic, eye-opening experience.

However, DrRacket the IDE was a huge pain for me. I often felt that what the language offered in power and sophistication, its development environment lacked.


I haven't used DrRacket for anything of any reasonable size, but I actually think it does pretty well. I was just asking some people on #racket about if DrRacket suites their needs for a development environment. I think it's interesting that a good number of Racket developers use DrRacket instead of emacs or vim, whereas other Lisps tend to favor (especially) emacs and vim.

So my question is: What about DrRacket didn't seem like enough for your project?


I'm not who you're asking the question to, but I dislike DrRacket because (when I used it last year) it took too long to load (iirc, intellij started up faster and they have to support a lot more features)


The IDE i use (phpstorm) - i load it once, and it just sits in the background until i restart or logout. I can't see how load time is really a big deal? unless you're talking 5+ min?


It takes ~5 seconds on my macbook pro with just the standard set of tools installed.


I normally close my programs when I'm not using them, out of habit


You can run racket as a console application and it can be run through emacs or standalone with any editor.


For sure -- but the class was taught using the IDE and it's what everybody ended up using. I felt kinda stuck with it.


The problem I faced was scrolling lags. I've heard it got much better with 6.3/6.4 release. Otherwise, it was pretty cool that you can see how data flows through your functions by just hovering mouse over identifiers, or see the coverage.


> If a datum sounds like a syn­tax object, that’s no coin­ci­dence — a syn­tax object is just a datum with some extra infor­ma­tion attached. The #' pre­fix nota­tion we used for a syn­tax object now con­nects log­i­cally: we can think of the # as rep­re­sent­ing the extra info that gets attached to the datum

This is not clear, can someone explain please?


Not sure which part isn't clear.

First, syntax objects are data, but with extra information, such as binding information, source location, etc.

Second, the #' form (written out it's called `syntax`) is similar to the ' form (written out as `quote`). But the first one includes the extra information to make a syntax object. Also, it has an extra character, which the chapter points out can be seen as going along with the extra information.


This is why I wish I could ask comments about books without going to Stack Overflow. Is there a publishing system that allows you to put up a work as it is being produced and solicit input from people on what they find unclear?


Gitbook. I've used it for two small (unpublished) books.

https://www.gitbook.com/

E:

I may have misparsed your question, upon re-reading it and had an overly liberal understanding of "solicit feedback". Apologies in advance if my answer isn't quite up the alley you were looking for.


The book Real World Haskell was written using such a system. I don't know what system they used, though. It let you attach comments to a specific paragraph.


I've bought a couple of books on the manning early access program and been very satisfied

https://www.manning.com/meap-program


Leanpub.con It integrates with git and is pretty simple to use.


Got it, thanks!


This is the only time I've heard "datum" used outside the context of GIS.


Datum is the singular of data.


In Latin. In English "data" is a mass noun. Nobody really says "data are" unless they're writing an academic paper.


The singular of data would be a 1, to be pedantic.

Edit: Information is uncountable, so maybe data should as well be. Is that plural or singular? Yes, you can have sand and a grain of sand, but the grain is hardly sandy. A lone 1 is hardly, excuse the pun, dative.


'data' comes from latin, and 'data' is plura.

the singular is 'datum'.

In Italian (the direct descendent of latin) there is both singular and plural for datum (singular: 'dato', plural: 'dati')


that's totally ignoring what I said. I hope you feel smug about it.

Edit: Interestingly, wiktionary says informations is just uncommon, and that information is not data, it's the meaning of data, in the computing context. ... with source. It links to a paper about an ISO standard, no less, that tries to define vocabulary and happens to use data as singular. Document Reader [is a] Character reader whose input data is the text from specific areas on a given type of form [1]. (This makes me so happy right now.)

Overall, if it's a technical term they invented, the authors are free to name their language construct whatever they want. But if it's so fudged that the author even writes datums ... I rest my case.

[1] https://www.iso.org/obp/ui/#iso:std:iso-iec:2382:ed-1:v1:en


This looks like a very well-written, easy introduction to making simple, dynamic programming languages (not surprising given the author's writing background).

But everyone writes about how to build these kinds of basic Forths, or Lisps, or reverse polish notation calculators. To be honest, once you've learned the basic technique, writing a toy dynamic language interpreter is pretty easy. Even adding a toy JIT isn't very hard, and there are multiple guides online on how to do this using Luajit, or Libjit, PyPy, or LLVM, etc.

What I want more than anything is a guide written on the same level on how to build a toy statically-typed language, with algebraic data types. And even better, some basic discussion on how to learn about implementing advanced techniques like refinement, or linear, or dependent types (I realize these are extremely complex topics).

Every discussion I find on these topics is in dense academic papers. I'm slowly making headway, but it's a slog.

The only good resource I've found so far (and it's an excellent one) is Andrej Bauer's Programming Languages Zoo. But as far as I know, it's all (very helpful and instructive) source code, with no accompanying tutorials.

Is there no very simple introduction on writing a simple ML, with type checking? Any recommended resources?

It's possible that Butterick intends to cover these topics in later chapters, in which case I can't wait to read the book.


These should get you started. The last two are by Simon Peyton Jones, one of the creators of Haskell.

One Hour ML https://vimeo.com/64593770

Algorithm W Step by Step http://catamorph.de/documents/AlgorithmW.pdf

Implementing functional languages http://research.microsoft.com/en-us/um/people/simonpj/Papers...

The Implementation of Functional Programming Languages http://research.microsoft.com/en-us/um/people/simonpj/Papers...


Oh, those are great, thanks. Not big on videos, but the Algo W pdf is great, and the last book is exactly what I need, and looks to answer some of the questions I'm running into doing this on my own (3rd one looks a little advanced for me at this point, maybe after I get through the Peyton Jones textbook).


Pierce's Types and Programming Languages ( https://www.cis.upenn.edu/~bcpierce/tapl/ ) is great - I'm working throught it now. Its goes through both untyped and statically typed languages. It also goes into how to implement these things in OCaml.


Yeah, I think I'm going to have a break down and shell out the dough for Types and Programming Languages. It's exactly what I need now.


I belive this is trying to fill that niche: http://dev.stephendiehl.com/fun/


> What I want more than anything is a guide written on the same level on how to build a toy statically-typed language, with algebraic data types.

The answers here might be useful: http://stackoverflow.com/questions/12532552/what-part-of-mil...

> Is there no very simple introduction on writing a simple ML, with type checking? Any recommended resources?

I'd recommend reading A. Field, P. Harrison, "Functional Programming". Despite the title, the book is about implementation techniques.

P.S. I keep suggesting to everyone interested in implementing type systems to use a very simple technique: find an embeddable Prolog compiler for your language of choice (e.g., MiniKanren for Racket), and then simply emit a flat list of Prolog equations out of your source language AST (do the lexical scoping pass first). Easy. And easily extendable to dependent typing and all that fancy stuff.


"find an embeddable Prolog compiler for your language of choice (e.g., MiniKanren for Racket), and then simply emit a flat list of Prolog equations out of your source language AST (do the lexical scoping pass first). Easy. And easily extendable to dependent typing and all that fancy stuff."

So, you represent the AST associations and type-checks as Prolog logic rules that operate on predicates describing the AST? And the inference engine runs through it to dump out true or false for various predicates and rules? Am I understanding it right?

Also, didn't realize Prolog could handle dependent types and such. That's neat to know.


For example, you have an AST node for 'x + 2', encoded as 'apply(apply(var("+"), var("x")), const("2"))' (we're talking about ML, so it is curried here).

Firstly, all the expression nodes must be annotated with type tags: 'A1:apply(A2:apply(A3:var("plus"),A4:var("x")), A5:const("2"))'.

Then your typing pass walking over this segment of AST would generate the following (mostly trivial) equations

    A5=integer  // from constant type
    A4=Vx

    A3=Vplus
    A3=fun(integer, fun(integer, integer)) // from environment lookup
    A3=fun(V1, A2) // application rule
    A2=fun(V2, A1) // application rule

Then this long Prolog query (all equations are comma separated) is executed and you'll get all An type values to attach to your AST, as well as variable x type.

> Prolog could handle dependent types

It's Turing-complete. You can encode anything you want in it.


You've sent me way down the rabbit hole here. I'm going back and reviewing Prolog for the first time in years (at least the syntax isn't strange since I've been using Erlang recently).

I don't quite understand this phrase "you'll get all An type values to attach to your AST". Do you just mean "all type values" or is "An type" a technical term?


Sorry for a confusing wording. I was referring to the newly generated tag variables A1, A2, ..., An. The next typing pass after solving the equations is to substitute those tags with the type values found by Prolog.


Ah perfect, thanks.

This whole thread has been a huge boon to me, very glad for all the input.


I think they meant you'll get the type for A1, A2 etc.


"Then your typing pass walking over this segment of AST would generate the following (mostly trivial) equations"

Thanks for the example. That does seem straight-forward.

"It's Turing-complete. You can encode anything you want in it."

The reason I mention it is that many people doing proofs and such specifically avoid first-order logic in favor of HOL or Coq. They sometimes mention FOL is too limited or you have to go out of your way for what they're doing. Not specialist enough to have figured out what they're talking about. There appears, though, to be some cutoff point where one is better off using HOL-style tools for analysis, proof, synthesis, whatever. Wish I had references on-hand if it's not clear already what I'm talking about.


Are you looking for general references on implementing type checkers and ML-like languages? Or how to implement those as languages in Racket specifically?


Either or any would be great, particularly if they're online and not books (although I'd buy a good book that covered those topics in depth).

Particularly an approachable intro to Hindley-Milner and building a toy/mini-ML, and type checking in general. All the better if it's in Racket, or some ML.

Actually, do you know of any examples of ML-type languages, or any statically-typed languages, that are written in Racket, aside from Typed Racket itself? Is looking at the Typed Racket code instructive? (I should just take a look)


There is a simple ML-like language implemented in Racket, called plai-typed, which is used by some people for teaching the PLAI programming language book. You can see the implementation here: https://github.com/mflatt/plai-typed


It looks like Pyret was first written in Racket. I think it's optionally typed, though.

https://github.com/brownplt/pyret-lang-resugarer


As the sibling comment mentions, Pyret was originally written in Racket. It's now self-hosted, and I'm working on rewriting the typechecker so if you want I can answer questions about that. The current development is all done on https://github.com/brownplt/pyret-lang



That is quite a broad and instructive project, very interested to see the Prolog type checking you describe below in action. Thanks!


Not the tutorial form you probably want but I've had this bookmarked, it may be interesting:

http://www.cse.chalmers.se/edu/year/2015/course/DAT150/ http://www.cse.chalmers.se/edu/year/2015/course/DAT150/lectu...


I have a compile-to-Racket implementation of a Pascal subset here:

https://github.com/soegaard/minipascal

There are two versions. The first one

    https://github.com/soegaard/minipascal/blob/master/minipascal/compiler-simple.rkt
is without typechecking. The second one adds a type checker:

https://github.com/soegaard/minipascal/blob/master/minipasca...


There was a great textbook by Sam Kamin around 1990 (http://loome.cs.uiuc.edu/kamin/pubs.html). I think that might help.


There is also an abandoned book on implementing Scheme by Paul Wilson:

ftp://ftp.cs.utexas.edu/pub/garbage/cs345/schintro-v14/schintro_toc.html

Yes, an ftp url.


Thanks, looks like a very good book, but looks to focus mainly on dynamic languages, no?



Do you find "Types and Programming Languages" to be a slog?


I've not yet wanted to shell out for Types and Programming Languages in the hopes of finding something online, but given that it covers exactly what I need at this moment, I'll probably go ahead and buy it. And no, excerpts from Pierce I've looked at in the past looked perfect for my level.

That said, the old Peyton Jones textbook that was referenced above looks pretty interesting. Might work through that one before I buy Types and Programming Languages.


This is the only sane way to reduce complexity in your programs.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: