1. # Spell Check

Me: write a spell checker in scheme that implements suggestions of corrections using the levenstein distance

ChatGPT:

(define (levenstein-distance str1 str2)
(define (min3 a b c)
(min (min a b) c))

(define (lev-distance str1-len str2-len)
(if (or (= str1-len 0) (= str2-len 0))
(max str1-len str2-len)
(let ((cost (if (char=? (string-ref str1 …
2. # Display Strings

Displaying a string in guile has the speed:

> (define p (open-file "/dev/null" "w"))
> (define x (make-string 100000000 #\a))
> ,time (begin (display x p) 1)

1.015054s real time, 1.014577s run time.  0.000000s spent in GC.


That's about 100MByte of data pushed out in 1 …

3. # Printing Doubles

Printing reals in guile head has the following characteristics.

> (define x (make-vector 10000000 0.8888888888888888888888))
> (define p (open-file "/dev/null" "w"))
> time (begin (write x p) 1)

15.812557s real time, 15.808950s run time.  0.000000s spent in GC.


Now with my heavily optimized SCM/C …

4. # Suspendable Soft Ports

Guile has the ability to define a soft port e.g. create a port with scheme code handlers that are executed in stead of C code when basic operations on the port is done. This works quite ok as long as one does not trip up due to the continuation …

5. # One Shot Prolog

We are going to play with an idea how to implement prolog programs using one shot continuation or simply where we allow a stack-code unit to be attached and detached to the active stack at will.

So the building blocks are that each predicate, $$f$$, is defined as a vector …

6. # Association Performans Test

We did some series of benchmarking between the fast assoc taking advantage of SIMD, the fast hash taking advantage of SIMD, normal assoc and normal guile hash. The keys used was integers and we performd tests for different sizes (N) with a differnt sizes subsample (M).

Here is the table …

7. # Association List

For small numbers of elements in an assoc list we know that a simple list assoc search is faster than a hash table lookup. The question is can we improve on the association list? First of all we could search a vector in stead of a list or even lay …

8. # Hash tables

Hash tables are a real workhorse for programmers and is essentially a quite effective way to store an association between a key and a value. For small number of pairs a simple association list is quite efficient. But for larger numbers of elements, a hash table is usually best until …

9. # One Shot Continuations

Guile has adjustable stacks and one thing that struck me when implementing generators in python on guile with the help of delimited continuations are that the overhead is pretty high as one need to tear down store, reload and tear up the stack for it. If you apply the continuation …

10. # Call And Define

In functional programming we pass the state as arguments to functions. It can be tedious to track all funciton arguments and not only this when we want to add an extra state parameter to a huge codebas you end up in an never ending work of updating function arguments and …

11. # functool

Considering associate meta information to functions. Closures are at your service but the question I had is if we could make it more functional. The idea is that at each time the value of a handle is unique and cloning is done through copying. Also we would like this to …

12. # Native Compilation

To compile scheme to native code natively how would we go about? Generating assebler and have a native compiler is kind of difficult if we want to reach a system that can compile to many different targets. What we would like is to take a scheme file and output byte …

13. # Tables

As soon as you see a table most computer programmers probably think about databases. And that's probably right, many times. But always?

In a table we manage a set of rows with a key or id field. If the table is small, say less than 10.000 the science of …

14. # Text Data Structure

This is a short discussion about how to model a flow of data enabling sharing and moving trough the datastructure in a left to right fashion. We ould like to cut out objects and insert them in other places and maintain everything in a prolog like datastructure.

The idea of …

15. # Paralell 2 Ideom

This is a continuation of the paralell conjunction ideom i've been working on. Previously the system could not handle variables that is located in many branches at the same time e.g. if you set X=1 in one branch and X=2 in another you would get into troubles …

16. # Paralell Ideom

Execution of prolog code is sequential in nature, but one would like to be able to execute multiple algorithm in paralell. Turns out that swi's engine's are quite good att performing this task for us, we can fire up one engine per algorithm and generate answers back and let them …

17. # Store The State Of Multiple Paralell Engines

My next task for guile-log is to make paralell engines store and restorable. This does not work before. In order to see how one can solve this with the already implemented framework, lets first recap paralell engines.

By issuing paralell engines e1,...en we device a scheme where we manually …

18. # Guile fibers

Check out wingo's fibers. I added support for fibers in guile-log and guile-log prolog. Fibers are an attempt to model multitasking, like in erlang, with cooperative scheduling (meaning that you need to enter a sleep now and then to allow other threads to run. Currently the interface is very simplistic …

19. # Swi Engines in Guile Log

A recent addition to swi prolog is engines. These objects are self contained prolog engines with their own stack that maintaines the computation state and will generate each answer back stepwise. Guile log have implemented the same API and is reachable from the library (logic guile-log guile-prolog engine). A good …

20. # Dependency and Guile Log

Having had a taste for executing things in paralell in kanren let's move over to guile-log. Executing stuff in paralell is similar but we can take advantage of variable binding beeing done directly on the variable and not bound in a binding data structure. The idea is for each engine …

21. # Dependency and Kanren

We will discuss here a kanren version that will modify just partial results and not redo the whole datastructure in order change an underlying value. This means that we are considering paralell executions of code that only modify the data relevant to their code section the solution is a combination …

22. # Continuations in Minikanren

Swi prolog recently got predicate continuation and knowing of extearamly functional minkanren/microkanren is, one should be able to construct such a beast. Now in most languages you would need to make sure that a cach throw mechanism is working in the return values and somehow knit that together. But …

23. # Fast Looping in Prolog

When coding my prolog VM I noticed that the overhead of a prolog call is in the order of 2M execution per second, and this is typically what I see when executing simple prolog perdicates in swi prolog as well. So all complexity that one need to care for simply …

24. # Set Mania

We are going to explore how set's are handled in guile-log prolog. Lets start off simple.

To define a set just do:

X is {1,2,3}.

X = {1,2,3}


We have added common set operators e.g.

% union e.g. all combined elements (cup in latex).
?- X is …
25. # Versioning

Consider a variables, a box with a value. Guile-log has the notion of a state. At any point in time all the prolog varibales are bound. And this information can be stored in a state. The guile-log variables are more general than pure prolog variables in that they can be …

26. # Return Values

Prolog passes all in,out,in/out values as arguments to the predicate. This has the drawback, for out variables, that the variables need to be allocated from the heap and adds complexity and overhead to the predicate. If in stead the out variables could be passed over without making …

27. # Type Magic

Let's consider the task to match something that has a type. We could use the extended matcher and :<, :, :>, as a default. If we don't like it it is possible to redefine it. So what to expect. We genereally constrain types to be of a certain type.

f(X :< number, Y …
28. # A Functional Findall in Kanren

How do we implement prologs findall in kanren. Prolog findall e.g:

f(X) :- findall(Y,g(Y),X)


Has the semantic to make a list of all Y solving g(Y) and put it in X. Now kanren is not minikanren, but something close to it and today much …