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
:- use_module(library(clpfd)). | |
:- use_module(library(delay)). | |
%% under_camel(?Underscore:atom, ?CamelCase:atom) is det. | |
% | |
% For example, `under_camel(hello_world, 'HelloWorld')`. Works in both | |
% directions. | |
under_camel(U,C) :- | |
when((ground(U0);ground(U)),prepend_underscore(U, U0)), | |
delay(atom_codes(U0,U0Codes)), |
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
tell application "iTerm" | |
return name of current session of current terminal | |
end tell |
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
-- run with `osascript -s s focused-chrome-tab.scpt` to get machine-readable output | |
tell application "Google Chrome" | |
set active_window to first window | |
set i to active tab index of active_window | |
set active_tab to item i of tabs of active_window | |
set x to {URL:URL of active_tab, title:title of active_tab} | |
return x | |
end tell |
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
:- dynamic asserted_a/1, asserted_z/1. | |
:- b_setval(global_variable, []). | |
count(1_000_000). | |
my_asserta(N) :- asserta(asserted_a(N)). | |
my_assertz(N) :- assertz(asserted_z(N)). | |
my_recorda(N) :- recorda(recorded_a, N). | |
my_recordz(N) :- recordz(recorded_z, N). | |
my_flag(N) :- flag(some_flag, _, N). |
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
:- module(bar, [ bar_a/0 ]). | |
do_import(TargetModule) :- | |
%TargetModule:use_module(bar, [bar_a/0]). | |
%TargetModule:import(bar:bar_a/0). | |
TargetModule:assert((bar_a :- writeln("Asserted bar_a/0"))). | |
bar_a :- | |
writeln("Inside bar_a/0"). |
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
:- module(bench, [call_ns/1,call_ns/2,compare/1]). | |
:- use_module(library(sweet)). | |
compare(Goals) :- | |
maplist(run_comparison,Goals,Timings), | |
keysort(Timings,Sorted), | |
format("name\tns/op~n",[]), | |
maplist(show_timing,Sorted). |
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
% Simplification and binarization of Prolog clauses. | |
% | |
% This code was my note paper while reading | |
% "The BinProlog Experience: Architecture and | |
% Implementation Choices for Continuation Passing | |
% Prolog and First-Class Logic Engines" by Paul Tarau. | |
% | |
% I find it especially pleasing that binary logic programs | |
% require only about half as many WAM instructions as | |
% traditional Prolog. This should make it easy to build |
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
% Requirements, using Prolog syntax, to qualify for the foreign earned income exclusion | |
% See http://www.irs.gov/Individuals/International-Taxpayers/Foreign-Earned-Income-Exclusion | |
% facts which act as parameters to the loophole solver | |
:- dynamic | |
us_citizen/0, | |
us_resident_alien/0. | |
% See http://www.irs.gov/Individuals/International-Taxpayers/Foreign-Earned-Income-Exclusion-Can-I-Claim-the-Exclusion-or-Deduction | |
qualify :- |
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
:- use_module(library(clpfd)). | |
dcg(Arabic) --> | |
{ Arabic in 1..3999 }, | |
roman(Arabic), | |
!. | |
roman(Total) --> | |
{ Rest #>= 0 }, | |
{ Total #= Value + Rest }, |
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
module UPC (is_upc) where | |
import Data.Char (digitToInt) | |
-- Is this string a valid Universal Product Code? | |
is_upc :: String -> Bool | |
is_upc u = ( length u == 12 ) && ( upc_checksum u `mod` 10 == 0 ) | |
-- Calculate the UPC checksum using the algorithm from http://xrl.us/omxh8 | |
upc_checksum :: String -> Int |
OlderNewer