{"comment":{"created_at":"2011-10-24T19:26:37Z","body":"Literate CoffeeScript\r\nI have added an alternative way to express that a script is Literate CoffeeScript. If the script starts with the line: “Literate CoffeeScript”, as does this comment, it is considered to be Literate CoffeeScript, regardless of the file extension.\r\n\r\nI did this because there is no chance that these two tokens will start a valid CoffeeScript program, yet they add a lot of beauty and rhetorical fluidity (as preamble) to the code. In fact, I think that even if that particular test is rejected from the code, the convention should be that Literate CoffeeScript start out as did this comment. (And we all know that code conventions are just missing compiler features.)\r\nIt also helps tools like file(1) to make positive identifications of Literate CoffeeScript files.\r\n\r\nSo, there it is.\r\n\r\n```coffeescript\r\n  console.log 'Merge me!'\r\n```\r\n\r\nI just had to put that there because I can, and you cannot stop me, and this comment will still compile. :-p","updated_at":"2011-10-24T19:26:37Z","url":"https://api.github.com/repos/jashkenas/coffee-script/issues/comments/2508130","id":2508130,"user":{"avatar_url":"https://secure.gravatar.com/avatar/929d7473528dcb46152c15a4160ff345?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"929d7473528dcb46152c15a4160ff345","url":"https://api.github.com/users/revence27","id":915566,"login":"revence27"}},"action":"created","issue":{"number":1786,"created_at":"2011-10-21T12:17:47Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"This file, as it is, has been taken from `tests/literate.literatecoffee` in my fork.\r\nWithout making any changes to it whatsoever, it is valid literate CoffeeScript, if you just copy and paste it into an editor, and make my fork of CoffeeScript run on it. Make the file end in `.literatecoffee` to make it go into literate mode.\r\nI wonder if Mr. Jeremy Ashkenas thinks it is a good idea. It would be good to know, before I send a pull request. (*Oops!* Earlier pull request for binary literals was pending, and it subsumed this one. Oh, well.)\r\nThe change is only one line in only one file, and it is bound to be faster than fast in use. It is in my commit revence27/coffee-script@132d306e3391182dc2c410b9c46251d476e74c3f with an accompanying modification (different commit) of the `Cakefile`, that it may look for `.literatecoffee` files in the tests.\r\n\r\nThis, of course, is inspired by the Haskell programming language, but it is neater that the Haskell version of literate programming.\r\n\r\nBeautiful Literate Programming\r\n========================\r\n\r\nIf this file parses at all, that is the test, and it has passed.\r\n\r\nOriginally, literate programming did not mean heavily-commented code. However, owing to the System, that is what it evolved to mean.\r\nLiterate programming is supposed to be where code invades the commentary, not lots of comments invading the code.\r\n\r\n```coffeescript\r\n  test \"If this parses, literate coffee works.\", ->\r\n    eq 'So beautiful, I want to cry.', 'So beautiful, I want to cry.'\r\n```\r\n\r\nUnder this scheme, everything is a comment.\r\nExcept the bits that are indented. If a line does not start with whitespace, it is a comment.\r\nEverything else is code.\r\n\r\n```coffeescript\r\n  test \"I parse, therefore I work.\", ->\r\n    eq 4, 100 - 96\r\n```\r\n\r\nThis is how we shall proceed with writing a string reverse in CoffeeScript.\r\n\r\n```coffeescript\r\n  reverse = (str) ->\r\n    rez = ''\r\n    for chr in str\r\n      rez = chr + rez\r\n    rez\r\n```\r\n\r\nAnd then we will use it.\r\n\r\n```coffeescript\r\n  test \"Using a function defined within literate CoffeeScript.\", ->\r\n    eq 'So beautiful, I want to cry.', reverse '.yrc ot tnaw I ,lufituaeb oS'\r\n```\r\n\r\nSee? Wasn't ugly, was it?\r\nWork on a syntax mode should not be difficult, in my opinion. (Although the only\r\nsyntax things I know how to do are Vim, and even those, not *too* perfectly.)\r\nThat will be all.","comments":20,"title":"Literate CoffeeScript","updated_at":"2011-10-24T19:26:37Z","url":"https://api.github.com/repos/jashkenas/coffee-script/issues/1786","id":2014815,"assignee":null,"milestone":null,"closed_at":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/929d7473528dcb46152c15a4160ff345?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"929d7473528dcb46152c15a4160ff345","url":"https://api.github.com/users/revence27","id":915566,"login":"revence27"},"html_url":"https://github.com/jashkenas/coffee-script/issues/1786","labels":[{"name":"enhancement","url":"https://api.github.com/repos/jashkenas/coffee-script/labels/enhancement","color":"84b6eb"}],"state":"open"},"legacy":{"issue_id":2014815,"comment_id":2508130}}