Skip to content

Commit 5edbee6

Browse files
committed
Add site skeleton and generated ref files.
1 parent b4dcdfb commit 5edbee6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+12603
-0
lines changed

_config.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
navbar:
2+
- url: /tut/
3+
label: Tutorial
4+
- url: /ref/
5+
label: Reference
6+
- url: http://arclanguage.org/forum
7+
label: Forum
8+
- url: http://arclanguage.org
9+
label: Offical Site

_layouts/default.html

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Arc Programming Language</title>
6+
<link rel="stylesheet" href="/assets/css/main.css">
7+
<link rel="shortcut icon" href="/assets/ico/favicon.png">
8+
<link href="//twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
9+
<link href="//twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
10+
</head>
11+
12+
<body>
13+
<header>
14+
<div class="navbar navbar-inverse">
15+
<div class="navbar-inner">
16+
<a class="brand" href="/">Arc</a>
17+
<ul class="nav">
18+
{% for item in site.navbar %}
19+
<li {% if page.url contains item.url %}class="active"{% endif %}>
20+
<a href="{{ item.url }}">{{ item.label }}</a>
21+
</li>
22+
{% endfor %}
23+
</ul>
24+
</div>
25+
</div>
26+
</header>
27+
28+
<div class="container-fluid">
29+
{{ content }}
30+
</div>
31+
</body>
32+
</html>

assets/css/main.css

Whitespace-only changes.

assets/ico/favicon.png

113 Bytes
Loading

index.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: default
3+
title: Arc Programming Language
4+
---
5+
6+
<div class="hero-unit">
7+
<div class="text-center">
8+
<h1>Arc Programming Language</h1>
9+
<p>A language designed for exploratory programming.</p>
10+
<br/>
11+
<p><a class="btn btn-primary btn-large" href="http://ycombinator.com/arc/arc3.1.tar">Download</a></p>
12+
<p><small class="muted">Version 3.1</small></p>
13+
</div>
14+
</div>

ref/ajax0.html

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
Ajax is surprisingly easy to use with the Arc language. This article shows how to implement Ajax-based autocompletion and dynamic page updates using
2+
the <a href="http://wiki.script.aculo.us/scriptaculous/">script.aculo.us</a> and <a href="http://prototypejs.org/">Prototype</a> JavaScript frameworks. These frameworks allow Ajax applications to be implemented with just a few lines of additional code.
3+
The hard work is done by the script.aculo.us and Prototype libraries. All the Arc code needs to do is provide the list of autocompletion candidates, and the dynamic page content.
4+
5+
<h3>The example</h3>
6+
This example implements a simple Ajax input autocompleter and dynamic page update. For the autocompleter, as soon as you enter a few letters into the input, it provides a list of matching terms. As soon as you select a term, the page is dynamically updated with associated data, as in the following screenshot:
7+
<br>
8+
<img style="border:1px solid #000000;" src="/ajax/ajax.gif" alt="screenshot">
9+
<br>
10+
For the purposes of the demonstration, the content is information on the
11+
countries of the world, obtained from the <a
12+
href="https://www.cia.gov/library/publications/the-world-factbook/">CIA World
13+
Factbook</a>.
14+
<p>
15+
To summarize how it all works:
16+
When you enter characters in the input field, the script.aculo.us
17+
autocompleter JavaScript sends the charaters to the Arc server, which returns the
18+
autocomplete suggestions. The autocompleter JavaScript displays the
19+
suggestions on the page.
20+
When you select a country, the updater JavaScript does three separate requests
21+
to the Arc server, to request the population, area, and capital. When the
22+
responses arrive, they are inserted into the page.
23+
<p>
24+
In more detail, the autocompletion is performed by <a href="http://wiki.script.aculo.us/scriptaculous/show/Ajax.Autocompleter">Ajax.Autocompleter</a>, and the dynamic updating is performed by <a href="http://www.prototypejs.org/api/ajax/updater">Ajax.Updater</a>. The control flow is:
25+
<ul>
26+
<li>
27+
The <code>Ajax.Autocompleter</code> associated with the <code>autocomplete</code> input and <code>autocomplete_choices</code> div sends inputs to <code>/auto_complete?prefix=<i>chars</i></code>.
28+
<li>The Arc handler sends back a formatted list of autocomplete candidates, e.g.
29+
<code>
30+
&lt;ul&gt;&lt;li&gt;Iran&lt;/li&gt;&lt;li&gt;Iraq&lt;/li&gt;&lt;li&gt;Ireland&lt;/li&gt;&lt;/ul&gt;</code>.
31+
<li>The <code>Ajax.Autocompleter</code> displays the candidates in the <code>autocomplete</code> div.
32+
<li>When an autocompletion is selected, the <code>update</code> JavaScript function starts three <code>Ajax.Updater</code> instances, which send an Ajax request to URL <code>/getcontents?field=population&amp;name=<i>value</i>, and similarly for area and capital in parallel.
33+
<li>The Arc handler for <code>getcontents</code> returns the desired contents.
34+
<li><code>Ajax.Updater</code> puts the contents into the <code>population</code>, <code>area</code>, and <code>capital</code> divs.
35+
</ul>
36+
<h3>Running the example</h3>
37+
First set up the necessary files.
38+
<ul>
39+
<li>Download <a href="/ajax/ajax.zip">ajax.zip</a> and uncompress it into the
40+
same directory that Arc runs in. This zip file provides
41+
<code>ajax.html</code>, <code>ajax.arc</code>, <code>data.arc</code>, and <code>autocomplete.css</code>.
42+
<li> Download the script.aculo.us library files from <a href="http://script.aculo.us/downloads">script.aculo.us</a>. Copy the <code>.js</code> files from <code>lib</code> and <code>src</code> into the same directory that Arc runs in.
43+
</ul>
44+
Next, start up the Arc interpreter,
45+
load the <code>ajax.arc</code> file, and start the web server.
46+
<pre class="arc">
47+
arc> (load "ajax.arc")
48+
arc> (thread (serve 8080))
49+
arc> ready to serve port 8080
50+
</pre>
51+
Then go to <a href="http://localhost:8080/ajax.html">http://localhost:8080/ajax.html</a>. (Unfortunately I don't have a live demo on a public machine. If anyone sets one up, let me know and I'll add a link here.)
52+
<p>
53+
Start typing in the box, and you should see a dropdown with autocompleted choices. Click one, and the code will be displayed below asynchronously.
54+
55+
<h3>The Arc code</h3>
56+
The Arc server code is in <a href="/ajax/ajax.arc"><code>ajax.arc</code></a>. Two Arc handlers are implemented to provide the client-side Ajax support. The first, <code>auto_complete</code> receives the current input contents and returns a list of up to 10 autocompletion candidates formatted in HTML.
57+
The second handler, <code>getcontents</code> returns the dynamic content for the page, from the <code>database</code> table. Note that the handlers do nothing particularly special to make them "Ajax"; they are standard Arc web handlers based on <code>defop</code> and can be accessed directly through the browser. See <a href="http://arcfn.com/doc/srv.html">Arc Web Server</a> for more information on web serving with Arc.
58+
59+
<pre class="code">
60+
(defop auto_complete req
61+
(let prefix (downcase (arg req "prefix"))
62+
(prn (to-html-list (cut (startselts prefix keylist) 0 10)))))
63+
64+
(defop getcontents req
65+
(with (field (arg req "field") name (arg req "name"))
66+
(if (is field "population") (prn ((database name) 1))
67+
(is field "area") (prn ((database name) 2))
68+
(is field "capital") (prn ((database name) 3)))))
69+
</pre>
70+
The handlers use a couple helpers; <code>startselts</code> returns the elements that match the autocomplete prefix and <code>to-html-list</code> wraps the elements in HTML list tags.
71+
<pre class="code">
72+
; Returns a list of elements that start with prefix
73+
(def startselts (prefix seq) (rem [no (begins (downcase _) prefix)] seq))
74+
75+
; Wraps elts in HTML list tags
76+
(def to-html-list (elts) (tostring
77+
(prall elts "&lt;ul&gt;&lt;li&gt;" "&lt;/li&gt;&lt;li&gt;")
78+
(pr "&lt;/li&gt;&lt;/ul&gt;")))
79+
</pre>
80+
The actual content is obtained from <a href="/ajax/data.arc"><code>data.arc</code></a>, which contains the information on each country as a list of lists.
81+
<pre class="code">
82+
("United States" "301,139,947" "9,826,630" "Washington, DC")
83+
</pre>
84+
Some simple code converts <code>data.arc</code> into a table called <code>database</code> indexed by country for easy lookup, and generates a sorted list of countries for use in autocompletion:
85+
<pre class="code">
86+
(= database (table))
87+
(w/infile inf "data.arc"
88+
(let datalist (sread inf nil)
89+
(each elt datalist
90+
(= (database (elt 0)) elt))))
91+
(= keylist (mergesort &lt; (keys database)))
92+
</pre>
93+
<p>
94+
For some reason, the default Arc web server <code>srv.arc</code> doesn't support <code>.js</code> files. The <code>ajax.arc</code> file modifies the server slightly to support these files:
95+
<pre class="code">
96+
(= (srv-header* 'text/javascript)
97+
"HTTP/1.0 200 OK
98+
Content-Type: text/javascript; charset=UTF-8
99+
Connection: close")
100+
101+
(def static-filetype (sym)
102+
(let fname (string sym)
103+
(and (~find #\/ fname)
104+
(case (last (check (tokens fname #\.) ~single))
105+
"gif" 'gif
106+
"jpg" 'jpg
107+
"css" 'text/css
108+
"txt" 'text/html
109+
"html" 'text/html
110+
"js" 'text/javascript
111+
))))
112+
</pre>
113+
<h3>Debugging</h3>
114+
Several things can go wrong when trying to run the example. If the initial page doesn't load at all, something is probably wrong with the Arc server. If no autocompletion happens, the JavaScript may not be loading, or the Arc server may have problems. If the autocompletion shows up as a bulleted list, the CSS file is probably not loading.
115+
<p>
116+
The Arc code can be debugged in several ways. The first is to access the handlers directly. The autocomplete handler <a href="http://localhost:8080/auto_complete?prefix=a">http://localhost:8080/auto_complete?prefix=a</a> should return a bullet list of autocomplete suggestions. The contents handler: <a href="http://localhost:8080/getcontents?field=area&name=Algeria">http://localhost:8080/getcontents?field=area&name=Algeria</a> should return the dynamic contents value.
117+
<p>
118+
The Arc code can also be debugged by strategically inserting print statements such as:
119+
<pre class="code">
120+
(write req (stderr))
121+
</pre>
122+
This will display the request on the Arc console.
123+
<p>
124+
To debug Ajax, you can use Firefox plugins
125+
<a href="http://livehttpheaders.mozdev.org/">Live HTTP Headers</a> and
126+
<a href="http://www.getfirebug.com/">Firebug</a>. Live HTTP Headers lets you see the headers between the browser and the server, and is very helpful to determine if something is failing. Firebug allows much more in-depth JavaScript debugging.
127+
The browser's JavaScript console is also useful to see JavaScript errors.
128+
<p>
129+
This article has just scratched the surface of script.aculo.us and Ajax. More information is available at the <a href="http://script.aculo.us/">script.aculo.us</a> website or in <a href="http://www.amazon.com/exec/obidos/ASIN/1934356018/rightocom">books</a>.

ref/anaphoric.html

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<html dir="ltr">
2+
<head>
3+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
4+
<title>Arc: Anaphoric operations</title>
5+
<link rel="stylesheet" type="text/css" href="code.css">
6+
</head>
7+
<body>
8+
<a href="http://arcfn.com"><img src="arc.gif" style="position:absolute; right:0px; top:0px; width:135px; height:125; border-style: none" title="Arc de Triomphe under construction. From English
9+
Illustrated Magazine."/></a>
10+
<div class="links">Previous: <a href="error.html">Error handling</a>
11+
Up: <a href="index.html">Contents</a>
12+
Next: <a href="html.html">HTML generation</a>
13+
</div>
14+
<h1 class="links">Arc: Anaphoric operations</h1>
15+
Anaphoric operations provide a mechanism to refer back to themselves.
16+
This can be useful when an expression needs to be used later, as in <code>aif</code>, <code>awhen</code>, or <code>aand</code>. Anaphoric functions allow a function to refer back to itself recursively, without creating a named function.
17+
18+
<p>See <a href='http://www.bookshelf.jp/texi/onlisp/onlisp_15.html'>On Lisp Chapter 14</a> for a detailed explanation of anaphoric operations.
19+
<h2>Anaphoric operations</h2>
20+
<p><table class='arc'>
21+
<tr>
22+
<td class='arc'><a name='aif'></a>
23+
<a target='CODE' href='/src/aif.html'><img src='code.gif' title='code'/></a>
24+
<img src='macro.gif' title='Macro'/>
25+
<a class='op' href='http://practical-scheme.net/wiliki/arcxref?aif'>aif</a> <span class='args'>expr body [expr body] ...</span>
26+
<div class='desc'>Anaphoric <code>if</code>: each <code>expr</code> is evaluated until one is true, and then the corresponding <code>body</code> is executed. Within the body, the anaphoric variable <code>it</code> refers back to the value of <code>expr</code>.</div>
27+
</td>
28+
<td class='arc'><pre>
29+
&gt;(aif (&gt; 1 2) (+ it 1) 42 (+ it 2))
30+
<span class="return">44
31+
</span></pre>
32+
<pre>
33+
&gt;(aif nil (+ it 1))
34+
<span class="return">nil
35+
</span></pre>
36+
</td></tr>
37+
<tr>
38+
<td class='arc'><a name='awhen'></a>
39+
<a target='CODE' href='/src/awhen.html'><img src='code.gif' title='code'/></a>
40+
<img src='macro.gif' title='Macro'/>
41+
<a class='op' href='http://practical-scheme.net/wiliki/arcxref?awhen'>awhen</a> <span class='args'>expr [body ...]</span>
42+
<div class='desc'>Anaphoric <code>when</code>: if the <code>expr</code> is true, the <code>body</code> is executed. Within the body, the variable <code>it</code> refers back to the value of <code>expr</code>.</div>
43+
</td>
44+
<td class='arc'><pre>
45+
&gt;(awhen (* 2 3) (+ it 1))
46+
<span class="return">7
47+
</span></pre>
48+
</td></tr>
49+
<tr>
50+
<td class='arc'><a name='aand'></a>
51+
<a target='CODE' href='/src/aand.html'><img src='code.gif' title='code'/></a>
52+
<img src='macro.gif' title='Macro'/>
53+
<a class='op' href='http://practical-scheme.net/wiliki/arcxref?aand'>aand</a> <span class='args'>[arg ...]</span>
54+
<div class='desc'>Anaphoric <code>and</code>. Returns the last argument if all arguments are true, otherwise returns <code>nil</code>. Inside each argument the anaphoric variable <code>it</code> refers to the value of the previous argument. Like <code>and</code>, lazy evaluation is used, so evaluation stops after encountering a false argument.</div>
55+
</td>
56+
<td class='arc'><pre>
57+
&gt;(aand 1 (+ it 2) (* it 10))
58+
<span class="return">30
59+
</span></pre>
60+
</td></tr>
61+
<tr>
62+
<td class='arc'><a name='afn'></a>
63+
<a target='CODE' href='/src/afn.html'><img src='code.gif' title='code'/></a>
64+
<img src='macro.gif' title='Macro'/>
65+
<a class='op' href='http://practical-scheme.net/wiliki/arcxref?afn'>afn</a> <span class='args'>parms [body ...]</span>
66+
<div class='desc'>Creates an anaphoric function, which can be called recursively with the name <code>self</code>. This allows a recursive function to be created without assigning it a name.</div>
67+
</td>
68+
<td class='arc'><pre>
69+
&gt;((afn (x) (if (is x 0) 1 (* 2 (self (- x 1))))) 5)
70+
<span class="return">32
71+
</span></pre>
72+
</td></tr>
73+
<tr>
74+
<td class='arc'><a name='rfn'></a>
75+
<a target='CODE' href='/src/rfn.html'><img src='code.gif' title='code'/></a>
76+
<img src='macro.gif' title='Macro'/>
77+
<a class='op' href='http://practical-scheme.net/wiliki/arcxref?rfn'>rfn</a> <span class='args'>name parms [body ...]</span>
78+
<div class='desc'>Creates a function with the given <code>name</code>. The name is only inside the scope of the <code>rfn</code> macro. This allows recursive functions to be created without polluting the wider scope.</div>
79+
</td>
80+
<td class='arc'><pre>
81+
&gt;((rfn pow2 (x) (if (is x 0) 1 (* 2 (pow2 (- x 1))))) 5)
82+
<span class="return">32
83+
</span></pre>
84+
</td></tr>
85+
<tr>
86+
<td class='arc'><a name='trav'></a>
87+
<a target='CODE' href='/src/trav.html'><img src='code.gif' title='code'/></a>
88+
<img src='proc.gif' title='Procedure'/>
89+
<a class='op' href='http://practical-scheme.net/wiliki/arcxref?trav'>trav</a> <span class='args'>obj [function ...]</span>
90+
<div class='desc'>Recursive traversal. Applies each <code>function</code> in sequence to <code>obj</code>, if <code>obj</code> is not <code>nil</code>. The function can recursively call itself with a new <code>obj</code> with <code>(self obj)</code>.</div>
91+
</td>
92+
<td class='arc'><pre>
93+
&gt;(trav '(1 2 3 4) (fn (_) (prn _)) (fn (_) (self (cdr _))))
94+
<span class="stdout">(1 2 3 4)
95+
(2 3 4)
96+
(3 4)
97+
(4)
98+
99+
</span><span class="return">nil
100+
</span></pre>
101+
</td></tr>
102+
</table>
103+
<p>
104+
Copyright 2008 Ken Shirriff.
105+
</body>
106+
</html>

0 commit comments

Comments
 (0)