Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
def process_line(line)
if line =~ /(.*):(\d*):(.*)/ then
"<a href=\"txmt://open?url=file://#{ENV['TM_DIRECTORY']}/#{$1}&line=#{$2}\">#{$1}:#{$2}: #{$3}</a><br/>"
else
line + "<br/>"
end
end
% Simple Prolog debugging trick
:- op(800, fx,'>').
'>'(X) :-
write(X),
write('\n'),
call(X).
test :-
>write('foobar').
% Combine several rules into a single one.
cl1(a, b, X) :- X is 2+2.
cl1(a, c, X) :- X is 4+4.
head_condition([],[],true).
head_condition([Parameter|RestParams], [RefParam|RestRefParams], (Cond, CondRest)) :-
Cond = (RefParam = Parameter),
head_condition(RestParams,RestRefParams, CondRest).
@cth
cth / re2fa.pl
Created May 6, 2009 11:22
converts regex -> NFA -> DFA
:- use_module(library(chr)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program performs conversions from
% regex -> NFA -> DFA
%
% It consists of three parts:
% 1. A regular expression parser (DCG)
% 2. A CHR program for converting DCG parse tree to an NFA
% 3. A CHR program for converting the NFA to a DFA
#!/usr/bin/env ruby
# Point it to the directory where the genbank files are and it will generate
# Prolog representations of the files.
require 'rubygems'
require 'bio'
class String
def to_prolog
"'" + self.gsub("'",'\\\\\'') + "'"
#!/usr/bin/env ruby
# Point it to the directory where the genbank files are and it will generate
# Prolog representations of the files.
require 'rubygems'
require 'bio'
class String
def to_prolog
"'" + self.gsub("'",'\\\\\'') + "'"
% A queue data type in CHR with constant time operations.
% Needed since this is difficult to do with pure Prolog.
:- use_module(library(chr)).
:- chr_constraint init_queue/0, enqueue/2, dequeue/1,
queue_element/3, queue_start/2, queue_end/2,
dequeued_element/2.
% The queue is initialized with start=end, first-index=1
@cth
cth / simplehmm2prism.pl
Created August 13, 2009 16:16
Convert a HMMs in simplistic fact format to a PRISM program
:- use_module(library(chr)).
:- set_prolog_flag(chr_toplevel_show_store,false).
simplehmm2prism(InputFile,OutputFile) :-
read_hmm(InputFile),
write_hmm(OutputFile).
% These rules are only used as template for creating
hmm(L) :- msw(trans(start),S0),hmm(S0,L).
@cth
cth / gist:168989
Created August 17, 2009 07:59
A simple O(n^2) DFA minimization implementation in CHR
% DFA minimization
:- use_module(library(chr)).
:- chr_constraint trans/3, state/1, same/2, different/2, final/1, non_final/1, state_order/2.
% A simple test DFA for arithmetic expressions
test :-
final(s3),
trans('(', s1, s1),
#!/usr/bin/env ruby
# Christian Theil Have, Sep. 2009.
require 'rubygems'
require 'xmlsimple'
class String
def to_prolog
"'" + self.gsub("'",'\\\\\'') + "'"
end