Skip to content

Instantly share code, notes, and snippets.

http://stackoverflow.com/questions/449734/is-there-a-tool-for-converting-vb-to-a-scripting-language-e-g-python-or-ruby
http://stackoverflow.com/questions/9880805/automatically-convert-scala-code-to-java-code
http://stackoverflow.com/questions/3919343/how-to-convert-vb6-to-visual-c-native-code
http://stackoverflow.com/questions/29193069/how-do-i-start-writing-a-transpiler-is-it-even-possible
http://stackoverflow.com/questions/358016/convert-python-to-c-sharp
http://stackoverflow.com/questions/2801811/how-can-i-convert-a-shell-script-into-a-perl-script
http://stackoverflow.com/questions/2597255/porting-perl-to-python
http://stackoverflow.com/questions/2184510/easily-porting-lua-code-to-c-sharp
http://stackoverflow.com/questions/1114789/how-can-i-convert-perl-to-c
http://stackoverflow.com/questions/8051710/is-there-any-tools-to-convert-perl-script-to-c-sharp-code
%Java-to-scala translator for SWI-Prolog
:- use_module(library(transpiler)).
:- set_prolog_flag(double_quotes,chars).
:- initialization(main).
main :-
Input = "def add(a:String,b:String):String={return a+b;} def squared(a:Int):Int={return a*a;} def add_exclamation_point(parameter:String):String={return parameter+\"!\";}
",
translate('scala','java',X),
atom_chars(Y,X),
@jarble
jarble / natural_language_user_interface.pl
Last active April 24, 2024 11:21
A simple English-to-Prolog translator, based on http://stackoverflow.com/a/21196849/975097
%This is a basic English-to-Prolog translator. It uses a
%pathfinding algorithm to find the meaning of each sentence.
%For example, output([a,is,greater,than,B],X) means X = (a > b).
%The input is an English phrase. The output is a Prolog expression.
output(Input,Output) :-
is_output(Output),
means(Input,Output).
@jarble
jarble / jarble_web_filter.user.js
Last active December 11, 2017 22:08
jarble_web_filter
// ==UserScript==
// @name Andy
// @namespace test
// @description test
// @grant GM_getValue
// @grant GM_setValue
// @match htt(p|ps)://*/*
// @exclude https://www.google.com*
// @noframes
// ==/UserScript==
@jarble
jarble / SAT_Solver.pl
Last active July 12, 2017 06:06
An (unfinished) implementation of an SAT solver using Constraint Handling Rules
:- use_module(library(chr)).
:- initialization(main).
:- chr_constraint is_true(+).
is_true(A) \ is_true(A) <=> true.
:- chr_constraint are_true(+).
are_true(A) \ are_true(A) <=> true.
:- chr_constraint is_false(+).
is_false(A) \ is_false(A) <=> true.
:- initialization(main).
main :- recursive_simplify_expr(((x+y+1)^2 = (x-y)^2),Output),writeln(["Output: ", Output]).
%mul([add([mul([add([mul([x,x]),mul([x,y2])])]),mul([add([mul([x,y1]),mul([y1,y2])])])])])=0
simplify_expr(mul([A|Rest]),mul([1|[A|Rest]])) :-
atom(A).
simplify_expr(mul([A]),A).
simplify_expr(A/B,A1/B1) :-
simplify_expr(A,A1),simplify_expr(B,B1).
@jarble
jarble / chr_metainterpreter.pl
Last active November 8, 2018 23:07
This is an attempt to write a meta-interpreter for Constraint Handling Rules.
:- 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).
<!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));};
@jarble
jarble / closure_example.pl
Last active February 8, 2024 09:05
An example of closures (or "nested predicates") in Prolog
%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).
@jarble
jarble / duplicate_code_detection.pl
Last active August 21, 2021 21:17
An example of duplicate code detection in Prolog
:- 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