Monthly Archives: August 2011

AjLisp in Javascript (Part 2) List Evaluation, Forms and Special Forms

Previous Post
Next Post

In the previous post I presented the structure and creation of atoms and list. But, how a list is evaluated in AjLisp? As in other lisp implementation, the head of the list points to something (form or special form) to apply to the rest of the elements. This is the initial code in list evaluation:

List.prototype.evaluate = function(environment) 
{
    var form = this.first().evaluate(environment);		
    return form.apply(this, environment);
}	

The head should be an element with .apply as method. There are two kinds of form: normal form and special forms. The form implementation:

function Form() {
}
Form.prototype.evaluate = function(environment) { return this; }
Form.prototype.apply = function(list, environment) 
{ 
    if (isNil(list)) return this.eval(list, environment);
    var rest = list.rest();
    if (rest != null)
        rest = rest.evaluateList(environment);
    return this.eval(rest, environment); 
}

The special form implementation:

function SpecialForm() {
}
SpecialForm.prototype.evaluate = function(environment) { return this; }
SpecialForm.prototype.apply = function(list, environment) 
{ 
    if (isNil(list)) return this.eval(list, environment);
    return this.eval(list.rest(), environment);
}

The difference? The elements of the rest of the list ARE EVALUATED in a normal form. An special form doesn’t evaluate them. Why? Because the special form are “primitives” like (if <cond> <then> <else>…) where the <then> <else>… parts should be evaluated under control of the special form. See:

Special Forms in Lisp

Special forms are those expressions in the Lisp language which do not follow normal rules for evaluation. Some such forms are necessary as primitives of the language, while others may be desirable in order to improve readability, control the evaluation environment, implement abstraction and modularity, affect the flow of control, allow extended scoping mechanisms, define functions which accept a variable number of arguments, or achieve greater efficiency. There exist several long-standing mechanisms for specifying the definition of special forms: FEXPR’s, NLAMBDA’s, and MACRO’s.

Form examples? I wrote new forms using instances, overriding their eval method:

var listForm = new Form();
listForm.eval = function eval(list) 
{
	return list;
}
var nilpForm = new Form();
nilpForm.eval = function eval(list) 
{
	if (isNil(list))
		return true;
		
	return isNil(list.first());
}
var listpForm = new Form();
listpForm.eval = function eval(list) 
{
	if (isNil(list))
		return true;
		
	return isList(list.first());
}

An special form example, the ‘if’:

var ifForm = new SpecialForm();
ifForm.eval = function eval(list, env)
{
	var cond = evaluate(list.first(), env);
	var then = list.rest().first();
	var elsebody = list.rest().rest();
	
	if (!isNil(cond) && cond != false)
		return evaluate(then, env);
	while (!isNil(elsebody)) 
	{
		result = evaluate(elsebody.first(), env);
		elsebody = elsebody.rest();
	}
	
	return result;			
}

They are exposed in the global environment:

// Environment
var environment = new Environment();
environment.list = listForm;
environment.first = firstForm;
environment.rest = restForm;
environment.cons = consForm;
environment['do'] = doForm;
environment['if'] = ifForm;
// more settings in environment

Topics for upcoming posts: environments, closures, lambdas, macros.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Lambda Calculus: Links, News and Resources (1)

"Everything is a lambda in the end" ajlopez (past century)

http://en.wikipedia.org/wiki/Lambda_calculus

In mathematical logic and computer science, lambda calculus, also written as λ-calculus, is a formal system for function definition, function application and recursion. The portion of lambda calculus relevant to computation is now called the untyped lambda calculus. In both typed and untyped versions, ideas from lambda calculus have found application in the fields of logic, recursion theory (computability), and linguistics, and have played an important role in the development of the theory of programming languages (with untyped lambda calculus being the original inspiration for functional programming, in particular Lisp, and typed lambda calculi serving as the foundation for modern type systems).

Closures + Lambda = The key to OOP in Lisp « Learning Lisp
http://lispy.wordpress.com/2007/07/18/closures-lambda-the-key-to-oop-in-lisp/

Papers | Lambda the Ultimate
http://lambda-the-ultimate.org/papers

Notas sobre el Cálculo Lambda
http://ajlopez.zoomblog.com/archivo/2009/04/14/notas-sobre-el-Calculo-Lambda.html

Presenting AjLambda, lambda calculus in C#
https://ajlopez.wordpress.com/2009/02/25/presenting-ajlambda-lambda-calculus-implementation-in-c/

Funarg problem
http://en.wikipedia.org/wiki/Funarg_problem

The lambda calculus
http://faculty.knox.edu/dblaheta/research/lambda.pdf

Fixed point combinator
http://en.wikipedia.org/wiki/Y-combinator

Introducction to Lambda Calculus
http://www.cs.chalmers.se/Cs/Research/Logic/TypesSS05/Extra/geuvers.pdf

Introduction to Lambda Calculus
http://citeseer.ist.psu.edu/barendregt94introduction.html

Lambda Calculus
http://www.cs.bham.ac.uk/~axj/pub/papers/lambda-calculus.pdf

A Tutorial Introduction to the Lambda Calculus
http://www.utdallas.edu/~gupta/courses/apl/lambda.pdf

Knights of the Lambda Calculus
http://en.wikipedia.org/wiki/Knights_of_the_Lambda_Calculus

A Hacker’s Introduction to Partial Evaluation | The Lambda meme – all things Lisp, and more
http://www.ymeme.com/hackers-introduction-partial-evaluation.html

To Dissect a Mockingbird: A Graphical Notation for the Lambda Calculus with Animated Reduction
http://users.bigpond.net.au/d.keenan/Lambda/index.htm

http://www.defmacro.org/

λProlog Home Page
http://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog/

Church’s Type Theory
http://plato.stanford.edu/entries/type-theory-church/

Lambda Calculus Schemata
http://cs-www.cs.yale.edu/homes/fischer/pubs/lambda.pdf

Lambda Animator : animated reduction of the lambda calculus
http://thyer.name/lambda-animator/

Peter Selinger: Papers
http://www.mscs.dal.ca/~selinger/papers.html

Mike Taulty’s Blog : Anonymous Methods, Lambdas, Confusion
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/01/28/anonymous-methods-lambdas-confusion.aspx

Lecture Notes on the Lambda Calculus (pdf)
http://www.mscs.dal.ca/~selinger/papers/lambdanotes.pdf

A Security Kernel Based on the Lambda-Calculus
http://mumble.net/~jar/pubs/secureos/

System F: Second-order lambda calculus
http://en.wikipedia.org/wiki/System_F

(Mis)using C# 4.0 Dynamic – Type-Free Lambda Calculus, Church Numerals, and more
http://community.bartdesmet.net/blogs/bart/archive/2009/08/17/mis-using-c-4-0-dynamic-type-free-lambda-calculus-church-numerals-and-more.aspx

Type-Free Lambda Calculus in C#, Pre-4.0 – Defining the Lambda Language Runtime (LLR)
http://community.bartdesmet.net/blogs/bart/archive/2009/08/30/type-free-lambda-calculus-in-c-pre-4-0-defining-the-lambda-language-runtime-llr.aspx

Jim McBeath: Practical Church Numerals in Scala
http://jim-mcbeath.blogspot.com/2008/11/practical-church-numerals-in-scala.html

My Links
http://www.delicious.com/ajlopez/lambda

Angel "AjLambda" Lopez

AjFabriq on NodeJs (Part 1) Introduction

Next Post

Some years ago I discovered Fabriq project (thanks @asehmi!):

Remember Fabriq
FABRIQ has gone public!
Arvindra Shemi Fabriq Articles
Clemens Vasters Fabriq Articles

Key points:

FABRIQ is an infrastructure for constructing networks of nodes processing and relaying messages. These nodes are hosted in machines running into a serviced application.

You can have multiple machines running the same or different applications. The “network” is the application, “node” is a collection of “actions”, and each action process a message. More doc:

These nodes can be hosted in any distribution on several machines according to a defined configuration, so there may be machines running a single node or several nodes, this association are made by specifying the host-name or machine identification associated with each node in the network.

Each of these machines is running a serviced application responsible for starting and stopping its Host and Nodes which are the application main components. The host is responsible for handling the configuration, loading and unloading nodes and receives the messages and delivers them to the appropriate Node.

Past weekend, I started a Javascript project to run on NodeJs, based on Fabriq ideas:

A Distributed Application Framework for NodeJs https://github.com/ajlopez/AjFabriqJs

Simple one file implementation. Four Javascript “Classes”.

I want to run many NodeJs servers that hosts AjFabriq applications, sending messages across their network:

Original Fabriq had application, nodes, configuration. I simplified it and now I have a simple Processor that accepts messages. It can produce 0, 1 or more messages:

Messages are schema-less JSON objects that contains its own routing information:

A Processor could handle all the messages containing the key/value application: “webcrawler”. Some processors are composites: they have another processors. Then, the webcrawler processor could have a child processor specialized in handle message with key/value node:”downloader”. See the picture? But the key/values and the deep of processor trees ARE DECIDED by the developer. You decide to have “applications”, “actions”, “nodes”, or whatever you want.

A host can have many processor defined. When message is posted, a simple local method decides where to send it. It could be locally processed or it could be send to a remote host. The host network is dynamic: a new host can be added at any time, then it can collaborate with the current messages processing.

Pending topics for upcoming blog posts: implementation details, the simplest application, using net (plain) sockets, my failure with Socket.IO. Work in progress: make AjFabriq more NodeJs friendly using EventEmitter in key points, host info (hosted application) better dissemination, more robust implementation; rename Socket to Channel, a better description word.

My previous work on distributed application samples:

AjMessages
AjAgents

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Erlang: Links, News and Resources (1)

Next Post

Recently I published a post about Haskell. Now, it’s time to visit Erlang programming languages. My links and discoveries:

http://en.wikipedia.org/wiki/Erlang_%28programming_language%29

Erlang is a general-purpose concurrent, garbage-collected programming language and runtime system. The sequential subset of Erlang is a functional language, with strict evaluation, single assignment, and dynamic typing. For concurrency it follows the Actor model. It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications. It supports hot swapping, so that code can be changed without stopping a system.[1]

While threads are considered a complicated and error-prone topic in most languages, Erlang provides language-level features for creating and managing processes with the aim of simplifying concurrent programming. Though all concurrency is explicit in Erlang, processes communicate using message passing instead of shared variables, which removes the need for locks.

The first version was developed by Joe Armstrong in 1986.[2] It was originally a proprietary language within Ericsson, but was released as open source in 1998.

Erlang Programming Language
http://www.erlang.org/

YouTube – Erlang: The Movie
http://www.youtube.com/watch?v=uKfKtXYLG78

Invited Tutorial Erlang
http://www.erlang.org/workshop/armstrong.pdf

Brief History of Erlang
http://www.erlang.org/course/history.html

Notes on A History of Erlang
http://www.sauria.com/blog/2008/05/28/notes-on-a-history-of-erlang/

HOPL-III: A History of Erlang
http://lambda-the-ultimate.org/node/2811

http://www.scribd.com/doc/3405806/Erlanghistory

A history of Erlang
http://dl.acm.org/citation.cfm?id=1238850

CiteSeerX — Use of Prolog for developing a new programming language
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.3972
This paper describes how Prolog was used for the development of a new concurrent realtime symbolic programming language called Erlang.

Welcome to Erjang! – GitHub
https://github.com/trifork/erjang/wiki
Erjang is a virtual machine for Erlang, which runs on Java(tm).

InfoQ: Beam.js: Erlang Meets JavaScript
http://www.infoq.com/presentations/Beamjs-Erlang-Meets-JavaScript

Erlang User Group Argentina
http://erlang.org.ar/P%C3%A1gina_Principal

LangDay – ErlangAr
http://erlang.org.ar/LangDay

InfoQ: Testing for the Unexpected
http://www.infoq.com/presentations/Testing-for-the-Unexpected

InfoQ: Ville Tuulos on Big Data and Map/Reduce in Erlang and Python with Disco
http://www.infoq.com/interviews/tuulos-erlang-mapreduce

Functional Languages will Rule (but not this year) – Good Stuff
http://goodstuff.im/functional-languages-will-rule-but-not-this-y

InfoQ: Francesco Cesarini and Simon Thompson on Erlang
http://www.infoq.com/interviews/cesarini-thompson-erlang

Table of Contents | Learn You Some Erlang for Great Good!
http://learnyousomeerlang.com/content

The Next Drupal? Zotonic: A Modern CMS Written in Erlang
http://www.readwriteweb.com/hack/2011/05/the-next-drupal-zotonic.php

Computer Language Design: What’s List Comprehension and Why is It Harmful?
http://xahlee.org/comp/list_comprehension.html

Node.js vs Erlang: SyncPad’s Experience
http://blog.mysyncpad.com/post/2073441622/node-js-vs-erlang-syncpads-experience

Hacker News | They’re so different and yet so similar it’s probably best taking them one topic…
http://news.ycombinator.com/item?id=2414035

9 Programming Languages To Watch In 2011 | Regular Geek
http://regulargeek.com/2010/12/11/9-programming-languages-to-watch-in-2011/

InfoQ: Scala, Erlang, F# Creators Discuss Functional Languages
http://www.infoq.com/interviews/functional-langs

InfoQ: Computation Abstraction: Going Beyond Programming Language Glue
http://www.infoq.com/presentations/Computation-Abstraction

Write A Template Compiler For Erlang
http://evanmiller.org/write-a-template-compiler-for-erlang.html

Erlang | September 2010 | Communications of the ACM
http://cacm.acm.org/magazines/2010/9/98014-erlang/fulltext

Ebot | Matteo Redaelli
http://www.redaelli.org/matteo-blog/projects/ebot/
Erlang Bot (Ebot) is an opensource web crawler written on top of Erlang,

The Lisp Before the End of My Lifetime
http://metalinguist.wordpress.com/2007/08/04/the-lisp-before-the-end-of-my-lifetime/
Networked & Concurrent Programming: Leaders in this area: Erlang

InfoQ: Steve Vinoski on Erlang and Rest
http://www.infoq.com/interviews/steve-vinoski-erlang-rest

Try Erlang
http://www.tryerlang.org/

String Calculator – Erlang » Software Craftsmanship – Katas
http://katas.softwarecraftsmanship.org/?p=96

InfoQ: Kresten Krab Thorup on Erjang, JVM Languages, Kilim
http://www.infoq.com/interviews/thorup-erjang

Avoiding Erlang deadlocks – Embrace change
http://mue.tideland.biz/avoiding-erlang-deadlocks

InfoQ: Horizontal Scalability via Transient, Shardable, and Share-Nothing Resources
http://www.infoq.com/presentations/Horizontal-Scalability

Tidier: A refactoring tool for Erlang
http://tidier.softlab.ntua.gr:20000/tidier/getstarted

The Pragmatic Bookshelf | Seven Languages in Seven Weeks
http://pragprog.com/titles/btlang/seven-languages-in-seven-weeks

Parsing SPARQL in Erlang with a monadic combinatory parser
http://antoniogarrote.lacoctelera.net/post/2009/11/01/parsing-sparql-in-erlang-with-monadic-combinatory-parser

Lisp Flavored Erlang
http://metajack.im/2009/01/09/lisp-flavored-erlang/

InfoQ: RPC and its Offspring: Convenient, Yet Fundamentally Flawed
http://www.infoq.com/presentations/vinoski-rpc-convenient-but-flawed

10 programming languages worth checking out – H3RALD
http://www.h3rald.com/articles/10-programming-languages/

The Pragmatic Bookshelf | What’s all this fuss about Erlang?
http://pragprog.com/articles/erlang

Jim McBeath: Actor Exceptions
http://jim-mcbeath.blogspot.com/2008/07/actor-exceptions.html

InfoQ: John Hughes Contrasts Erlang and Haskell
http://www.infoq.com/interviews/Erlang-Haskell-John-Hughes

InfoQ: Systems that Never Stop (and Erlang)
http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong

The “Anti-For” Campaign – Matthew Podwysocki – CodeBetter.Com – Stuff you need to Code Better!
http://codebetter.com/blogs/matthew.podwysocki/archive/2009/06/26/the-anti-for-campaign.aspx

Luke Galea on Ruby and Erlang
http://www.infoq.com/interviews/galea-ruby

Functional programming in the Java language
http://www.ibm.com/developerworks/java/library/j-fp.html

Contrasting Performance : Languages, styles and VMs – Java, Scala, Python, Erlang, Clojure, Ruby, Groovy, Javascript
http://blog.dhananjaynene.com/2011/08/cperformance-comparison-languages-styles-and-vms-java-scala-python-erlang-clojure-ruby-groovy-javascript/

State You are doing wrong
http://www.slideshare.net/jboner/state-youre-doing-it-wrong-javaone-2009

Erlang vs. Scala – PlanetErlang
http://www.planeterlang.org/en/planet/article/Erlang_vs._Scala/

Minimal Erlang SMTP, POP3 server code « LShift Ltd.
http://www.lshift.net/blog/2007/09/20/minimal-erlang-smtp-pop3-server-code

PubSub is taking off – ProcessOne
http://www.process-one.net/en/blogs/article/pubsub_is_taking_off/

Humanist → Scalable Web Apps: Erlang + Python
http://humani.st/scalable-web-apps-erlang-python/

InfoQ: CouchDB From 10,000 Feet
http://www.infoq.com/presentations/couchDB-from-10K-feet

Erlang Factory London 2009
http://www.erlang-factory.com/conference/London2009/talks

InfoQ: Domain Specific Languages in Erlang
http://www.infoq.com/presentations/dsl-erlang-dennis-byrne

Tic-tac-toe in Erlang — smart game space
http://nealabq.com/blog/2009/03/06/tic-tac-toe-erlang-smart-game-space/

The State of Axum
http://blogs.msdn.com/b/maestroteam/archive/2011/02/28/the-state-of-axum.aspx
How new C# features were influenced by Erlang
“I see axum as erlang done right and for the CLR, coouldnt be better!”

My links:
http://www.delicious.com/ajlopez/erlang

More links about functional programming are coming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Node.Js: Links, news, Resources (2)

Previous post
Next post

Since my previous post, I was playing a bit with Node.Js, on Ubuntu and Windows (now, there is a Windows precompiled version, ready to download and run, see http://nodejs.org/#download). I’m working on rewriting Fabriq ideas from @asehmi to run on pure NodeJs (check my progress at https://github.com/ajlopez/AjFabriqJs; for Fabriq, check https://ajlopez.wordpress.com/2007/10/15/remember-fabriq/)

http://en.wikipedia.org/wiki/Node.js

Node.js is an event-driven I/O server-side JavaScript environment based on V8. It is intended for writing scalable network programs such as web servers.[1] It was created by Ryan Dahl in 2009, and its growth is sponsored by Joyent, which employs Dahl.[2] [3]

Similar environments written in other programming languages include Twisted for Python, Perl Object Environment for Perl, libevent for C and EventMachine for Ruby. Unlike most JavaScript, it is not executed in a web browser, but is instead a form of server-side JavaScript. Node.js implements some CommonJS specifications.[4] Node.js includes a REPL environment for interactive testing.

Deploying Node.js With Upstart and Monit – How To Node – NodeJS
http://howtonode.org/deploying-node-upstart-monit

Custom Node.js Modules « joshdulac.com
http://joshdulac.com/index.php/custom-node-js-modules/

Writing Node.js Native Extensions | Cloudkick, manage servers better
https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/

How To Module – How To Node – NodeJS
http://howtonode.org/how-to-module

Installing Node.js and NPM on Ubuntu 10.04 and try a simple chat application
http://www.giantflyingsaucer.com/blog/?p=1688

Installing node.js on ubuntu 10.04
http://www.codediesel.com/linux/installing-node-js-on-ubuntu-10-04/

BDD and TDD for node.js? – Stack Overflow
http://stackoverflow.com/questions/4706020/bdd-and-tdd-for-node-js

Ubuntu 11.10 to support the Cloud Foundry Platform-as-a-Service
http://www.h-online.com/open/news/item/Ubuntu-11-10-to-support-the-Cloud-Foundry-Platform-as-a-Service-1324917.html

TJ Holowaychuk • commander.js – nodejs command-line interfaces made easy
http://tjholowaychuk.com/post/9103188408/commander-js-nodejs-command-line-interfaces-made-easy

nodechat.js – Using node.js, backbone.js, socket.io, and redis to make a real time chat app
http://fzysqr.com/2011/02/28/nodechat-js-using-node-js-backbone-js-socket-io-and-redis-to-make-a-real-time-chat-app/

Node.js on Windows: Who Needs NPM? « ICED IN CODE
http://icewalker2g.wordpress.com/2011/07/23/node-js-on-windows-who-needs-npm/

node.js & socket.io fun – till’s blog
http://till.klampaeckel.de/blog/archives/133-node.js-socket.io-fun.html

Adam Coffman – Getting your feet wet with node.js and socket.io – Part 1
http://thecoffman.com/2011/02/21/getting-your-feet-wet-with-node.js-and-socket.io/

node.js: Building a graph of build times using the Go API at Mark Needham
http://www.markhneedham.com/blog/2011/08/13/node-js-building-a-graph-of-build-times-using-the-go-api/

Episode 10: Sprite 3D, Candy, NodeJS discussion, jQuery plugins | The Javascript Show
http://javascriptshow.com/episodes/10

Nodejs – A quick tour (v4)
http://www.slideshare.net/the_undefined/nodejs-a-quick-tour-v4

NodeSocket to launch hosting for Node.js apps
http://binzaman.com/2011/08/10/nodesocket-to-launch-hosting-for-node-js-apps/

Dear PHP, I’m leaving and yes, she’s sexier
http://blog.nodeping.com/2011/08/12/dear-php-im-leaving-and-yes-shes-sexier/

InfoQ: Ephemeralization or Heroku’s Evolution to a Polyglot Cloud OS
http://www.infoq.com/news/2011/08/heroku_polyglot

Understanding node.js » Debuggable Ltd
http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb

The Node.js Philosophy – blog.nodejitsu.com – scaling node.js applications one callback at a time.
http://blog.nodejitsu.com/the-nodejs-philosophy

Using node.js async library reminds me of continuations and monads – The Web and all that Jazz
http://iamwil.posterous.com/64271154

Real time online activity monitor example with node.js and WebSocket
http://lchandara.wordpress.com/2011/08/07/real-time-online-activity-monitor-example-with-node-js-and-websocket/

Windows Azure Storage for Node.js
http://blogs.southworks.net/jpgarcia/2011/08/06/windows-azure-storage-for-node-js

Step by step instructions to install NodeJS on Windows
http://lchandara.wordpress.com/2011/08/05/step-by-step-instructions-to-install-nodejs-on-windows/

Easy Node.js Apps With Lisp
http://confreaks.net/videos/485-larubyconf2011-easy-node-js-apps-with-lisp

LearnBoost/tobi – GitHub
https://github.com/LearnBoost/tobi

NodeJS is easy, just ask her out
http://vincentwoo.com/2011/06/10/nodejs-is-easy-just-ask-her-out/

npm – Node Package Manager
http://npmjs.org/

nowjs for Node – Directly call remote functions in Javascript
http://nowjs.com/

Websockets everywhere with Socket.IO
http://howtonode.org/websockets-socketio

Running the “Express” web development framework on Node for Windows
http://weblogs.asp.net/cibrax/archive/2011/08/05/running-the-express-web-development-framework-on-node-for-windows.aspx

Orkis – online web based multiplayer tetris
http://orkis.skdev.me/

node.js – A giant step backwards – Fenn’s Thoughts
http://fenn.posterous.com/nodejs-a-giant-step-backwards

Learning Javascript with Object Graphs
http://howtonode.org/object-graphs

Bricks.js – Documentation
http://bricksjs.com/documentation.html

Node.js Beginner Book
http://davidhayden.com/blog/dave/archive/2011/07/31/NodejsBeginnerBook.aspx

The Node Beginner Book » A comprehensive Node.js tutorial
http://www.nodebeginner.org/

Node.js Creator Ryan Dahl’s Keynote from NodeConf
http://www.readwriteweb.com/hack/2011/07/nodejs-creator-ryan-dahls-keyn.php

Node.js, Ruby, and Python in Windows Azure
http://channel9.msdn.com/Shows/Cloud+Cover/Cloud-Cover-Episode-48-Nodejs-Ruby-and-Python-in-Windows-Azure

Reactor pattern
http://en.wikipedia.org/wiki/Reactor_pattern

The New Heroku (Part 2 of 4): Node.js & New HTTP Capabilities
http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/

Microsoft working with Joyent and the Node community to bring Node.js to Windows
http://blogs.msdn.com/b/interoperability/archive/2011/06/23/microsoft-working-with-joyent-and-the-node-community-to-bring-node-js-to-windows.aspx

Porting Node to Windows With Microsoft’s Help
http://blog.nodejs.org/2011/06/23/porting-node-to-windows-with-microsoft%E2%80%99s-help/

Do I need a server to use HTML5’s WebSockets? – Stack Overflow
http://stackoverflow.com/questions/1530023/do-i-need-a-server-to-use-html5s-websockets

Single Page Apps with Node.js. – blog.nodejitsu.com – scaling node.js applications one callback at a time.
http://blog.nodejitsu.com/single-page-apps-with-nodejs

Node Inspector – Node.js Debugger
http://www.youtube.com/watch?v=AOnK3NVnxL8

Where does node.js fit in a Microsoft / Azure / WCF / MVC project? – Stack Overflow
http://stackoverflow.com/questions/5269892/where-does-node-js-fit-in-a-microsoft-azure-wcf-mvc-project

NodeJS Tutorial with CouchDB and Haml – ErdNodeFlips
http://www.robsearles.com/2010/05/28/nodejs-tutorial-with-couchdb-and-haml-erdnodeflips/

isaacs/nave – GitHub
https://github.com/isaacs/nave
Virtual Environments for Node

Comparing clojure and node.js for speed
http://swizec.com/blog/comparing-clojure-and-node-js-for-speed/swizec/1593

node core vs userland – GitHub
https://github.com/joyent/node/wiki/node-core-vs-userland

Calipso – A Node CMS
http://calip.so/

My links:
http://www.delicious.com/ajlopez/nodejs

Haskell: Links, News and resources (1)

I’m interested in programming languages and in functional programming. Haskell study and practice is a good step towards grasping functional ideas. These are my links about this language:

http://en.wikipedia.org/wiki/Haskell_%28programming_language%29

Haskell (pronounced /ˈhæskəl/)[3][4] is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing.[5] It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language.[6] As a functional programming language, the primary control construct is the function. The language is rooted in the observations of Haskell Curry and his intellectual descendants, that "a proof is a program; the formula it proves is a type for the program".

Learn You a Haskell for Great Good! – Higher Order Functions
http://learnyouahaskell.com/higher-order-functions

Haskell :: Functional Programming with Types
http://en.wikibooks.org/wiki/Haskell

How to learn Haskell – Stack Overflow
http://stackoverflow.com/questions/1012573/how-to-learn-haskell

Try Haskell! An interactive tutorial in your browser
http://tryhaskell.org/

A Neighborhood of Infinity: The Infinitude of the Primes
http://blog.sigfpe.com/2011/07/infinitude-of-primes.html

InfoQ: Multicore Programming in Haskell
http://www.infoq.com/presentations/Multicore-Programming-in-Haskell

Yesod :: Enumerator Package
http://www.yesodweb.com/book/enumerator

The implementation of the Gofer functional programming system
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.117.5058

I1M2010: Operaciones con el TAD de los polinomios en Haskell | Vestigium
http://www.glc.us.es/~jalonso/vestigium/i1m2010-operaciones-con-el-el-tad-de-los-polinomios-en-haskell/

Un problema de las olimpiadas rusas en Haskell | Vestigium
http://www.glc.us.es/~jalonso/vestigium/un-problema-de-las-olimpiadas-rusas-en-haskell/

Applicative Programming with Effects
http://www.soi.city.ac.uk/~ross/papers/Applicative.html

Arrows: A General Interface to Computation
http://www.haskell.org/arrows/

Haskell/Understanding arrows – Wikibooks, open books for an open world
http://en.wikibooks.org/wiki/Haskell/Understanding_arrows

Haskell :: Functional Programming with Types
http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html

Functional Languages will Rule (but not this year) – Good Stuff
http://goodstuff.im/functional-languages-will-rule-but-not-this-y

Ruminations of a Programmer: Combinators as the sublanguage of DSL syntax
http://debasishg.blogspot.com/2011/05/combinators-as-sublanguage-of-dsl.html

The Algebra of Data, and the Calculus of Mutation » Lab49 Blog
http://blog.lab49.com/archives/3011

Type inference – Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Type_inference

The Joy of Haskell, parte 1 – Introdução « Ars Physica
http://arsphysica.wordpress.com/2011/04/18/haskell1/

A Neighborhood of Infinity: Generalising Gödel’s Theorem with Multiple Worlds. Part II.
http://blog.sigfpe.com/2010/12/generalising-godels-theorem-with_24.html

The Arrows Calculus
http://homepages.inf.ed.ac.uk/wadler/papers/arrows-jfp/arrows-jfp.pdf

Wadler’s Blog: The Arrow Calculus
http://wadler.blogspot.com/2010/11/arrow-calculus.html

Program Haskell with Lisp Syntax Using Liskell or Lisk
http://www.readwriteweb.com/hack/2010/11/haskell-with-lisp-syntax.php

Lisk – Lisp and Haskell
http://chrisdone.com/posts/2010-11-25-lisk-lisp-haskell.html

johang88’s haskellinjavascript at master – GitHub
http://github.com/johang88/haskellinjavascript

Conal Elliott » “Everything is a function” in Haskell?
http://conal.net/blog/posts/everything-is-a-function-in-haskell/

Haskell: The Confusing Parts
http://echo.rsmw.net/n00bfaq.html

Video presentations – HaskellWiki
http://www.haskell.org/haskellwiki/Video_presentations

A Neighborhood of Infinity: Products, Limits and Parametric Polymorphism
http://blog.sigfpe.com/2010/03/products-limits-and-parametric.html

My Links
http://www.delicious.com/ajlopez/haskell

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

AjLisp in Javascript (Part 1) Atoms, Lists and TDD

Next Post

I’m rewriting my AjLisp interpreter using Javascript. I think that a Lisp interpreter is a good project to learn a language: simple, bounded but not trivial. I would never have begun this project without TDD (Test-Driven Development): Javascript is so dynamic and the tools I’m using (the browser, plain text editors) are so limited, that this project have been hard without the help of TDD. The practice of TDD gives me fun, doing baby steps and it helps me to explore good design.

The code (with parser, many primitive forms, some macro procession, work in progress) is at GitHub:

https://github.com/ajlopez/AjLispJs

The code is in one file: https://github.com/ajlopez/AjLispJs/blob/master/src/ajlisp.js

I’m using QUnit for tests:

The implementation uses the namespace pattern:

AjLisp = function() {
// ...
}();

The namespace is the result of evaluate a function. This function returns an object with the public members of the namespace:

return {
	// Classes
	List: List,
	Environment: Environment,
	Atom: Atom,
	Closure: Closure,
	Lexer: Lexer,
	TokenType: TokenType,
	Parser: Parser,
	
	// Functions
	makeList: makeList,
	isAtom: isAtom,
	isList: isList,
	isNil: isNil,
	asString: asString,
	evaluate: evaluate,
	
	// Top Environment
	environment: environment
}

As usual, a Lisp interpreter should support lists and atoms. Partial code:

function List(first, rest) {
	function getFirst() {
		return first;
	}
	
	function getRest() {
		return rest;
	}
	
	this.first = getFirst;
	this.rest = getRest;
}
List.prototype.isAtom = function() { return false; }
List.prototype.isList = function() { return true; }
List.prototype.evaluate = function(environment) 
{
	var form = this.first().evaluate(environment);		
	return form.apply(this, environment);
}	
// ...

Note that the first and rest part of a list are encapsulated in the constructor closure. They are inmutable, and can be accesed by functions aList.first(), aList.rest(). I should evaluate the impact of all those closure at list construction. But they are relative light.

Atom implementation is simple:

function Atom(name) {
	this.evaluate = function(environment) {
		return environment.getValue(name);
	};
	
	this.name = function() { return name; };
}
Atom.prototype.isAtom = function() { return true; }
Atom.prototype.isList = function() { return false; }
Atom.prototype.asString = function() { return this.name(); }
Atom.prototype.equals = function(atom)
{
	if (isNil(atom) || !isAtom(atom))
		return false;
		
	return this.name() == atom.name();
}

The atom evaluation is based in an enviroment (association of names to values) and the atom name. Numbers, strings are direct Javascript objects and they don’t need to be implemented as atoms. In a “classical” Lisp implementation, all elements are SExpressions (symbolic expressions) capable of being evaluated. Now, I have AjLisp.evaluate that accepts any Javascript object and detect if it can be evaluated in an environment:

function evaluate(x, environment)
{
	if (x === null || x === undefined)
		return x;
		
	if (x.evaluate != undefined && typeof(x.evaluate) == "function")
		return x.evaluate(environment);
		
	return x;
}

Atom tests:

test("Atom", function() {
	var environment = new AjLisp.Environment();
	environment.setValue("one", 1);
	var one = new AjLisp.Atom("one");
	equal(one.evaluate(environment), 1);
	ok(one.isAtom());
	equal(one.isList(), false);
	ok(AjLisp.isAtom(one));
	equal(AjLisp.isList(one), false);
	equal(one.asString(), "one");
	equal(one.equals(one), true);
	var one2 = new AjLisp.Atom("one");
	equal(one.equals(one2), true);
});

Test exercising list behavior:

test("List", function() {
	var list = new AjLisp.List(1,2);
	equals(list.first(), 1);
	equals(list.rest(), 2);
	equal(list.isAtom(),false);
	equal(list.isList(),true);
	equal(AjLisp.isAtom(list), false);
	equal(AjLisp.isList(list), true);
	equal(list.asString(), "(1.2)");
	equal(list.equals(list), true);
	var list2 = new AjLisp.List(1,2);
	equal(list.equals(list2), true);
	equal(list2.equals(list), true);
	var list3 = AjLisp.makeList(1,2,3);
	equal(list.equals(list3), false);
	equal(list3.equals(list), false);
	list = AjLisp.makeList(null, null);
	ok(list.first() === null);
	ok(list.rest().first() === null);
});

Pending topics: environment implementation, list evaluation, forms and special forms, parser, lambda, mlambda, flambda. Lot of fun! 😉

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez