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
:- 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
-- 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
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
:- 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
$ cat dicts.pl | |
person{name: john}. | |
$ swipl -f none -s dicts.pl | |
% /tmp/dicts.pl compiled 0.00 sec, 2 clauses | |
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.3) | |
Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam | |
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, | |
and you are welcome to redistribute it under certain conditions. | |
Please visit http://www.swi-prolog.org for details. |
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
% The graphical front-end will be used for subsequent tracing | |
% .plrc compiled 0.28 sec, 4,557 clauses | |
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.3) | |
Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam | |
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, | |
and you are welcome to redistribute it under certain conditions. | |
Please visit http://www.swi-prolog.org for details. | |
For help, use ?- help(Topic). or ?- apropos(Word). |
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
answer X | |
X is 41 + 1 |
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
// ack +Dir +Language +Pattern -File -Line | |
// | |
// True if File is beneath the directory Dir, written in Language and contains | |
// a Line that matches Pattern. Similar to the command line tool ack. | |
ack Dir Language Pattern File Line | |
dir_entry Dir Entry | |
type Entry file | |
fan_out 1 // optional optimization. See Note_fan_out | |
language Entry Language | |
line Entry Line |
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
% The numerous inline comments are explanatory. Normal code wouldn't have them. | |
% I'm using double quotes to delineate raw text content. Real code would use | |
% a quasiquotation mechanism. | |
amazon_condition_overview(ASIN, Condition, BestPrice, Inventory, Section) :- | |
% HTTP GET the URL and parse it into a DOM structure | |
get(url("amazon.com/gp/offer-listing/$ASIN/?ie=UTF8"), DOM), | |
% build an atom representing the tab's node ID | |
TabId = qq("olpTab$Condition"), |