EMACS 25.1 + SLIME on Windows 10

Here is my Lisp Development Environment setup on Windows 10:

  1. Clozure Lisp http://ccl.clozure.com/
    Unzip the Windows Zip ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-windows.zip
    Add the Lisp path to PATH variable.
  2. EMACS 25.1
    Unzip the Windows 64 binaries emacs-25.1-x86_64-w64-mingw32.zip and run bin/runemacs.exe
  3. QuickLisp
    Download the QuickLisp lisp files https://beta.quicklisp.org/quicklisp.lisp

    wx86cl64.exe -load <path to quicklisp.lisp>
  4. SLIME
    Open your emacs configuration file in EmacsCTRL+X CTRL+F -then-> ~/.emacsThen insert following entries to enable MELPA repository

    (when (>= emacs-major-version 24)
     (require 'package)
     '("melpa" . "http://melpa.org/packages/")

    Now restart Emacs. After restart type  ALT+X and type

    package-install RET slime

    Then set following values in Emacs configuration file (“~/.emacs”)

    ;;; Lisp - SLIME
    (setq inferior-lisp-program "C:/ccl-1.11-windows/wx86cl64.exe")
    (setq slime-contribs '(slime-fancy))

    Now on restart of Emacs, when I type CTRL+X slime I get following SLIME prompt


Enjoying Lisp + Emacs


Emacs – 101

I have recently developed interest in learning Emacs editor. I have been learning Functional Programming languages like Haskell and lately Erlang and was looking for Editor/IDE for them. IntelliJ Idea have plugins for these languages but the IDE is very heavy. So came to Emacs and am learning it. Particularly like the idea that every thing can be done with keyboard shortcut so no need to move hands between mouse and keyboards.

A bit of warning for faint hearts, don’t try emacs as quick learning. It has steep learning curve.

I have started with basic navigation commands like (these are for WINDOWS) :

CTRL+c CTRL+f : Open a file

Move in file :

CTRL+f : move forward one character (RIGHT key)

CTRL+b : move back one character (LEFT key)

CTRL+n : move down on next line (DOWN key)

CTRL+p : move up on previous line (UP key)

CTRL+a : Move to the beginning of the lines (Home key)

CTRL+e : Move to the end of the lines (End key)

ALT+f : Move forward one word

ALT+b : Move backward one word

Other navigation:

ALT+r : Moves to center most line of window

ALT+< : Move to top of the buffer

ALT+> : Move to end of the buffer

CTRL+v : PageDown key

ALT+v : PageUp key


The other good feature is Org-mode. For beginners found the tutorial at http://orgmode.org/worg/org-tutorials/org4beginners.html

What is Org-mode?

From the website orgmode.org :

“Org mode is for keeping notes, maintaining TODO lists, planning projects, and authoring documents with a fast and effective plain-text system.”

The  Org-Babel model can be use to write Literate Programming Documents.

More to come…


Haskell OpenCL on Windows

To try running OpenCL bindings in Haskell (https://github.com/HIPERFIT/hopencl) I had installed Intel SDK for OpenCL (https://software.intel.com/en-us/intel-opencl) on Windows 8.1 64 bit machine.

To install hopencl, the instructions is :

cabal install c2hs
cabal install

The first command to install c2hs succeeded.
The second command to install hopencl failed with :

Resolving dependencies...
In order, the following will be installed:
hopencl-0.2.1 (reinstall)
Configuring hopencl-0.2.1...
Failed to install hopencl-0.2.1
Build log ( C:\Users\...\AppData\Roaming\cabal\logs\hopencl-0.2.1.log ):
Configuring hopencl-0.2.1...
setup.exe: Missing dependency on a foreign library:
* Missing C library: OpenCL
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.

To make it compile sepcify the OpenCL include and lib like :

C:\>cabal install --ext
ra-include-dirs="c:\Program Files (x86)\Intel\OpenCL SDK\include" --extra-lib-di
rs="c:\Program Files (x86)\Intel\OpenCL SDK\lib\x64"

Mobile Enabled Razor View Engine

Today I was trying to add jQuery Mobile to my project. To start with I found Scott Hanselman’s blog entry

A Better ASP.NET MVC Mobile Device Capabilities ViewEngine . I used the code by deriving the RazorViewEngine. My class looks like this:


  1. public class WebEnabledViewEngine : RazorViewEngine
  2.     {
  3.         public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
  4.         {
  5.             ViewEngineResult result = null;
  6.             var request = controllerContext.HttpContext.Request;
  8.             // Avoid unnecessary checks if this device isn't suspected to be a mobile device
  9.             if (request.Browser.IsMobileDevice)
  10.             {
  11.                 result = base.FindView(controllerContext, "Mobile/" + viewName, masterName, useCache);
  12.             }
  14.             //Fall back to desktop view if no other view has been selected
  15.             if (result == null || result.View == null)
  16.             {
  17.                 result = base.FindView(controllerContext, viewName, masterName, useCache);
  18.             }
  20.             return result;
  21.         }
  22.     }


Apparently Scott has marked his blog entry as broken. The issue I was facing was that my jQuery Mobile site  was running good but the desktop version failed to load script files. So I end up adding following routing entry and now both version work’s good.


  1. routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });

MEF Tip : Importing multiple instances of a Contract

In the last post, I have used following Contract

Code Snippet
  1. public interface ILogger
  2.     {
  3.         void Debug(string message);
  4.         void Error(string message);
  5.         void Warn(string message);
  6.     }


To import a collection of ILogger the ImportManyAttribute  can be used like:


Code Snippet
  1. [ImportMany(typeof(ILogger))]
  2. public IEnumerable<ILogger> Loggers { get; set; }

Composition using MEF


With .NET 4.0 Microsoft ships a new composition container named Managed Extensibility Framework (MEF). MEF already have two feathers in the cap: Visual Studio 2010 editor extensions and Intellipad, the DSL editor of OSLO SQL Server Modeling.

MEF can be used to achieve the object-oriented programming  principle “Open-Closed Principle (OCP)”  software entities (classes, modules, functions, etc.) should be open for extension, but closed for modifications. What that means to me is that it should be possible to extend the application without modifying its case. For example, if an application was programmed to log to an text file and a later point of time if the requirement is to write to a console, then it should be possible to do so without modifying the source code. To achieve OCP we need to provide extension points. We can found a lot of such examples in the addin model of the applications like Visual Studio text editor, Outlook, WinAmp etc.


The fundamental concepts in MEF are : Import, Export, Composable Part, Contracts, Composition. The following diagram shows how they are related :



A Composable Part should have at least one or more Export or Import. Imports and Exports are defined using Contracts.  A catalog of parts is used by container to compose the parts. Lets see a simple example of this.


Let’s define a contract first for the Imports and Exports. I have a ILogger interface as contract.

Code Snippet
  1. public interface ILogger
  2.     {
  3.         void Debug(string message);
  4.         void Error(string message);
  5.         void Warn(string message);
  6.     }


A ConsoleLogger class which implements ILogger and writes to the Console.

Code Snippet
  1. using System;
  2. using System.ComponentModel.Composition;
  5. namespace CdcSoftware.Loggers
  6. {
  7.     [Export(typeof(ILogger))]
  8.     public class ConsoleLogger : ILogger
  9.     {
  10.         #region ILogger Members
  12.         public void Debug(string message)
  13.         {
  14.             Console.WriteLine("[DEBUG] " +  message);
  15.         }
  17.         public void Error(string message)
  18.         {
  19.             Console.WriteLine("[ERROR] " + message);
  20.         }
  22.         public void Warn(string message)
  23.         {
  24.             Console.WriteLine("[WARN] " + message);
  25.         }
  27.         #endregion
  28.     }
  29. }


At line no. 2 the we import System.ComponentModel.Composition namespace from the references assembly System.ComponentModel.Composition one of the MEF assembly. This is required for the ExportAttribute used at line no. 7. By using Export attribute we have exported the ConsoleLogger as a composable part .

Now we have a contract and an export. Lets see the code to import. To import we need to use the ImportAttribute like this. 

Code Snippet
  1. [Import(typeof(ILogger))]
  2. public ILogger Logger { get; set; }

Now lets compose it.

Code Snippet
  1. using System.ComponentModel.Composition;
  2. using System.ComponentModel.Composition.Hosting;
  3. using System.Reflection;
  5. namespace CdcSoftware.Application
  6. {
  7.     public class ComposedApplication
  8.     {
  9.         [Import(typeof(ILogger))]
  10.         public ILogger Logger { get; set; }
  12.         public static void Main(string[] args)
  13.         {
  14.             ComposedApplication app = new ComposedApplication();
  15.             app.Run();
  16.         }
  18.         private void Run()
  19.         {
  20.             Compose();
  21.             //now the application dependency is composed
  22.             Logger.Debug("This is a debug message");
  23.         }
  25.         private void Compose()
  26.         {
  27.             AssemblyCatalog catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
  28.             CompositionContainer mefContainer = new CompositionContainer(catalog);
  29.             mefContainer.ComposeParts(this);
  30.         }
  32.     }
  33. }


On start of the ComposedApplication, the first thing we do is to compose it as in line 20. For this application since all the required parts viz. Imports and Exports, are in the same assembly I am using AssemblyCatalog at line no 27 and initializing with the executing assembly. Then the CompositionContainer is instantiated with this catalog as constructor parameter. To get the dependency fulfilled or the part composed, we need to call the ComposeParts method on the container as in line 29.  After the composition succeeds, all the imports the current class will be fulfilled like the Logger property.


References :

Where is Python absolutely necessary in Intellipad? http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/7a440138-1417-4414-89c3-2e6ecd2ab430

Managed Extensibility Framework in the Editor http://msdn.microsoft.com/en-us/library/dd885013.aspx

Dynamic Language Runtime in Pivotal Client

One of the new additions to the .NET Framework 4.0 is Dynamic Language Runtime.  From the MSDN documentation:

The dynamic language runtime (DLR) is a runtime environment that adds a set of services for dynamic languages to the common language runtime (CLR). The DLR makes it easier to develop dynamic languages to run on the .NET Framework and to add dynamic features to statically typed languages.

Advantages of dynamic languages:

  • The ability to use a rapid feedback loop. This lets you enter several statements and immediately execute them to see the results.
  • Support for both top-down development and more traditional bottom-up development.
  • Easier refactoring and code modifications, because you do not have to change static type declarations throughout the code.

The purpose of the DLR is to enable a system of dynamic languages to run on the .NET Framework and give them .NET interoperability.

Like the CLR, the DLR is a part of the .NET Framework and is provided with the .NET Framework and Visual Studio installation packages. The open-source version of the DLR is also available for download on the CodePlex Web site.

The DLR provides the following advantages.

  • Simplifies Porting Dynamic Languages to the .NET Framework
  • Enables Dynamic Features in Statically Typed Languages
  • Provides Future Benefits of the DLR and .NET Framework
  • Enables Sharing of Libraries and Objects
  • Provides Fast Dynamic Dispatch and Invocation

DLR architecture.

DLR architecture

IronPython and IronRuby are implementation of Python and Ruby using DLR on .NET runtime.

IronPython Hosting in Pivotal Client

To host IronPython we need to reference following dlls available for download from IronPython CodePlex site http://ironpython.codeplex.com/

  • IronPython.dll
  • IronPython.Modules.dll
  • Microsoft.Scripting.dll
  • Microsoft.Scripting.Core.dll
  • Microsoft.Scripting.ExtensionAttribute.dll

To run IronPython code, create Python script engine, ScriptScope, ScriptSource objects and execute the ScriptSource using Execute method as shown below.

ScriptScope scope = engine.CreateScope();

ScriptSource source = engine.CreateScriptSourceFromString(this.CodeEditor.Text, SourceCodeKind.Statements);

scope = engine.CreateScope();


In IronPython to access classes from the .NET framework, your application must have a reference to the assemblies you want to use.

import clr


Having added the reference, you can import from the namespace inside the assembly. Usually this will have the same name as the assembly.

from System.Windows.Forms import *

Similarly to reference any custom classes, add reference and import types from it. For example, here I am adding reference of Pivotal.Engine.Client.Services.Interfaces assembly and importing a number of classes, interfaces and enumerations. ActionContent, ActionCommand and ActionTargetWindow are enumerations, ClientContext is a static class and rest are interfaces.


from CdcSoftware.Pivotal.Engine.Client.Services.Interfaces import ( ActionContent , ActionTargetWindow ,

ClientContext , IActionService, ActionCommand, IFormActionTarget, IDataAccessService, ISearchActionTarget )