μKanren: A Minimal Functional Core for Relational Programming

Discuss the future of the AutoHotkey language
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

μKanren: A Minimal Functional Core for Relational Programming

16 Oct 2017, 03:23

I would like to propose the native implementation of the relational programming paradigm, represented by the minikanren language.
The minikanren.org site offers more insights.

I ask the more experienced AHK if they can implement the minikanren language in AHK, in order to be able to check out the enormous potential that it offers, maybe before thinking about implementing it natively.
It could also be a remarkable exercise to enter the minikanren.org site to demonstrate the flexibility of AHK, but this is out of my reach and requires master AHK knowledge.

Having a native implementation would be a big plus: today, the only environment that internally integrates with minikanren is Clojure, a Lisp derived language that works in a Java environment.

Only 40 lines of code written in the Scheme language would allow to implement the core of minikanren!
Search online for HemannMuKanren2013.pdf implementation document in Scheme Language, reported below:

Code: Select all

(define (var c) (vector c))
(define (var? x) (vector? x))
(define (var=? x1 x2) (= (vector-ref x1 0) (vector-ref x2 0)))

(define (walk u s)
	(let ((pr (and (var? u) (assp (λ (v) (var=? u v)) s))))
		(if pr (walk (cdr pr) s) u)))

(define (ext-s x v s) `((,x . ,v) . ,s))

(define (≡ u v)
	(λg(s/c)
		(let ((s (unify u v (car s/c))))
			(if s (unit `(,s . ,(cdr s/c))) mzero))))

(define (unit s/c) (cons s/c mzero))
(define mzero '())

(define (unify u v s)
	(let ((u (walk u s)) (v (walk v s)))
		(cond
			((and (var? u) (var? v) (var=? u v)) s)
			((var? u) (ext-s u v s))
			((var? v) (ext-s v u s))
			((and (pair? u) (pair? v))
				(let ((s (unify (car u) (car v) s)))
					(and s (unify (cdr u) (cdr v) s))))
			(else (and (eqv? u v) s)))))

(define (call/fresh f)
	(λg(s/c)
		(let ((c (cdr s/c)))
			((f (var c)) `(,(car s/c) . ,(+ c 1))))))

(define (disj g1 g2) (λg(s/c) (mplus (g1 s/c) (g2 s/c))))
(define (conj g1 g2) (λg(s/c) (bind (g1 s/c) g2)))

(define (mplus $1 $2)
	(cond
		((null? $1) $2)
		((procedure? $1) (λ$() (mplus $2 ($1))))
		(else (cons (car $1) (mplus (cdr $1) $2)))))

(define (bind $ g)
	(cond
		((null? $) mzero)
		((procedure? $) (λ$() (bind ($) g)))
		(else (mplus (g (car $)) (bind (cdr $) g)))))
I hope Minikanren can inspire the AHK chief developer in the best way: it's small, compact, powerful, advanced, projected in the future.
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

Re: μKanren: A Minimal Functional Core for Relational Programming

16 Oct 2017, 04:08

To clarify already in these lines what is the relational programming, I rewrite some lines of the page:
http://minikanren.org/minikanren-and-prolog.html
In Scheme language the append function can append two lists, returning a new list: the function call

Code: Select all

(append '(a b c) '(d e))
returns the list (a b c d e).
We can, however, also treat append as a three-place relation rather than as a two-argument function. The call

Code: Select all

(appendo '(a b c) '(d e) Z)
would then associate the logic variable Z with the list (a b c d e).
Of course things get more interesting when we place logic variables in other positions.
The call

Code: Select all

(appendo X '(d e) '(a b c d e))
associates X with (a b c), while the call

Code: Select all

(appendo X Y '(a b c d e))
associates X and Y with pairs of lists that, when appended, are equal to (a b c d e).
For example X = (a b) and Y = (c d e) are one such pair of values.
We can also write

Code: Select all

(appendo X Y Z)
which will produce infinitely many triples of lists X, Y, and Z such that appending X to Y produces Z.
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: μKanren: A Minimal Functional Core for Relational Programming

16 Oct 2017, 07:46

I am afraid your suggestions (both this and the head/tail things) are nowhere goal of AHK, and the syntax is far off we had & heading to. Lastly, I believe that what ever it is - it can be already done with existing syntax.
If You care for these to be in AHK so much, You can write a library or even a parser (like JSON/JXON) to convert string formatted as your stuff to actually perform actions You desire.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: μKanren: A Minimal Functional Core for Relational Programming

16 Oct 2017, 08:07

No I think this suggestion has a better chance at passing.
AHKs central point is still that it is able to easily modify Windows and it's programs.
However if we think of progressing it will be necessary for several things to happen:
A) Cross-Platformability
B) Making it easier to target specific programs and call their specific actions
C) Including APIs of programs

C) might require ( or might get solved ) by giving AHK the ability to include other languages in some form - something like this language would fit there.
Recommends AHK Studio
concepter
Posts: 47
Joined: 24 Aug 2017, 13:02

Re: μKanren: A Minimal Functional Core for Relational Programming

16 Oct 2017, 09:13

What I proposed came from the observation that AHK is powerful for the presence of both hotkeys and hotstring.
It seems to me that a natural evolution of language can be made by enhancing these aspects and the more natural direction is towards the style of relational programming (or logic programming).
It is my instinctive feeling and I think that such an evolution would make AHK an attractive language, both for newcomers and for experienced business programmers.

To demonstrate this I can say that Erlang's language, derived from Prolog, has recently undergone a language revision through Elixir, which is a very point of reference and indicates the course of progress in language definition.
What I propose is not to miss the opportunity to give a strong identity to AHK v2, to distance it from version v1, and approach it to the ideal programming Language: more descriptive than algorithmic.

In summary, I think that integrating into AHK the syntactic formalism [H|T], a syntactic adaptation of miniKanren's language, inspiration by Elixir's language, would speak to many AHK people, promoting the language beyond the boundaries of current attitudes, which are many but can be many more.
At least I hope so and I hope there are others confident: I believe that AHK could become even more beautiful with these additions, but without becoming difficult.

I believe that if this opportunity is not addressed at this historic moment of AHK rewrite, then later it will be more difficult to make important decisions to give a strong identity even on the theoretical level to the language.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 28 guests