This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- initialization(main). | |
:- set_prolog_flag('double_quotes','chars'). | |
main :- Term = (member(Z,A),append(A,B,C),dif(A,[true,false])),has_type(Term:Type,Types),writeln('Term with types to infer:'),writeln(Term),writeln('Types of variables in this term:'),writeln(Types). | |
greater_than(A,B) :- | |
A > B. | |
matches_any_([],B) :- false. | |
matches_any_([A|A1],B) :- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- initialization(main). | |
:- set_prolog_flag(double_quotes,chars). | |
main :- recursive_partial_eval((is_between(3,4,5) -> false,is_between(1,C,3);is_between(3,4,5);is_between(3,D,4)),B),writeln(B). | |
recursive_partial_eval(A,B) :- | |
find_all_clauses_(A,A1), | |
(A==A1,A1=B;recursive_partial_eval(A1,B)). | |
find_all_clauses_(A,A) :- var(A). | |
find_all_clauses_(A,B) :- nonvar(A),find_all_clauses(A,B). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
import sys | |
import subprocess | |
from tokenize import tokenize | |
from io import BytesIO | |
def tokenize_input(the_input): | |
return ([a.string for a in list(tokenize(BytesIO(the_input.encode('utf-8')).readline)) if a.string not in ["\n","","utf-8"]]) | |
def matches_pattern(string,pattern): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
import sys | |
import subprocess | |
def matches_pattern(string,pattern): | |
if len(string) != len(pattern): | |
return False | |
for i in range(0,len(string)): | |
if is_expr_(pattern[i]): | |
for j in range(0,len(string)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- initialization(main). | |
:- set_prolog_flag('double_quotes','chars'). ;this is for SWI-Prolog | |
:- use_module(library(chr)). | |
:- chr_constraint type/2. | |
type(A,B) \ type(A,B) <=> true. | |
type((A;B),C) ==> C = bool,type(A,bool),type(B,bool). | |
type((A,B),C) ==> C = bool,type(A,bool),type(B,bool). | |
type(A>B,C) ==> C = bool,type(A,number),type(B,number). | |
type(A<B,C) ==> C = bool,type(A,number),type(B,number). | |
type(A+B,C) ==> C = number,type(A,number),type(B,number). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* lexical grammar */ | |
%lex | |
%% | |
\s+ /* skip whitespace */ | |
[0-9]+("."[0-9]+)?\b return 'NUMBER' | |
\"([^\\\"]|\\.)*\" return 'STRING_LITERAL' | |
"forall" return 'forall' | |
"copy_term" return 'copy_term' | |
"if" return "if" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- initialization(main). | |
:- set_prolog_flag(double_quotes, chars). | |
main :- | |
duplicate_code( | |
(G<A;A>B+1;C>D+1), | |
Output), | |
writeln(Output). | |
%find a duplicated term within a term |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Since SWI-Prolog does not have a built-in implementation of closures, I wrote my own implementation here. | |
:- initialization(main). | |
:- set_prolog_flag('double_quotes','chars'). | |
main :- predicate_with_nested(1,C),writeln(C). | |
call_local(Definition,Params) :- | |
copy_term(Definition,(Params :- Body)), | |
call(Body). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<input type="text" id="input_box"/> <button id = "speak">Click me</button><br/><br/>Repeat how many times:<input type="text" id="repeat"/> | |
<script type = "text/javascript"> | |
var speak = function(){for(var i = 0; i < document.getElementById("repeat").value; i++) | |
window.speechSynthesis.speak(new SpeechSynthesisUtterance(document.getElementById('input_box').value));}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- initialization(main). | |
:- set_prolog_flag('double_quotes','chars'). | |
:- use_module(library(chr)). | |
:- chr_constraint is_true/1. | |
is_true(X) \ is_true(X) <=> true. | |
is_true(X ==> Y),is_true(X1) ==> copy_term((X -> Y),(X2 -> Y1)),(X2=X1,(is_true(X1)->is_true(Y1));X2\=X1),writeln(Y). | |
is_true((X;Y)) ==> is_true(X);is_true(Y). | |
is_true((X,Y)) ==> is_true(X),is_true(Y). | |
is_true(is_true(X)) ==> is_true(X). |