Skip to content

Instantly share code, notes, and snippets.

@patham9
patham9 / gist:94aff6fe0467d1ff236f451cceb0702c
Last active January 8, 2026 23:27
PeTTa v1.0 (cat *.pl in src folder)
:- use_module(library(readutil)). % read_file_to_string/3
:- use_module(library(pcre)). % re_replace/4
:- current_prolog_flag(argv, Args), ( (memberchk(silent, Args) ; memberchk('--silent', Args) ; memberchk('-s', Args))
-> assertz(silent(true)) ; assertz(silent(false)) ).
%Read Filename into string S and process it (S holds MeTTa code):
load_metta_file(Filename, Results) :- load_metta_file(Filename, Results, '&self').
load_metta_file(Filename, Results, Space) :- read_file_to_string(Filename, S, []),
process_metta_string(S, Results, Space).
git clone https://github.com/jazzbox35/MettaWamJam
cd MettaWamJam
docker build -t mettawamjam:latest .
docker run --rm -d --name mwj -p 127.0.0.1:5000:5000 mettawamjam:latest
then run:
python3 RunMeTTaCode.py
python3 RunMutex_and_Transaction.py
python3 RunMM2Code.py
@patham9
patham9 / syntaxhighlightme.c
Last active November 27, 2025 21:30
NARS-GPT: Whale disease example
//Input: Whales are mammals that live in the ocean.
<(whale * ocean) --> live_in>. :|: {1.0 0.9}
//Input: Animals that live in the ocean are marine animals.
<(animal * ocean) --> live_in>. :|: {1.0 0.9}
<animal --> marine_animal>. :|: {1.0 0.9}
//Input: Marine mammals are exposed to pollutant P.
<(marine_animal * pollutant_p) --> are_exposed_to>. :|: {1.0 0.9}
@patham9
patham9 / gist:58b63d02717b034822f0bb92cced97fd
Created October 3, 2025 08:23
Behavior of once(concurrent_and( vs. first_solution(
%Finding divisors
'find-divisor'(A, B, C) :-
*(B, B, D),
>(D, A, E),
( E==true
-> C=A
; C=F,
'%'(A, B, G),
==(0, G, H),
( H==true
@patham9
patham9 / gist:2639f0110be8a3c1bab9c033739c0e14
Created September 14, 2025 18:06
PeTTa match-single approaching match-once code
(foo 1)
(foo 2)
;Ok: Leads to unnecessary 'and' and 'empty' invocation in compiled output:
(= (match-single1 $space $pat $ret)
(if (and (= $x (match $space $pat $ret)) (cut))
$x (empty)))
;Bad: Leads to unneccesary maybe_call which is expensive:
@patham9
patham9 / gist:d9cb14eca9e3adfca97b29340e0c723d
Created September 11, 2025 22:01
Exponential pattern generator
((step app)
(, (num $1) )
(, (num (M $1))
(num (W $1)) ))
((step app)
(, (num (M $1)),
(num (W $1)) )
(, (num (C $1)) ))
@patham9
patham9 / gist:589fd717bf9ee0ae4e0ff6ec73bb1da6
Created August 17, 2025 12:34
MM2/MORK: getting started
Needed:
pip3 install requests-sse
client.py:
Replace /target/debug/mork_server with /target/release/mork_server
@patham9
patham9 / gist:56ccaf963266406c33d27826ee6a6f4b
Created July 31, 2025 22:07
PLN deriver efficiency: use derivations only for inference in each recursion.
;; Exhaustive-until-depth deriver
(= (Derive $derivationsLast $beliefs $depth $maxdepth)
(if (> $depth $maxdepth)
$beliefs
(let $derivations
(collapse (superpose ((let* (((Sentence $x $Ev1) (superpose $derivationsLast))
((Sentence $y $Ev2) (superpose $beliefs))
($stamp (TupleConcat $Ev1 $Ev2)))
(if (StampDisjoint $Ev1 $Ev2)
(case (|- $x $y) ((($T $TV) (Sentence ($T $TV) $stamp)))) (empty)))
;PLN for MeTTa-Morph, based on PLN 0f2e0008f82cefdf53585d0bc103489e00b77de7 of June 12, 2025.
;What made it work:
;1. mettamorph extension for (empty)
;2. removal of functions that are already in the stdlib of mettamorph
;3. Replaced if occurrences with If of Mettamorph
;4. Represented implication sentences with functions to avoid floating vars
;mettamorph extension:
(= (empty) ()) ;todo make it call amb-failure-continuation
@patham9
patham9 / gist:b89ef4b8d7d40782766889b833ac5495
Created May 20, 2025 09:06
MeTTa Motto (rel extraction test)
!(import! &self motto)
!(let $x ((chat-gpt-agent "gpt-4o-mini")
(system "You are an assistant. Answer as a tuple (R a b) (no commas) where R in {near} and a,b in {human, robot, chair}")
(user "the robot is close to the chair!"))
(let $L ((py-dot ((py-dot ((py-dot $x replace) "(" "" ) replace) ")" "") split) " ")
(let ($R $a $b)
(((py-dot $L __getitem__) 0)
((py-dot $L __getitem__) 1)
((py-dot $L __getitem__) 2))
(EXTRACTED: (R = $R) (a = $a) (b = $b)))))