<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ponton&#039;s site &#187; c</title>
	<atom:link href="http://www.ponton.srednikpe.org/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ponton.srednikpe.org</link>
	<description>blog głównie matematyczno-informatyczny (nie chce mi się pisać o życiu)</description>
	<lastBuildDate>Mon, 18 Jan 2010 22:23:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Programowanie literackie</title>
		<link>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/</link>
		<comments>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 01:57:52 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[tex]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=183</guid>
		<description><![CDATA[Ostatnio miałem ponowną styczność z TeX-em, tym razem konkretnie z Beamerem (całkiem fajne narzędzie do tworzenia ładnych i profesjonalnych prezentacji; być może wrzucę tę, którą zrobiłem na zajęcia). Jest to jeden z programów, które są owiane dla mnie lekką tajemnicą&#8230; Już sam fakt że został napisany przez legendarnego Donalda Knutha, powoduje bojaźn i trwogę podczas [...]]]></description>
			<content:encoded><![CDATA[<p>Ostatnio miałem ponowną styczność z TeX-em, tym razem konkretnie z Beamerem (całkiem fajne narzędzie do tworzenia ładnych i profesjonalnych prezentacji; być może wrzucę tę, którą zrobiłem na zajęcia). Jest to jeden z programów, które są owiane dla mnie lekką tajemnicą&#8230; Już sam fakt że został napisany przez legendarnego Donalda Knutha, powoduje bojaźn i trwogę podczas używania. No dobra, przesadzam, ale TeX to program wyjątkowy. Nie dlatego, że jest bezbłędny (ma już ze 30 lat chyba, a ostatni błąd wykryto w nim kilkanaście lat temu), ale dlatego, że jest napisany&#8230; literacko.</p>
<p>Donald Knuth napisał książkę-program pod tytułem <em>TeX: The Program</em> (ISBN: 0201134373). Następnie (a może uprzednio?) napisał narzędzie, które nazwał WEB. WEB pozwalał mu automatycznie skonwertować książkę-program do poprawnego programu w Pascalu (w tamtych czasach był to bardzo popularny język), który po skompilowaniu robił to, co opisano w książkoprogramie. Oprócz tego, pozwalał też wygenerować&#8230; książkę. Z nagłówkami, sekcjami, stronami &#8212; ot, PDF lub PostScript, nadający się do wydrukowania.</p>
<p>Książkoprogram to tak naprawdę dokumentacja i kod w jednym. Programista pisze na przemian kod i tekst. Może przy pisaniu kodu korzystać ze wszystkich dobrodziejstw TeX-a do opisywania swojego kodu, tworzyć odnośniki do innych fragmentów kodu, etc. Lepiej to zobaczyć na przykładzie: <a href="http://srednikpe.org/src/kwadrat/kwadrat.w">kwadrat.w</a>. Użyłem wesji WEB dla C/C++, która nazywa się <a title="CWEB" href="http://www-cs-faculty.stanford.edu/~knuth/cweb.html">CWEB</a>. Aby otrzymać program C, wystarczy polecnie:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ctangle kwadrat
This is CTANGLE, Version <span style="color: #000000;">3.64</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Writing the output <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>kwadrat.c<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Done.
<span style="color: #7a0874; font-weight: bold;">&#40;</span>No errors were found.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> kwadrat kwadrat.c <span style="color: #660033;">-lm</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>kwadrat
Podaj a: <span style="color: #000000;">1</span>
Podaj b: <span style="color: #000000;">10</span>
Podaj c: <span style="color: #000000;">5</span>
x = -<span style="color: #000000;">9.472136</span>
x = -<span style="color: #000000;">0.527864</span></pre></div></div>

<p>Aby otrzymać dokument TeX-a, należy napisać:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cweave kwadrat
This is CWEAVE, Version <span style="color: #000000;">3.64</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Writing the output file...
Writing the index...
Done.
<span style="color: #7a0874; font-weight: bold;">&#40;</span>No errors were found.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ pdftex kwadrat.tex
This is pdfTeXk, Version <span style="color: #000000;">3.141592</span>-1.40.3 <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>...<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Output written on kwadrat.pdf <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span> pages, <span style="color: #000000;">63651</span> bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Transcript written on kwadrat.log.</pre></div></div>

<p>Oto wygenerowane pliki: <a href="http://srednikpe.org/src/kwadrat/kwadrat.tex">kwadrat.tex</a>, <a href="http://srednikpe.org/src/kwadrat/kwadrat.pdf">kwadrat.pdf</a> i <a href="http://srednikpe.org/src/kwadrat/kwadrat.c">kwadrat.c</a>. Niestety nie wiem jak zmusić czystego TeX-a do poprawnego czytania UTF-8, dlatego w PDF-ie nie ma polskich liter.</p>
<p>Szczerze mówiąc nie mam zdania na temat <em>literate programming</em>. Jeśli ktoś lubi tak pisać, to proszę bardzo &#8212; całkiem przyjemnie się czyta taki dokument. Jednak ja nie lubię się rozpisywać nad kodem, dla mnie sam kod (z komentarzami) stanowi wystarczającą dokumentację. ;)</p>
<p>Warto jeszcze dodać, że wsparcie dla <em>literate programming</em> jest zaimplementowane w Haskellu. Ale to już lepiej poczytać na <a title="Literate programming in Haskell" href="http://www.haskell.org/haskellwiki/Literate_programming">Haskell Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LOLCode Compiler (my own!)</title>
		<link>http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/</link>
		<comments>http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 23:18:42 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[lolcode]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/</guid>
		<description><![CDATA[Hah! My dream have come through! I wrote my first compiler with my own lexer and parser. It compiles LOLCode (slightly modified version, see in specification [in polish, but only output language]) to stack machine language. My project contains also stack machine which interprets output files and prints them in human readable assembler and three [...]]]></description>
			<content:encoded><![CDATA[<p>Hah! My dream have come through! I wrote my first compiler with my own lexer and parser. It compiles LOLCode (slightly modified version, see in specification [in polish, but only output language]) to stack machine language. My project contains also stack machine which interprets output files and prints them in human readable assembler and three examples of LOLCode programs. It&#8217;s all GPL so you can learn how it works. It&#8217;s written in C and I didn&#8217;t have much time to write pretty dynamic arrays and If someone will fix it, I would be verry happy. If you&#8217;ve got question about how it works, go ahead, write me and ask.</p>
<p>Source: <a title="LCC Source" href="http://www.srednikpe.org/src/lcc/">http://www.srednikpe.org/src/lcc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
