Permalink
Browse files

Created gh-pages branch via GitHub

  • Loading branch information...
0 parents commit 6acc04171b23080ac0fca552434de53941dd9387 @krig committed Apr 2, 2012
Showing with 498 additions and 0 deletions.
  1. +157 −0 index.html
  2. +20 −0 javascripts/scale.fix.js
  3. +1 −0 params.json
  4. +69 −0 stylesheets/pygment_trac.css
  5. +251 −0 stylesheets/styles.css
@@ -0,0 +1,157 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="chrome=1">
+ <title>LISP by krig</title>
+
+ <link rel="stylesheet" href="stylesheets/styles.css">
+ <link rel="stylesheet" href="stylesheets/pygment_trac.css">
+ <script src="javascripts/scale.fix.js"></script>
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+ <!--[if lt IE 9]>
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+ </head>
+ <body>
+ <div class="wrapper">
+ <header>
+ <h1>LISP</h1>
+ <p>My attempt at implementing the original LISP paper while learning lisp. Nothing special, mostly posted as a homage to McCarthy.</p>
+ <p class="view"><a href="https://github.com/krig/LISP">View the Project on GitHub <small>krig/LISP</small></a></p>
+ <ul>
+ <li><a href="https://github.com/krig/LISP/zipball/master">Download <strong>ZIP File</strong></a></li>
+ <li><a href="https://github.com/krig/LISP/tarball/master">Download <strong>TAR Ball</strong></a></li>
+ <li><a href="https://github.com/krig/LISP">Fork On <strong>GitHub</strong></a></li>
+ </ul>
+ </header>
+ <section>
+ <h3>LISP</h3>
+
+<p>The original paper on LISP, written by John McCarthy in 1960 and available <a href="http://www-formal.stanford.edu/jmc/recursive.html">here</a>, specifies the basic rules of Lisp in a very clear and readable way. It is almost impossible to read the paper and not get the urge to try implementing it yourself. That's what I've done in this repository.</p>
+
+<h3>Rationale</h3>
+
+<p>This is not intended to be a usable or interesting programming language. It is an exploration of the roots of Lisp. My purpose with publishing it is primarily as a homage and exercise.</p>
+
+<h3>eval</h3>
+
+<p>Here is the complete <code>eval</code> function:</p>
+
+<pre><code>sexpr_t lisp_eval(Lisp I, sexpr_t e, sexpr_t env) {
+ static const char* squote = NULL;
+ static const char* scar = NULL;
+ static const char* scdr = NULL;
+ static const char* satom = NULL;
+ static const char* scond = NULL;
+ static const char* scons = NULL;
+ static const char* seq = NULL;
+ static const char* slabel = NULL;
+ static const char* sfn = NULL;
+ static const char* ssetq = NULL;
+
+ if (squote == NULL) {
+ squote = intern("quote");
+ scar = intern("car");
+ scdr = intern("cdr");
+ satom = intern("atom");
+ scond = intern("cond");
+ scons = intern("cons");
+ seq = intern("eq");
+ slabel = intern("label");
+ sfn = intern("fn");
+ ssetq = intern("setq");
+ }
+
+ if (NILP(e)) {
+ return &amp;I-&gt;nil;
+ } else if (ATOMP(e)) {
+ if (ATOMTYPE(e) == T_SYMBOL) {
+ return lisp_assoc(I, e, env);
+ }
+ else {
+ return e;
+ }
+ }
+ else if (ATOMP(CAR(e))) {
+ if (ATOMTYPE(CAR(e)) == T_FUNCTION) {
+ I-&gt;call = e;
+ return ATOM2FN(CAR(e))(I, lisp_evlis(I, CDR(e), env), env);
+ }
+ else if (ATOMTYPE(CAR(e)) == T_SYMBOL) {
+ // todo: apply
+ const char* astr = ATOM2STR(CAR(e));
+ if (astr == squote) {
+ return CADR(e);
+ }
+ else if (astr == satom) {
+ sexpr_t ret = lisp_eval(I, CADR(e), env);
+ if (ATOMP(ret))
+ return ret;
+ else
+ return &amp;I-&gt;nil;
+ }
+ else if (astr == seq) {
+ return lisp_eq(I, lisp_eval(I, CADR(e), env), lisp_eval(I, CADDR(e), env));
+ }
+ else if (astr == scond) {
+ sexpr_t c = CDR(e);
+ while (!NILP(c)) {
+ sexpr_t r = lisp_eval(I, CAAR(c), env);
+ if (!NILP(r)) {
+ return lisp_eval(I, CADAR(c), env);
+ }
+ else {
+ c = CDR(c);
+ }
+ }
+ printf("Cond error:");
+ print_sexpr(I, e);
+ return &amp;I-&gt;nil;
+ }
+ else if (astr == scar) {
+ return CAR(lisp_eval(I, CADR(e), env));
+ }
+ else if (astr == scdr) {
+ return CDR(lisp_eval(I, CADR(e), env));
+ }
+ else if (astr == scons) {
+ return lisp_cons(I, lisp_eval(I, CADR(e), env), lisp_eval(I, CADDR(e), env));
+ }
+ else if (astr == ssetq) {
+ sexpr_t v1 = CADR(e);
+ do {
+ I-&gt;env = lisp_cons(I, lisp_list(I, CADR(e), lisp_eval(I, CADDR(e), env)), I-&gt;env);
+ e = CDDR(e);
+ } while(!NILP(CDR(e)));
+ return v1;
+ }
+ else {
+ return lisp_eval(I, lisp_cons(I, lisp_assoc(I, CAR(e), env), CDR(e)), env);
+ }
+ }
+ }
+ else if (lisp_streq(I, CAAR(e), slabel) != &amp;I-&gt;nil) {
+ return lisp_eval(I, lisp_cons(I, CADDAR(e), CDR(e)),
+ lisp_cons(I, lisp_list(I, CADAR(e), CAR(e)), env));
+ }
+ else if (lisp_streq(I, CAAR(e), sfn) != &amp;I-&gt;nil) {
+ return lisp_eval(I, CADDAR(e),
+ lisp_append(I, lisp_pair(I, CADAR(e),
+ lisp_evlis(I, CDR(e), env)), env));
+ }
+
+ printf("Eval error:");
+ print_sexpr(I, e);
+ return &amp;I-&gt;nil;
+}
+</code></pre>
+ </section>
+ <footer>
+ <p>This project is maintained by <a href="https://github.com/krig">krig</a></p>
+ <p><small>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
+ </footer>
+ </div>
+ <!--[if !IE]><script>fixScale(document);</script><!--<![endif]-->
+ </body>
+</html>
@@ -0,0 +1,20 @@
+fixScale = function(doc) {
+
+ var addEvent = 'addEventListener',
+ type = 'gesturestart',
+ qsa = 'querySelectorAll',
+ scales = [1, 1],
+ meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
+
+ function fix() {
+ meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
+ doc.removeEventListener(type, fix, true);
+ }
+
+ if ((meta = meta[meta.length - 1]) && addEvent in doc) {
+ fix();
+ scales = [.25, 1.6];
+ doc[addEvent](type, fix, true);
+ }
+
+};
@@ -0,0 +1 @@
+{"name":"LISP","body":"### LISP\r\n\r\nThe original paper on LISP, written by John McCarthy in 1960 and available [here](http://www-formal.stanford.edu/jmc/recursive.html), specifies the basic rules of Lisp in a very clear and readable way. It is almost impossible to read the paper and not get the urge to try implementing it yourself. That's what I've done in this repository.\r\n\r\n### Rationale\r\n\r\nThis is not intended to be a usable or interesting programming language. It is an exploration of the roots of Lisp. My purpose with publishing it is primarily as a homage and exercise.\r\n\r\n### eval\r\n\r\nHere is the complete `eval` function:\r\n\r\n```\r\nsexpr_t lisp_eval(Lisp I, sexpr_t e, sexpr_t env) {\r\n static const char* squote = NULL;\r\n static const char* scar = NULL;\r\n static const char* scdr = NULL;\r\n static const char* satom = NULL;\r\n static const char* scond = NULL;\r\n static const char* scons = NULL;\r\n static const char* seq = NULL;\r\n static const char* slabel = NULL;\r\n static const char* sfn = NULL;\r\n static const char* ssetq = NULL;\r\n\r\n if (squote == NULL) {\r\n squote = intern(\"quote\");\r\n scar = intern(\"car\");\r\n scdr = intern(\"cdr\");\r\n satom = intern(\"atom\");\r\n scond = intern(\"cond\");\r\n scons = intern(\"cons\");\r\n seq = intern(\"eq\");\r\n slabel = intern(\"label\");\r\n sfn = intern(\"fn\");\r\n ssetq = intern(\"setq\");\r\n }\r\n\r\n if (NILP(e)) {\r\n return &I->nil;\r\n } else if (ATOMP(e)) {\r\n if (ATOMTYPE(e) == T_SYMBOL) {\r\n return lisp_assoc(I, e, env);\r\n }\r\n else {\r\n return e;\r\n }\r\n }\r\n else if (ATOMP(CAR(e))) {\r\n if (ATOMTYPE(CAR(e)) == T_FUNCTION) {\r\n I->call = e;\r\n return ATOM2FN(CAR(e))(I, lisp_evlis(I, CDR(e), env), env);\r\n }\r\n else if (ATOMTYPE(CAR(e)) == T_SYMBOL) {\r\n // todo: apply\r\n const char* astr = ATOM2STR(CAR(e));\r\n if (astr == squote) {\r\n return CADR(e);\r\n }\r\n else if (astr == satom) {\r\n sexpr_t ret = lisp_eval(I, CADR(e), env);\r\n if (ATOMP(ret))\r\n return ret;\r\n else\r\n return &I->nil;\r\n }\r\n else if (astr == seq) {\r\n return lisp_eq(I, lisp_eval(I, CADR(e), env), lisp_eval(I, CADDR(e), env));\r\n }\r\n else if (astr == scond) {\r\n sexpr_t c = CDR(e);\r\n while (!NILP(c)) {\r\n sexpr_t r = lisp_eval(I, CAAR(c), env);\r\n if (!NILP(r)) {\r\n return lisp_eval(I, CADAR(c), env);\r\n }\r\n else {\r\n c = CDR(c);\r\n }\r\n }\r\n printf(\"Cond error:\");\r\n print_sexpr(I, e);\r\n return &I->nil;\r\n }\r\n else if (astr == scar) {\r\n return CAR(lisp_eval(I, CADR(e), env));\r\n }\r\n else if (astr == scdr) {\r\n return CDR(lisp_eval(I, CADR(e), env));\r\n }\r\n else if (astr == scons) {\r\n return lisp_cons(I, lisp_eval(I, CADR(e), env), lisp_eval(I, CADDR(e), env));\r\n }\r\n else if (astr == ssetq) {\r\n sexpr_t v1 = CADR(e);\r\n do {\r\n I->env = lisp_cons(I, lisp_list(I, CADR(e), lisp_eval(I, CADDR(e), env)), I->env);\r\n e = CDDR(e);\r\n } while(!NILP(CDR(e)));\r\n return v1;\r\n }\r\n else {\r\n return lisp_eval(I, lisp_cons(I, lisp_assoc(I, CAR(e), env), CDR(e)), env);\r\n }\r\n }\r\n }\r\n else if (lisp_streq(I, CAAR(e), slabel) != &I->nil) {\r\n return lisp_eval(I, lisp_cons(I, CADDAR(e), CDR(e)),\r\n lisp_cons(I, lisp_list(I, CADAR(e), CAR(e)), env));\r\n }\r\n else if (lisp_streq(I, CAAR(e), sfn) != &I->nil) {\r\n return lisp_eval(I, CADDAR(e),\r\n lisp_append(I, lisp_pair(I, CADAR(e),\r\n lisp_evlis(I, CDR(e), env)), env));\r\n }\r\n\r\n printf(\"Eval error:\");\r\n print_sexpr(I, e);\r\n return &I->nil;\r\n}\r\n```","tagline":"My attempt at implementing the original LISP paper while learning lisp. Nothing special, mostly posted as a homage to McCarthy.","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}
@@ -0,0 +1,69 @@
+.highlight { background: #ffffff; }
+.highlight .c { color: #999988; font-style: italic } /* Comment */
+.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
+.highlight .k { font-weight: bold } /* Keyword */
+.highlight .o { font-weight: bold } /* Operator */
+.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
+.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
+.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
+.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
+.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
+.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
+.highlight .ge { font-style: italic } /* Generic.Emph */
+.highlight .gr { color: #aa0000 } /* Generic.Error */
+.highlight .gh { color: #999999 } /* Generic.Heading */
+.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
+.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
+.highlight .go { color: #888888 } /* Generic.Output */
+.highlight .gp { color: #555555 } /* Generic.Prompt */
+.highlight .gs { font-weight: bold } /* Generic.Strong */
+.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
+.highlight .gt { color: #aa0000 } /* Generic.Traceback */
+.highlight .kc { font-weight: bold } /* Keyword.Constant */
+.highlight .kd { font-weight: bold } /* Keyword.Declaration */
+.highlight .kn { font-weight: bold } /* Keyword.Namespace */
+.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
+.highlight .kr { font-weight: bold } /* Keyword.Reserved */
+.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
+.highlight .m { color: #009999 } /* Literal.Number */
+.highlight .s { color: #d14 } /* Literal.String */
+.highlight .na { color: #008080 } /* Name.Attribute */
+.highlight .nb { color: #0086B3 } /* Name.Builtin */
+.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
+.highlight .no { color: #008080 } /* Name.Constant */
+.highlight .ni { color: #800080 } /* Name.Entity */
+.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
+.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
+.highlight .nn { color: #555555 } /* Name.Namespace */
+.highlight .nt { color: #000080 } /* Name.Tag */
+.highlight .nv { color: #008080 } /* Name.Variable */
+.highlight .ow { font-weight: bold } /* Operator.Word */
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
+.highlight .mf { color: #009999 } /* Literal.Number.Float */
+.highlight .mh { color: #009999 } /* Literal.Number.Hex */
+.highlight .mi { color: #009999 } /* Literal.Number.Integer */
+.highlight .mo { color: #009999 } /* Literal.Number.Oct */
+.highlight .sb { color: #d14 } /* Literal.String.Backtick */
+.highlight .sc { color: #d14 } /* Literal.String.Char */
+.highlight .sd { color: #d14 } /* Literal.String.Doc */
+.highlight .s2 { color: #d14 } /* Literal.String.Double */
+.highlight .se { color: #d14 } /* Literal.String.Escape */
+.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
+.highlight .si { color: #d14 } /* Literal.String.Interpol */
+.highlight .sx { color: #d14 } /* Literal.String.Other */
+.highlight .sr { color: #009926 } /* Literal.String.Regex */
+.highlight .s1 { color: #d14 } /* Literal.String.Single */
+.highlight .ss { color: #990073 } /* Literal.String.Symbol */
+.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
+.highlight .vc { color: #008080 } /* Name.Variable.Class */
+.highlight .vg { color: #008080 } /* Name.Variable.Global */
+.highlight .vi { color: #008080 } /* Name.Variable.Instance */
+.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
+
+.type-csharp .highlight .k { color: #0000FF }
+.type-csharp .highlight .kt { color: #0000FF }
+.type-csharp .highlight .nf { color: #000000; font-weight: normal }
+.type-csharp .highlight .nc { color: #2B91AF }
+.type-csharp .highlight .nn { color: #000000 }
+.type-csharp .highlight .s { color: #A31515 }
+.type-csharp .highlight .sc { color: #A31515 }
Oops, something went wrong.

0 comments on commit 6acc041

Please sign in to comment.