Skip to content

Instantly share code, notes, and snippets.

@bmaland
Created November 18, 2010 16:43
Show Gist options
  • Select an option

  • Save bmaland/705253 to your computer and use it in GitHub Desktop.

Select an option

Save bmaland/705253 to your computer and use it in GitHub Desktop.
?- 'bergen' = L.
L = bergen.
?- "bergen" = L.
L = [98, 101, 114, 103, 101, 110].
?- atom('bergen').
true.
?- is_list("bergen").
true.
?- write('sdf').
sdf
true.
?- write("sdf").
[115, 100, 102]
true.
?- writef("%s", ["sdf"]).
sdf
true.
?- name('bergen', CharList), nth0(0, CharList, FirstChar), put(FirstChar).
b
CharList = [98, 101, 114, 103, 101, 110],
FirstChar = 98.
sublist(S, L) :-
append(_, L2, L),
append(S, _, L2).
contains(A, B) :-
atom(A),
atom(B),
name(A, AA),
name(B, BB),
contains(AA, BB).
contains(A, B) :-
atom(A),
name(A, AA),
contains(AA, B).
%% The empty list is removed mainly for nicer output in the following example.
contains(A, B) :-
sublist(B, A),
B \= [].
?- forall( contains('bergen', X) , writef("%s\n", [X]) ).
b
be
ber
berg
berge
bergen
e
er
erg
erge
ergen
r
rg
rge
rgen
g
ge
gen
e
en
n
true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment