Literate programming (A Python frontend for noweb)

82 views
Skip to first unread message

Dilawar

unread,
Oct 29, 2013, 1:28:10 AM10/29/13
to wncc...@googlegroups.com

The idea of literate programming -- a program can be a piece of literature -- is due to Donald E. Knuth who is extremely respected figure in programming community (and also among combinatorics and computer science people). In this paradigm, one does not write a program based on how computer would reason about it but rather follows a human-like flow. It is the job of literate programming tool to convert this human-readable program into something which make sense to a computer. Since the translation process is governed by a computer program, there are specific constraints on how to write a program in literate way.

Best way to understand the difference is to look at a literate program. One can find many. A program is written like an essay, and one then uses a tool to extract code (this process was called tangling by Knuth) or documentation (weaving) out of it. Knuth, true to his nature, wrote cweb for his personal use and used in this personal work. Other used it if they liked. Some other tools cropped up and many of them were written for pacific languages. Noweb, written by Roman Ramsay, is language agnostic. There are some other tools like it e.g. funnel-web, nuweb etc but none is as simple to use as this one. Lyx also have support for noweb. And if my memory serves me write, IIT Madras, offered (or still offering) a course in literate programming to its students using Lyx.

Literate programming did not really catch up (who wants to write documentation in the first place). But some people have used it extensively. To my knowledge, apart from Knuth, Columbia Esterel Compiler (cec) is written as literate program using noweb and its really easy to understand. I myself have made some changes to it for personal use.

THIS IS FOR INTERMEDIATE USERS OF NOWEB (IF ANY) :

This python font-end introduces two more features to noweb by extending its markup language. You don't have to write a single noweb file for full program; it can be divided into many others file and can be included using %\include{file.nw} switch. Moreover, one needs specify from command line which chunck to be written to which file, this can now be embeded inside the literate file. Just write over the chunk something like %file:src/file.c. % is a comment in tex file therefore it does not introduce error in noweb which simply ignores it. For example if a chunk named `gloabal.h` is to be written to file `include/global.h` then, just above the chunk `<<global.h>>`, you must have
   %file:include/global.h
   <<global.h>>=
   // whatver is there in global
   @ %def global.h 


--
Dilawar
NCBS/IITB

Prashant Sohani

unread,
Oct 30, 2013, 7:32:56 AM10/30/13
to wncc...@googlegroups.com
Haha.. nice, I had myself tried my hand at trying to create a 'Natural C' (or 'C natural' , for a more punny resemblance to C sharp, haha ). Attached are the results.

start
  create a string called name
  create an int called age
  do
    print "Hello! What is your name?\n"
      ask name
      print "What is your age?\n"
      ask age
      if 18 exceeds age
        then print "Sorry " << name << ", you cannot vote!\n"
        otherwise print "Congrats " << name << ", maybe you can vote!\n"
      endif

    print "Try again? Y/N\n"
    ask name
  while name is exactly "Y" or name is exactly "y"
  donewhile
finish



--
--
The website for the club is http://stab-iitb.org/wncc
To post to this group, send email to wncc...@googlegroups.com
 
---
You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Untitled1.cpp
naturalC.h

Dilawar Singh

unread,
Oct 30, 2013, 8:15:33 AM10/30/13
to wncc...@googlegroups.com
That is interesting but it may not be work well on English language (lot of
inconsistencies in grammar of language). These people are doing somewhat similar
on Hindustanti language http://hindawi.in/en_US/about_hindawi.php

It would be a great idea to have xterm-devnagiri or rxvt-devnagiri.
Unfortunately, on rxvt-unicode, Hindi does not render well. It will be quite a
work. Anyone enthusiastic?

--
Dilawar
NCBS Bangalore
EE, IIT Bombay
On Wed, Oct 30, 2013 at 05:02:56PM +0530, Prashant Sohani wrote:
>Haha.. nice, I had myself tried my hand at trying to create a 'Natural C'
>(or 'C natural' , for a more punny resemblance to C sharp, haha ). Attached
>are the results.
>
>start
> create a string called name
> create an int called age
> do
> print "Hello! What is your name?\n"
> ask name
> print "What is your age?\n"
> ask age
> if 18 exceeds age
> then print "Sorry " << name << ", you cannot vote!\n"
> otherwise print "Congrats " << name << ", maybe you can vote!\n"
> endif
>
> print "Try again? Y/N\n"
> ask name
> while name is exactly "Y" or name is exactly "y"
> donewhile
>finish
>
>
>
>On 29 October 2013 10:58, Dilawar <dilawar....@gmail.com> wrote:
>
>> The idea of literate programming -- a program can be a piece of literature
>> -- is due to Donald E. Knuth <http://www-cs-faculty.stanford.edu/~uno/>who is extremely respected figure in programming community (and also among
>> combinatorics and computer science people). In this paradigm, one does not
>> write a program based on how computer would reason about it but rather
>> follows a human-like flow. It is the job of literate programming tool to
>> convert this human-readable program into something which make sense to a
>> computer. Since the translation process is governed by a computer program,
>> there are specific constraints on how to write a program in literate way.
>>
>> Best way to understand the difference is to look at a literate program<http://www-cs-faculty.stanford.edu/~uno/programs/setset.w>.
>> One can find many. A program is written like an essay, and one then uses a
>> tool to extract code (this process was called tangling by Knuth) or
>> documentation (weaving) out of it. Knuth, true to his nature, wrote cweb
>> for his personal use and used in this personal work. Other used it if they
>> liked. Some other tools cropped up and many of them were written for
>> pacific languages. Noweb <http://www.cs.tufts.edu/~nr/noweb/>, written by
>> Roman Ramsay, is language agnostic. There are some other tools like it e.g.
>> funnel-web, nuweb etc but none is as simple to use as this one. Lyx also
>> have support for noweb. And if my memory serves me write, IIT Madras,
>> offered (or still offering) a course in literate programming to its
>> students using Lyx.
>>
>> Literate programming did not really catch up (who wants to write
>> documentation in the first place). But some people have used it
>> extensively. To my knowledge, apart from Knuth, Columbia Esterel Compiler
>> (cec) is written as literate program using noweb and its really easy to
>> understand. I myself have made some changes to it for personal use<https://github.com/dilawar/cec>
>> .
>> *THIS IS FOR INTERMEDIATE USERS OF NOWEB (IF ANY) :*
>>
>> This python font-end<https://raw.github.com/dilawar/Scripts/master/pynoweb.py>introduces two more features to noweb by extending its markup language. You
>> don't have to write a single noweb file for full program; it can be divided
>> into many others file and can be included using *%\include{file.nw}*switch. Moreover, one needs specify from command line which chunck to be
>> written to which file, this can now be embeded inside the literate file.
>> Just write over the chunk something like *%file:src/file.c*. % is a
>> comment in tex file therefore it does not introduce error in noweb which
>> simply ignores it. For example if a chunk named `gloabal.h` is to be
>> written to file `include/global.h` then, just above the chunk `<<global.h>
>> **>`, you must have
>>
>> %file:include/global.h
>> <**<global.h>>=
>> // whatver is there in global
>> @ %def global.h **
>>
>>
>> --
>> Dilawar
>> NCBS/IITB
>> **
>>
>> --
>> --
>> The website for the club is http://stab-iitb.org/wncc
>> To post to this group, send email to wncc...@googlegroups.com
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Web and Coding Club IIT Bombay" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to wncc_iitb+...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>--
>--
>The website for the club is http://stab-iitb.org/wncc
>To post to this group, send email to wncc...@googlegroups.com
>
>---
>You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
>For more options, visit https://groups.google.com/groups/opt_out.

>#include "naturalC.h"
>
>start
> create a string called name
> create an int called age
> do
> print "Hello! What is your name?\n"
> ask name
> print "What is your age?\n"
> ask age
> if 18 exceeds age
> then print "Sorry " << name << ", you cannot vote!\n"
> otherwise print "Congrats " << name << ", maybe you can vote!\n"
> endif
>
> print "Try again? Y/N\n"
> ask name
> while name is exactly "Y" or name is exactly "y"
> donewhile
>finish

>#include <iostream>
>
>using namespace std;
>
>#define start int main(){
>
>#define finish ; return 0;}
>
>#define create ;
>
>#define a /* */
>#define an /* */
>#define the /* */
>
>#define called /* */
>
>#define ask ; cin>>
>
>#define print ; cout<<
>
>#define if ; if(
>
>#define then ){
>
>#define otherwise ; } else {
>
>#define endif ; }
>
>#define do ; do{
>
>#define while ; } while(
>
>#define exceeds >
>
>#define is /* */
>
>#define exactly ==
>
>#define donewhile );

Prashant Sohani

unread,
Oct 30, 2013, 9:07:39 AM10/30/13
to wncc...@googlegroups.com
Hindawi is very interesting.. (haha CS101 turtle assignment in Hindi: http://www.youtube.com/watch?v=kCMF3oz7clM ), surprising to find not much recent discussion/activity anywhere.

Re: English language being unsuitable: possibly, but maybe that is the challenge: to make a translator powerful enough to understand all nuances of English grammar, and generate C code from it.




For more options, visit https://groups.google.com/groups/opt_out.


--
--
The website for the club is http://stab-iitb.org/wncc
To post to this group, send email to wncc...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+unsubscribe@googlegroups.com.
--
--
The website for the club is http://stab-iitb.org/wncc
To post to this group, send email to wncc...@googlegroups.com

--- You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+unsubscribe@googlegroups.com.

Mayank Singhal

unread,
Nov 15, 2013, 8:06:25 AM11/15/13
to wncc_iitb
lot of inconsistencies in grammar of language
Interesting. Do you have any examples?

Hindawi seems to be claiming technological superiority with little to no explanation. From what I can see in the manual, the language is largely translation of C/C++ methods/functions and reserved keywords. While I understand how this can be very beneficial for someone who doesn't speak/read english to get into the language, I fail to see much value for intermediate/expert users. I would have personally prefer  translations of manpages a lot more than translating the signature of methods themselves.

Mayank Singhal



To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.

Dilawar Singh

unread,
Nov 18, 2013, 7:43:33 AM11/18/13
to wncc...@googlegroups.com
>> lot of inconsistencies in grammar of language
> Interesting. Do you have any examples?

Yes. If it were not, there is no need for Chomsky grammars.

Here is what Ponthy and Mython are saying about it, English.SO has a lot of
relevant question about it.
http://answers.yahoo.com/question/index?qid=20120414113232AAPv2Ua

And here is somewhat serious take on it.
http://www.gray-area.org/Research/Ambig/

Moreover, sneaky nature of this language which is no less a reason why so much
is still being invested in searching technology (in context based searching).
Its just not easy to search English due to its "beautifully sneaky nature" which
is described by Soumen Chakrabarti as following,

English is a beautifully sneaky language. I find the conflation between ...
race -- (any competition; "the race for the presidency")
race -- (a contest of speed; "the race is to the swift")
race -- (people who are believed to belong to the same genetic stock;
"some biologists doubt that there are important genetic differences
between races of human beings")
race -- (to work as fast as possible towards a goal, sometimes in
competition with others
... sublimely delightful.

There was once a Forbes article (inflated some Indian pride) stating that
Sankrit is most suitable for computer programming. Their reasoning was that
Sankrit grammar is already in Chomsky forms (well, at least a large subset of
it).

> Hindawi seems to be claiming technological superiority with little to no
> explanation. From what I can see in the manual, the language is largely
> translation of C/C++ methods/functions and reserved keywords. While I
> understand how this can be very beneficial for someone who doesn't
> speak/read english to get into the language, I fail to see much value for
> intermediate/expert users. I would have personally prefer translations of
> manpages a lot more than translating the signature of methods themselves.

Yes. This is a weired fashion these days to claim 100 feet after digging only 2
feet. Many are confusing "adaptation" with innovation. Hindawi is no more
innovative than the Akash Tablet (rumours have it that damn thing is assembled
outside India, forget the OS and hardware). Its not the thing but the thought
that they are trying to do something from scratch that count. Of course, it is
never going to be as sophisticated as English based compilers but as far as
front-end is concerned, it is written by browns for other non-anglophones
browns. And like Doordarshan is for entertainment, it may be their only option
to do some computer programming.

Usefulness is there, as you mentioned. I did not know English language when I
started my B.Tech; and there is not a single good reason why this can not be
appreciated, if only it helps students like me to discover programming early in
school days.

--
Dilawar
NCBS Bangalore (+91 080 2366 6504)
EE, IIT Bombay

Mayank Singhal

unread,
Nov 19, 2013, 8:45:45 AM11/19/13
to wncc...@googlegroups.com
Its just not easy to search English due to its "beautifully sneaky nature"

Which is also the reason why understanding natural english is hard for computers/compilers. And the reason why natural english would be a bad choice to code in (Well, that and because quite a few english words mean quite a few very distinct things). This, however is no reason to argue that coding in a constrained subset of english, just like coding in a constrained 
unambiguous subset of sanskrit cannot be sufficiently efficient and awesome.

it is never going to be as sophisticated as English based compilers
I would say that in terms of innovation, if they really do anything awesome, it would get easily ported to core compilers as well - because the features, in their fundamentals, are not language dependent. 

 And like Doordarshan is for entertainment, it may be their only option
to do some computer programming
I disagree. I started programming quite young when I could barely read (non-textbook) english and definitely couldn't speak any. For me, learning programming was orthogonal to learning english. Programming was essentially recognizing keywords - much like how someone who doesn't read english can still recognize denominations on a currency note. However, the largest challenge was that all textbooks, documentation and tutorials were in english and largely for native/expert speakers of the language. Again, I totally understand the idea and the effort - and yet if I had considered the problem as a venue worth investing my time on, I would have picked a different solution.

And I am not hating on the project and I appreciate the effort very much. I just don't see it making much of a difference. I would, however, love to be proved wrong. I would love the programming community to grow stronger, and I don't care if it happens through projects I find less compelling.

Dilawar Singh

unread,
Nov 19, 2013, 8:48:36 AM11/19/13
to wncc...@googlegroups.com
>coding in a constrained subset of english, just like coding in a
>constrained unambiguous subset of sanskrit cannot be sufficiently efficient
>and awesome.

Yes. I think that is the whole find. I suspect that it is extremely hard to find
a constrained subset of English which computer can understand without any
ambiguity.

--
Dilawar
Reply all
Reply to author
Forward
0 new messages