Skip to content

Instantly share code, notes, and snippets.

@patham9
patham9 / vlmspace.metta
Last active February 3, 2026 02:48
Persistent atomspace of (capital country) incrementally grown by local VLM (runnable with PeTTa v1.0.x)
!(import! &self (library lib_spaces))
!(import! &self (library lib_import))
!(git-import! "https://github.com/patham9/petta_lib_localvlm.git")
!(import_prolog_functions_from_file (library lib_localvlm.pl) (vlm_query vlm_embed))
!(git-import! "https://github.com/patham9/petta_lib_snapshot.git")
!(import! &self (library lib_snapshot))
(= (forever)
(progn (case (catch (sread (vlm_query "http://192.168.1.129:2276"
"give me 5 capitals, format is strict S-Expression, output nothing else: ((capital1 country1) ... (cityn countryn))"
@patham9
patham9 / gist:487ca71399b6febdbaff6df8e121fe09
Created January 29, 2026 19:03
Make firefox "normal"/usable from shell on Mac
sudo rm -f /usr/local/bin/firefox && \
sudo tee /usr/local/bin/firefox >/dev/null <<'EOF'
#!/bin/bash
exec open -a Firefox "$@"
EOF
sudo chmod +x /usr/local/bin/firefox
@patham9
patham9 / gist:8c0c5126132a3ea24b89afce0afd64db
Created January 28, 2026 12:22
ros2fix.py (Keeping fixed amounts of laser readings)
#!/usr/bin/env python3
import math
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
FIXED_LEN = 447
class ScanSanitizer(Node):
def __init__(self):
@patham9
patham9 / gist:fe1889971e8cd2de11e40acd97d394f0
Last active January 24, 2026 02:03
PeTTa v1.0.x: Resumable computation with budget limits
!(import_prolog_function statistics)
(= (BudgetLimitCheck)
(if (> (- (statistics inferences) (get-state &initinferences)) (get-state &inferenceslimit))
(translatePredicate (shift (pay-for-inferences)))
True))
(= (AssignBudgetLimit $N)
(progn (change-state! &initinferences (statistics inferences))
(change-state! &inferenceslimit $N)))
@patham9
patham9 / gist:54af0acff57a1d0be82d339c5e818b47
Last active January 23, 2026 20:21
PeTTa from Python (after "pip install sexpdata")
from sexpdata import loads
from petta import *
metta = PeTTa()
expstring = metta.process_metta_string("!(hello \"world\" (1.0 1))")[0]
print(loads(expstring))
#Output:
#[Symbol('hello'), 'world', [1.0, 1]]
@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: