Making use of Scheme: Calling Built-In Libraries

How to Use Built-in Libraries: A Quick Example

Making use of Scheme: Calling Built-In Libraries

In this section we will give you some idea of the libraries and features of the Scheme world. VSA® extends IronScheme. In this first version of AcceλerateTM for Microsoft 365, our additions have been minimal, as our focus has been integration into Excel; but over time you will find that we are focused on linked data and web serving as key elements in bringing desktop artifacts into the world of data interoperability through data sharing over microservices. Subsequent versions will significantly expand your ability to make the data in these siloed environments more interoperable.

VSA fully implements 99% of the R6RS specification (with the minor exception of advanced continuation support, disallowed by the .NET runtime), provides dozens of SRFIs that have been vetted and proven over the years by the larger Scheme community, and includes a number of other well-known libraries and frameworks for things like unit testing, purely functional data structures, logic programming, and even object-oriented programming.

The goal of this brief section is merely to make you “situationally aware” of what’s available and give you enough information to explore the code yourself. We encourage everyone so inclined to try out ways to integrate these built-in libraries and frameworks into their use of Acceλerate. It will prove very helpful for you as you learn the language to see how others have written useful libraries and transformed Scheme into precisely the language they needed it to become for various diverse tasks.

Below is a list of frameworks and libraries you will find in the \lib subdirectory of your Acceλerate for Microsoft 365 installation directory. The respective licenses of these libraries can be found where they are stored, in the \lib directory of your Acceλerate installation.






A variety of utilities mainly aimed at providing access to .NET functionality through idiomatic Scheme library wrappers.



A full-blown, quite well-known logic programming “micro-framework” that you can learn about in The Reasoned Schemer. (See Helpful References and Resources.)



A library of “purely functional data structures.” These are data structures which avoid mutability and are therefore generally a great fit for “pure functional” programming.


Collection of standalone libraries

SRFI stands for “Scheme Request for Implementation” and they are one-off, usually quite small libraries that are intended to add/extend the core Scheme language in a community-driven way. Dozens of accepted SRFIs are included for your use. 



These are libraries that are the core of VSA. 



A collection of useful libraries implemented and/or curated by well-known Schemers.



Pattern matching library.



Benchmarking library



Abstract data type library.



Implementation of a well-known diff algorithm.



Implementation of functional vectors.



Matching algorithm for lists



Another pattern matching library.



Entry point to the minikanren micro-framework.



A portable regular expression library.



A library for regression testing



A utility for currying



A small object-oriented framework that emulates Smalltalk’s dynamic, message-passing style.



The primary entry point to the visualscheme library.

As you can see, there are a LOT of libraries at your disposal in “pure Scheme” that we hope will inspire you to learn, use, and master this simple but subtle language. It is good at things neither VBA nor Excel’s formula expression language were built for, and it is now a full-fledged partner with both of these traditional Excel tools to help you get the most out of Excel’s unique computation engine.

We believe that integrating it into Excel as fully as we have endeavored to do so - bringing new functions to Excel to make it easy to incorporate Scheme code, an editor to make authoring custom functions written in Scheme, and even including a proper REPL experience - will prove a powerful new way to transform the use of spreadsheets in the coming era of data interoperability.

As we expand our reach into the other applications that are part of Microsoft 365, especially Access, our upcoming enhancements will, we think, put VSA in a unique position to help you move your solutions into the cloud (and beyond), on your terms.

How to Use Built-in Libraries: A Quick Example

In the meantime, you can use the many libraries provided to do some interesting, fun, and useful things. We will provide here a brief example of using “minikanren,” a library for logic programming that has a long, rich history. “Kanren” is Japanese for “relation” and logic programming is sometimes referred to as “relational programming,” as the main computational operation is reasoning about relations between things. As its name suggests, minikanren is therefore a “mini” framework for relational programming that allows you to do some powerful relational inference based on data.

You can play with minikanren in the REPL by importing it into the runtime:

(import (minikanren))

Then of course CTRL-Shift-T to test it out:

For the more curious: Using minikanren requires familiarizing yourself with its approach to the task of automated reasoning, something that is beyond the scope of this overview. What we will do is give you a taste of it in action. For a deeper understanding of the topic, we highly recommend you read The Reasoned Schemer, Second Edition, by D. Friedman (The MIT Press, 1998), a classic exposition of the realm of logic programming in which the core of minikanren is built up from first principles, one concept at a time. In general, the series of which that book is a part is required reading for anyone interested in programming, whether they plan to master Scheme itself or not. What will surprise you is how small the library actually is. This is a testimony to how powerful the simple concepts underlying Scheme really are. There is a cottage industry of porting minikanren to other languages, but it’s very difficult to find one that can touch Scheme’s implementation for brevity, elegance, and simplicity. It should be noted that the version of minikanren included is aligned with the first edition of the book, but we will be updating it for the latest version soon. Nevertheless, the changes to minikanren in the latest version of the book are easy to back-port to the version used in the original edition.

So the following is a trivial but still interesting example of how you can use minikanren. In this example we are interested in the question:

Given a list of values, what possible combinations of appending two lists can produce it?

This question might be easier to conceptualize with a concrete example:

'(1 2 3 4)

So the question is, what two-list combinations can be appended to produce exactly that list?

There is a standard Scheme function called “append” to append two lists, producing a new list, combining the values of the original two lists, in order. So for example:

(append '(1 2) '(3 4))


That is clearly one of the answers. But we want all of them. If you were to sit down and imagine how to code this in, say, VBA or C#, you’d quickly realize that it is not an easy or straightforward problem using brute force searching. Basically, this is what is known as a constraint satisfaction problem. The idea is to search a solution space for possibly correct answers to a well defined (aka constrained) problem.

Minikanren has a number of operators modeled after standard functions like append, that allow them to bring analogous functionality to the context of solution-space searching. The convention is to add an “o” at the end of functions “ported” for use in a minikanren relational programming context. The process of porting such functions for this purpose is explained in great detail in The Reasoned Schemer book referenced above. Needless to say, “append” is one of the examples it uses and its analogous function is therefore called “appendo.”

So, we can answer this question using appendo. The idea is to frame it as a search problem, and the following captures the essence of how to do it. We will define a new function, called “appendos,” which takes a list, which we name “lst”, and returns all the two-list combinations that can append to create the “lst”.

(define appendos
  (lambda (lst)
    (run* (q)
       (fresh (x y)
         (appendo x y lst)
         (== q (list x y))))))

While that may look kind of cryptic at this point in your journey, just know that run* means “find all”; can be thought of as the query result; and fresh is basically assigning temporary variables to be used as a solution space is iterated. What it is saying is, find all combinations of two lists, x and y, that when appended, result in the input list. The ==  or “unify” operator here means “unify the query results with only those combinations of x and y that, when appended, result in the input list.”

So you see it’s basically a query language of sorts. What is kind of surprising is that with just the 5 lines of code from “(run* …)” to the end of the function the answer can be obtained for any list you might send in. Let’s test it. 

First, CTRL-Shift-T:

So far so good. Let’s test our simple example first.

(appendos '(1 2 3 4))


Not only did it tell us how many there are, it listed them all for us. This is because we used run* - we could have just asked for 1 or 2 or some other number of values to return.

We can test bigger lists, and get bigger answers:

Note how fast it executes. Since lists are inherently generic, you can try this with lists of strings or other data types as well.

Although perhaps not immediately obvious through this somewhat contrived example, the implications here are that we can frame queries to hard constraint problems in a simple “mini language” built in Scheme called minikanren (now, because of Acceλerate for Microsoft 365, part of Excel), that will vastly simplify the problem of iterating a solution space for correct answers.

Now you should be able to imagine how useful this could be ported into a spreadsheet model. We will be demonstrating how to do just that in future blog posts, video demos and examples as we evolve Acceλerate further.

The following terms are registered trademarks of the Microsoft group of companies and are used in accordance with Microsoft’s Trade and Brand Guidelines: Microsoft, Microsoft 365, Microsoft Office, Microsoft Excel, Microsoft Edge, Microsoft Edge WebView2, Microsoft Windows, Excel, Office 365

The following terms are registered trademarks of Apex Data Solutions: Visual Scheme, VSA.

Copyright © 2022.  Apex Data Solutions, LLC. All Rights Reserved.