Skip to content

Instantly share code, notes, and snippets.

View kamahen's full-sized avatar

Peter Ludemann kamahen

View GitHub Profile
@kamahen
kamahen / swipy-context-manager.diff
Created April 12, 2024 14:55
WIP context manager for swipy
$ git diff stash@{1}
diff --git a/janus.doc b/janus.doc
index fafbae8..dc1836d 100644
--- a/janus.doc
+++ b/janus.doc
@@ -431,7 +431,7 @@ Loading janus into Python is realized using the Python package
\const{janus-swi}, which defines the module \const{janus_swi}. We do
not call this simply \const{janus} to allow coexistence of Janus for
multiple Prolog implementations. Unless you plan to interact with
-multiple Prolog systems in the same session, we advise importing janus
@kamahen
kamahen / why-japanese-writing-is-so-weird.md
Last active December 17, 2023 21:04
Why Japanese Writing is so Weird

Why Japanese Writing is so Weird

  • Peter Ludemann, November 2023

Creative Commons license "BY" - may use, but must attribute the author.

This is an aggregation of what I've learned over the years about the Japanese writing system. You'll have to take my word for many of things, or find the references on your own — it would take too long to dig up references.

Classical Japanese and Middle Chinese are not related (nor is Korean or Vietnamese)

@kamahen
kamahen / deadfish2.pl
Last active October 15, 2023 23:58
deadfish code improved
:- module(deadfish,
[deadfish/0,
deadfish/3, % for debugging
score_deadfish/1]).
% Deadfish is one of the best known non Turing-complete programming languages.
% It has only one accumulator (which starts at 0) to store data, and only four commands:
%
% i - Increment the accumulator
% s - Square the accumulator
@kamahen
kamahen / deadfish.pl
Created October 6, 2023 16:45
deadfish code using dict/DCG and library(yall)
% Deadfish is one of the best known non Turing-complete programming languages.
% It has only one accumulator (which starts at 0) to store data, and only four commands:
%
% i - Increment the accumulator
% s - Square the accumulator
% d - Decrement the accumulator
% o - Output the accumulator
%
% Create a program that will input a number and output Deadfish
% code to display the number. It must work for any integer from 0 to 255.
@kamahen
kamahen / compilation.output
Last active June 2, 2023 19:50
SWIPL wasm build with error
2: Running test set "gmp" ...................../home/peter/src/swipl-devel/build.wasm/src/swipl.js:1
2: var Module=typeof Module!="undefined"?Module:{};var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");if(ENVIRONMENT_IS_WORKER){scriptDirectory=nodePath.dirname(scriptDirectory)+"/"}else{scriptDirectory=__dirname+"/"}read_=(filename,binary)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return fs.rea
@kamahen
kamahen / chatgpt_solve_visitor_problem.rkt
Created March 19, 2023 23:15
ChatGPT writes Racket code to solve the visitor problem
; Define the hosts and visitors as symbols
(define hosts '(akira bhaskar charlemagne))
(define visitors '(delancy erika fei-fei))
; Define the availability of each host
(define availability
'((akira (1 2 3))
(bhaskar (1 3 4))
(charlemagne (2 4))))
/* Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@vu.nl
WWW: http://www.swi-prolog.org
Copyright (c) 2000-2022, University of Amsterdam
VU University Amsterdam
SWI-Prolog Solutions b.v.
All rights reserved.
@kamahen
kamahen / archive.pl
Last active June 3, 2022 17:40
library(archive) snapshot 2022-06-03
/* Part of SWI-Prolog
Author: Jan Wielemaker and Matt Lilley
E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org
Copyright (c) 2012-2019, VU University Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@kamahen
kamahen / pcre2_mingw.c
Created April 5, 2022 20:16
Output some PCRE2 values for debugging PCRE2 with MinGW
#include <stdio.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
static void config_uint(const char *descr, uint32_t flag) {
uint32_t value;
uint32_t len = pcre2_config_8(flag, NULL);
int rc = pcre2_config_8(flag, &value);
if (rc >= 0) {
printf("%s (len=%d rc=%d) 0x%08x: 0x%08x\n", descr, len, rc, flag, value);
:- det(valid_termpos/2).
%! valid_termpos(+Term, +TermPos) is semidet.
% Checks that a Term has an appropriate TermPos.
% This should always succeed:
% read_term(Term, [subterm_positions(TermPos)]),
% valid_termpos(Term, TermPos)
valid_termpos(_Term, Var), var(Var) => true. % trivial default: "unknown" position
valid_termpos(Atom, _From-_To), atom(Atom) => true.
valid_termpos(Number, _From-_To), number(Number) => true.
valid_termpos(Var, _From-_To), var(Var) => true.