Skip to content

Instantly share code, notes, and snippets.

(! (add-atom '&self ('coffee 'moka)))
(! (add-atom '&self ('coffee 'turkish)))
(= (myMultiFunction 'moka) ('moka 'good))
(= (myMultiFunction 'moka) ('moka 'excellent))
(! (Let w (superpose ('big 'small myMultiFunction))
(Match '&self ('coffee x) (w x))))
Output:
;[((big turkish)), ((big moka)), ((small turkish)), ((small moka)), ((moka excellent)), ((moka good))]
(coffee moka)
(coffee turkish)
(coffee expresso)
(coffee cappuccino)
(coffee latte)
!(match &self (coffee $1) $1)
(define %coffee
(%rel ()
[('moka)]
[('turkish)]
[('expresso)]
[('cappuccino)]
[('latte)]))
(define (test data)
(if data
@patham9
patham9 / gist:d8615121e1b5c1f18a7c66be34ab5b23
Created October 28, 2023 07:26
Simple dll usage (never use dlopen if your program just needs to load the library at startup!!)
/* add.c */
#include <stdio.h>
float add(float a, float b) { return a + b; }
//gcc -shared -o libadd.so add.c -fPIC
/* main.c */
#include <stdio.h>
extern float add(float a, float b);
int main() { printf("Result: %f\n", add(3.0, 4.0)); return 0; }
//gcc main.c -L. -ladd
(let ((r392874
(##core#inline_allocate
("C_a_i_list3" 9)
'Sentence
r393386
r393390)))
(let ((r393221
(##core#inline_allocate
("C_a_i_list2" 6)
'ExtSet
(define-syntax auto-list-helper
(syntax-rules ()
((_ expr1 ()) ;empty list
(list expr1))
((_ (expr1i ...) argi ...) ;a nested expression is not a procedure
(list (auto-list expr1i ...) (auto-list1 argi) ...))
((_ expr1 argi ...)
(if (procedure? expr1)
(apply expr1 (list (auto-list1 argi) ...))
(list (auto-list1 expr1) (auto-list1 argi) ...)))))
!(collapse (superpose ((superpose (1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3))
(superpose (1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3))
(superpose (4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6))
(superpose (4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6))
(superpose (7 8 9 7 8 9 7 8 9 7 8 9 7 8 9 7 8 9 7 8 9 7 8 9))
(superpose (1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3))
(superpose (1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3))
(superpose (4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6))
(superpose (4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6 4 5 6))
(superpose (7 8 9 7 8 9 7 8 9 7 8 9 7 8 9 7 8 9 7 8 9 7 8 9))
@patham9
patham9 / gist:7d9043e6930e788a1ccfac9c98c77d31
Created October 1, 2023 00:03
MeTTa for Meta-programming?
(: If (-> Bool Atom Atom))
(= (If True $then) $then)
(= (If False $then) ())
(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))
(= (TupleConcat $Ev1 $Ev2) (collapse (superpose ((superpose $Ev1) (superpose $Ev2)))))
;safe expression equality
(: ==expr (-> Expression Expression Bool))
(: sequential (-> Expression %Undefined%))
(: TupleConcat (-> Expression Expression Expression))
(= (TupleConcat $Ev1 $Ev2) (collapse (superpose ((superpose $Ev1) (superpose $Ev2)))))
(= (sequential $1) (superpose $1))
(: do (-> Expression %Undefined%))
(= (do $1) (case $1 ()))
(: If (-> Bool Atom Atom))
(= (If True $then) $then)
(= (If False $then) ())
(: If (-> Bool Atom Atom Atom))
@patham9
patham9 / gist:3eb5f80e786dbdbf4fbe9572ec3eb854
Last active September 19, 2023 19:21
MicroKanren experiment
(include "microKanren.scm")
(define (squared x) (* x x))
(define (main)
(define results
(run* (q)
(fresh (x y)
(== x 2)
(== y 3)