Literate CoffeeScript

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Literate CoffeeScript

Owen Densmore
Administrator
(This may be a bit odd for some of us, but I wanted to pass on a novel innovation)

The latest release of coffeescript has a new Literate "mode": if you use the extension .litcoffee it is also treated as markdown!  This is a modern extension to Knuth's Literate Programming:
  http://www-cs-faculty.stanford.edu/~uno/lp.html

This is likely brought about by the coffeescript docco documentation tool, but now integrated into the coffeescript compiler.  

I've been imbedding markdown in agentscript for docco use once the project "got real".  You can see it here:
I wasn't sure initially, but now am entirely sold on the approach.  For one thing it has been invaluable for discussing the project with other programmers wishing to modify the code.

The literate coffeescript announcement is here, with links showing the source in various formats:

As odd as it may seem, I recommend use of similar stunts in all languages that support it.  Knuth has quite a following in this area.  The idea of markdown comments certainly has a lot of traction.

( Now back to our scheduled .. er.. programming! :)

   -- Owen

Literate CoffeeScript

Besides being used as an ordinary programming language, CoffeeScript may also be written in "literate" mode. If you name your file with a .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler will treat any indented blocks (Markdown's way of indicating source code) as code, and ignore the rest as comments.

Just for kicks, a little bit of the compiler is currently implemented in this fashion: See it as a documentraw, and properly highlighted in a text editor.

I'm fairly excited about this direction for the language, and am looking forward to writing (and more importantly, reading) more programs in this style. As 1.5.0 is the first version of CoffeeScript that supports it, let us know if you have any ideas for improving the feature.






============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Marcus G. Daniels
So sad, and so unnecessary..

https://github.com/faylang/fay/wiki
http://www.haskell.org/haskellwiki/Literate_programming


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://link.mail2web.com/mail2web



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Russ Abbott
Haskell is a wonderful language. But it is (obviously) functional, which means no side effects. The primary purpose of a language like JavaScript is to produce side-effects that change the DOM and what is displayed by a browser. How does Fay get around that seeming incompatibility in objectives?

 
-- Russ Abbott
_____________________________________________
  Professor, Computer Science
  California State University, Los Angeles

  My paper on how the Fed can fix the economy: ssrn.com/abstract=1977688
  Google voice: 747-999-5105
  CS Wiki and the courses I teach
_____________________________________________ 



On Mon, Feb 25, 2013 at 12:11 PM, [hidden email] <[hidden email]> wrote:
So sad, and so unnecessary..

https://github.com/faylang/fay/wiki
http://www.haskell.org/haskellwiki/Literate_programming


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://link.mail2web.com/mail2web



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Marcus G. Daniels
In reply to this post by Owen Densmore
Russ wrote:

"But it is (obviously) functional, which
means no side effects. The primary purpose of a language like JavaScript is
to produce side-effects that change the DOM and what is displayed by a
browser. How does Fay get around that seeming incompatibility in
objectives?"

Haskell deals with side-effects using Monads.  Las Vegas is like a Monad:
"What happens in Vegas, stays in Vegas."   The idea is your DOM would be an
opaque type that could be returned by a function, but its state is not
revealed.  In this way, there are no side effects outside of the global
object that is returned.

http://hackage.haskell.org/package/fay-dom
http://www.haskell.org/haskellwiki/Monad

--------------------------------------------------------------------
myhosting.com - Premium Microsoft® Windows® and Linux web and application
hosting - http://link.myhosting.com/myhosting



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Russ Abbott
That's fine, but it seems strange to promote a language because one of its features lets you work around its primary objective.

 
-- Russ Abbott
_____________________________________________
  Professor, Computer Science
  California State University, Los Angeles

  My paper on how the Fed can fix the economy: ssrn.com/abstract=1977688
  Google voice: 747-999-5105
  CS Wiki and the courses I teach
_____________________________________________ 



On Mon, Feb 25, 2013 at 2:44 PM, [hidden email] <[hidden email]> wrote:
Russ wrote:

"But it is (obviously) functional, which
means no side effects. The primary purpose of a language like JavaScript is
to produce side-effects that change the DOM and what is displayed by a
browser. How does Fay get around that seeming incompatibility in
objectives?"

Haskell deals with side-effects using Monads.  Las Vegas is like a Monad:
"What happens in Vegas, stays in Vegas."   The idea is your DOM would be an
opaque type that could be returned by a function, but its state is not
revealed.  In this way, there are no side effects outside of the global
object that is returned.

http://hackage.haskell.org/package/fay-dom
http://www.haskell.org/haskellwiki/Monad

--------------------------------------------------------------------
myhosting.com - Premium Microsoft® Windows® and Linux web and application
hosting - http://link.myhosting.com/myhosting



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Marcus G. Daniels
In reply to this post by Owen Densmore
"That's fine, but it seems strange to promote a language because one of its
features lets you work around its primary objective."

Nope.  Monads are a purely functional construct.  A elegant generalization,
Arrows, enable one to construct Unix-style pipelines, but with typed
contracts.  That is, imagine having a command shell that rejected as bad
syntax pipelines where the data of the consumer and producer did not make
sense together.  

Marcus

--------------------------------------------------------------------
myhosting.com - Premium Microsoft® Windows® and Linux web and application
hosting - http://link.myhosting.com/myhosting



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

glen ropella
[hidden email] wrote at 02/25/2013 02:57 PM:
> Nope.  Monads are a purely functional construct.  A elegant generalization,
> Arrows, enable one to construct Unix-style pipelines, but with typed
> contracts.  That is, imagine having a command shell that rejected as bad
> syntax pipelines where the data of the consumer and producer did not make
> sense together.

You mean I wouldn't be allowed to listen to the smooth sounds of:

echo "main(t){for(t=0;;t++)putchar(t*((t>>9|t>>13)&25&t>>6));}" | gcc
-xc - && ./a.out | aplay

--
=><= glen e. p. ropella
You gotta help me, help me to shake off


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Marcus G. Daniels
On 2/25/13 5:31 PM, glen wrote:

> [hidden email] wrote at 02/25/2013 02:57 PM:
>> Nope.  Monads are a purely functional construct.  A elegant generalization,
>> Arrows, enable one to construct Unix-style pipelines, but with typed
>> contracts.  That is, imagine having a command shell that rejected as bad
>> syntax pipelines where the data of the consumer and producer did not make
>> sense together.
> You mean I wouldn't be allowed to listen to the smooth sounds of:
>
> echo "main(t){for(t=0;;t++)putchar(t*((t>>9|t>>13)&25&t>>6));}" | gcc
> -xc - && ./a.out | aplay
Here's an example taken from YampaSynth, a domain-specific language for
sound synthesis built using the concepts of Functional Reactive
Programming.  The pipeline is all in Haskell, all the way to the OpenAL
output.  (No cheating with an external command line program.)

http://www.haskell.org/haskellwiki/Arrow
http://www.cs.rit.edu/~eca7215/frp-independent-study/Survey.pdf
http://www.haskell.org/haskellwiki/Yampa
http://hackage.haskell.org/package/YampaSynth

Here's a couple sounds.  `scifi' is a whirly-gig sort of sound, and
`scale' is just a set of sequential notes.
{-# LANGUAGE Arrows #-}

module Main where

import qualified SynthBasics as Synth
import qualified Data.Audio as Audio
import Player.OpenAL (play)
import FRP.Yampa

sciFi :: SF () Audio.Sample
sciFi = proc () -> do
   und   <- arr (*0.2) <<< Synth.oscSine 3.0  -< 0
   swp   <- arr (+1.0) <<< integral     -< -0.25
   audio <- Synth.oscSine 440           -< und + swp
   returnA -< audio

envBell :: SF (Event ()) (Synth.CV, Event ())
envBell = Synth.envGen 0 [(0.05,1),(1.5,0)] Nothing

bell :: Synth.Frequency -> SF () (Audio.Sample, Event ())
bell f = proc () -> do
   m            <- Synth.oscSine (2.33 * f)  -< 0
   audio        <- Synth.oscSine f           -< 2.0 * m
   (ampl, end)  <- envBell           -< noEvent
   returnA -< (audio * ampl, end)

scale :: SF () (Audio.Sample, Event ())
scale =  (  afterEach  [  (0.0, 60), (1.0, 62), (1.0, 64),
                           (1.0, 65), (1.0, 67), (1.0, 69),
                           (1.0, 71), (1.0, 72)]
             >>>  constant ()
                  &&& arr (fmap (\k -> (bell $ toFreq k) >>> arr fst))
             >>> rSwitch (constant 0))
          &&& after 8 ()

toFreq :: Int -> Double
toFreq n = 440.0 * (2.0 ** (((fromIntegral n) - 69.0) / 12.0))

main :: IO ()
main = do
   let playIt = play 44100 50000 1
   -- playIt (sciFi &&& after 5 ())
   playIt scale
   return()


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Marcus G. Daniels
In reply to this post by glen ropella
On 2/25/13 5:31 PM, glen wrote:
> You mean I wouldn't be allowed to listen to the smooth sounds of: echo
> "main(t){for(t=0;;t++)putchar(t*((t>>9|t>>13)&25&t>>6));}" | gcc -xc -
> && ./a.out | aplay

I should not let this slip-by without acknowledging that this is a
functional program.  +1 for that!

Marcus

============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Barry MacKichan
In reply to this post by Owen Densmore
Very interesting.

I have been using Docco to document a project in JavaScript, and this is an interesting enhancement.

Embedding code in documentation was only half of Knuth's Web (Wow! This dates back to when the word 'web' had no other meaning in software). The part I don't see is the macro expansion that Knuth used. Is this implemented, or is the feeling that it is the wrong thing to use with modern languages?

Also, does it apply markdown or multi markdown; the latter has support for math and footnotes, etc. I would guess it is configurable.

Do you know if the screenshot in http://cl.ly/LxEu is of Sublime Text 2? If so, is a special package required, or are they using the CoffeeScript package?

I know I could look all of this up, but I'm hoping you could save me some time. Also, the answers could be useful to others on this list.

--Barry

On Feb 25, 2013, at 11:03 AM, Owen Densmore <[hidden email]> wrote:

(This may be a bit odd for some of us, but I wanted to pass on a novel innovation)

The latest release of coffeescript has a new Literate "mode": if you use the extension .litcoffee it is also treated as markdown!  This is a modern extension to Knuth's Literate Programming:
  http://www-cs-faculty.stanford.edu/~uno/lp.html

This is likely brought about by the coffeescript docco documentation tool, but now integrated into the coffeescript compiler.  

I've been imbedding markdown in agentscript for docco use once the project "got real".  You can see it here:
I wasn't sure initially, but now am entirely sold on the approach.  For one thing it has been invaluable for discussing the project with other programmers wishing to modify the code.

The literate coffeescript announcement is here, with links showing the source in various formats:

As odd as it may seem, I recommend use of similar stunts in all languages that support it.  Knuth has quite a following in this area.  The idea of markdown comments certainly has a lot of traction.

( Now back to our scheduled .. er.. programming! :)

   -- Owen

Literate CoffeeScript

Besides being used as an ordinary programming language, CoffeeScript may also be written in "literate" mode. If you name your file with a .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler will treat any indented blocks (Markdown's way of indicating source code) as code, and ignore the rest as comments.

Just for kicks, a little bit of the compiler is currently implemented in this fashion: See it as a documentraw, and properly highlighted in a text editor.

I'm fairly excited about this direction for the language, and am looking forward to writing (and more importantly, reading) more programs in this style. As 1.5.0 is the first version of CoffeeScript that supports it, let us know if you have any ideas for improving the feature.





============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

glen ep ropella
In reply to this post by Marcus G. Daniels
Marcus G. Daniels wrote at 02/25/2013 09:19 PM:
> Here's an example taken from YampaSynth, a domain-specific language for
> sound synthesis built using the concepts of Functional Reactive
> Programming.  The pipeline is all in Haskell, all the way to the OpenAL
> output.  (No cheating with an external command line program.)
>
> http://www.haskell.org/haskellwiki/Arrow
> http://www.cs.rit.edu/~eca7215/frp-independent-study/Survey.pdf
> http://www.haskell.org/haskellwiki/Yampa
> http://hackage.haskell.org/package/YampaSynth

VERY nice!  That's the coolest and most useful thing I've learned this
year.  Thanks.

Marcus G. Daniels wrote at 02/25/2013 09:21 PM:> On 2/25/13 5:31 PM,
glen wrote:
>> "main(t){for(t=0;;t++)putchar(t*((t>>9|t>>13)&25&t>>6));}" | gcc -xc
>> - && ./a.out | aplay
>
> I should not let this slip-by without acknowledging that this is a
> functional program.  +1 for that!

I'm still ashamed I couldn't find a way to execute the a.out content to
a pipe without saving it to disk. 8^(

--
glen e. p. ropella, 971-255-2847, http://tempusdictum.com
Fear is the main source of superstition, and one of the main sources of
cruelty. To conquer fear is the beginning of wisdom. -- Bertrand Russell


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Marcus G. Daniels
In reply to this post by Owen Densmore
Microsoft's take on reactive programming, LINQ-style.  
(Includes a JavaScript implementation, among others..)

  http://rx.codeplex.com/

And Netflix's Java implementation

  http://techblog.netflix.com/search/label/FRP
  https://github.com/Netflix/RxJava


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://link.mail2web.com/mail2web



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com
Reply | Threaded
Open this post in threaded view
|

Re: Literate CoffeeScript

Barry MacKichan
In reply to this post by Barry MacKichan
Since I asked the questions on this list, and now have the answers, I might as well send them back to the list.
On Feb 26, 2013, at 9:24 AM, Barry MacKichan <[hidden email]> wrote:

Embedding code in documentation was only half of Knuth's Web (Wow! This dates back to when the word 'web' had no other meaning in software). The part I don't see is the macro expansion that Knuth used. Is this implemented, or is the feeling that it is the wrong thing to use with modern languages?

No macro expansion. It was a long shot anyway.
Also, does it apply markdown or multi markdown; the latter has support for math and footnotes, etc. I would guess it is configurable.

Duh. The markdown file *is* the source, so if you use markdown, you look at the source with a markdown processor; if you want to use multi markdown, you look at the source with a multi markdown processor.
Do you know if the screenshot in http://cl.ly/LxEu is of Sublime Text 2? If so, is a special package required, or are they using the CoffeeScript package?

The screenshot is evidently of TextMate. Ashkenas fixed up his TextMate CoffeeScript package which is trivially adapted to Sublime Text 2.

============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
to unsubscribe http://redfish.com/mailman/listinfo/friam_redfish.com