more code snippets for the website

This commit is contained in:
Araq 2014-12-14 11:29:27 +01:00
commit 556f488087
3 changed files with 54 additions and 8 deletions

View file

@ -52,7 +52,7 @@
<!-- slides --> <!-- slides -->
<div id="slide0" class=""> <div id="slide0" class="">
<div> <div>
<h2>nim looks like this..</h2> <h2>Nim looks like this..</h2>
<pre><span class="cmt"># compute average line length</span> <pre><span class="cmt"># compute average line length</span>
<span class="kwd">var</span> <span class="kwd">var</span>
<span class="tab"> </span>sum = <span class="val">0</span> <span class="tab"> </span>sum = <span class="val">0</span>
@ -85,13 +85,13 @@ p.greet() <span class="cmt"># or greet(p)</span>
<div id="slide1" class="active"> <div id="slide1" class="active">
<h2><a name="why-should-i-be-excited">Why should I be excited?</a></h2> <h2><a name="why-should-i-be-excited">Why should I be excited?</a></h2>
<span class="desc"> <span class="desc">
Nim the only language that leverages automated proof technology Nim is the only language that leverages automated proof technology
to perform a <i>disjoint check</i> for your parallel to perform a <i>disjoint check</i> for your parallel
code. Working on disjoint data means no locking is code. Working on disjoint data means no locking is
required and yet data races are impossible:</span> required and yet data races are impossible:</span>
<pre> <pre>
<span class="kwd">parallel</span>: <span class="kwd">parallel</span>:
<span class="tab"> </span><span class="kwd">var</span> i = 0 <span class="tab"> </span><span class="kwd">var</span> i = <span class="val">0</span>
<span class="tab"> </span><span class="kwd">while</span> i <= a.high: <span class="tab"> </span><span class="kwd">while</span> i <= a.high:
<span class="tab"> </span>spawn f(a[i]) <span class="tab"> </span>spawn f(a[i])
<span class="tab"> </span>spawn f(a[i+<span class="val">1</span>]) <span class="tab"> </span>spawn f(a[i+<span class="val">1</span>])
@ -100,10 +100,40 @@ p.greet() <span class="cmt"># or greet(p)</span>
<span class="tab end"> </span>i += <span class="val">1</span> <span class="tab end"> </span>i += <span class="val">1</span>
</pre> </pre>
</div> </div>
<div id="slide2" class="">
<div>
<h2>interfacing with C..</h2>
<pre>
<span class="kwd">proc</span> <span class="def">unsafeScanf</span>(f: <span class="typ">File</span>; s: <span class="typ">cstring</span>)
<span class="tab"> </span>{.importc: <span class="val">"fscanf"</span>,
<span class="tab end"> </span>header: <span class="val">"&lt;stdio.h&gt;"</span>, varargs.}
<span class="kwd">var</span> x: cint
unsafeScanf(stdin, <span class="val">"%d"</span>, <span class="kwd">addr</span> x)
</pre></div>
<div>
<h2>..and DSLs made easy</h2>
<pre>
<span class="kwd">import</span> jester, asyncdispatch, htmlgen
routes:
<span class="tab"> </span>get <span class="val">"/"</span>:
<span class="tab end"> </span>resp h1(<span class="val">"Hello world"</span>)
runForever()
</pre><p><span class="desc">
Compile and run with:<br />
nim c -r example.nim<br />
View at: localhost:5000
</span></p>
</div>
</div>
</div> </div>
<div id="slideshow-nav"> <div id="slideshow-nav">
<div id="slideControl0" onclick="slideshow_click(0)"></div> <div id="slideControl0" onclick="slideshow_click(0)"></div>
<div id="slideControl1" onclick="slideshow_click(1)" class="active"></div> <div id="slideControl1" onclick="slideshow_click(1)" class="active"></div>
<div id="slideControl2" onclick="slideshow_click(2)"></div>
</div> </div>
# end # end
<aside id="sidebar"> <aside id="sidebar">
@ -174,7 +204,7 @@ var timer;
var prevIndex = 0; var prevIndex = 0;
function setSlideShow(index, short) { function setSlideShow(index, short) {
if (index > 1) index = 0; if (index > 2) index = 0;
for (var i = 0; i < 10; ++i) { for (var i = 0; i < 10; ++i) {
var x = document.getElementById("slide"+i); var x = document.getElementById("slide"+i);
if (!x) break; if (!x) break;

View file

@ -134,6 +134,22 @@ pre .end { background:url("images/tabEnd.png") no-repeat left bottom; }
border-left:8px solid rgba(0,0,0,.3); border-left:8px solid rgba(0,0,0,.3);
box-shadow:1px 2px 16px rgba(28,180,236,.4); } box-shadow:1px 2px 16px rgba(28,180,236,.4); }
#slide2 { margin:30px 0 0 10px; }
#slide2 > div { float:left; width:320px; font:10pt monospace; }
#slide2 > div:first-child { margin:0 40px 0 0; }
#slide2 h2 { margin:0 0 5px 0; color:rgba(162,198,223,.78); }
#slide2 > div > pre {
margin:0;
padding:15px 10px;
line-height:14pt;
background:rgba(0,0,0,.4);
border-left:8px solid rgba(0,0,0,.3);
box-shadow:1px 2px 16px rgba(28,180,236,.4); }
#slide2 .desc { margin:0 0 5px 0; color:rgba(162,198,223,.78);
font:13pt "arial"; }
/* back when slide1 was the quote: /* back when slide1 was the quote:
#slide1 { margin-top:50px; } #slide1 { margin-top:50px; }
#slide1 > p { #slide1 > p {

View file

@ -18,7 +18,7 @@ Nim's Community
---- ----
Many Nim developers are a part of the Many Nim developers are a part of the
`#nim IRC channel <http://webchat.freenode.net/?channels=nimrod>`_ on `#nim IRC channel <http://webchat.freenode.net/?channels=nim>`_ on
Freenode. That is the place where the rest of the discussion relating to Nim Freenode. That is the place where the rest of the discussion relating to Nim
occurs. Be sure to join us there if you wish to discuss Nim in real-time. occurs. Be sure to join us there if you wish to discuss Nim in real-time.
IRC is the perfect place for people just starting to learn Nim and we IRC is the perfect place for people just starting to learn Nim and we
@ -98,7 +98,7 @@ Nim's Community
<iframe style="border: 0; margin: 0; padding: 0;" <iframe style="border: 0; margin: 0; padding: 0;"
src="https://www.gittip.com/Araq/widget.html" src="https://www.gittip.com/Araq/widget.html"
width="48pt" height="22pt"></iframe> width="64pt" height="22pt"></iframe>
Paypal Paypal
.. raw:: html .. raw:: html