Reverse a list.
my_reverse(L1,L2) :- my_rev(L1,L2,[]).
my_rev([],L2,L2) :- !.
my_rev([X|Xs],L2,Acc) :- my_rev(Xs,L2,[X|Acc]).
Reverse a list.
my_reverse(L1,L2) :- my_rev(L1,L2,[]).
my_rev([],L2,L2) :- !.
my_rev([X|Xs],L2,Acc) :- my_rev(Xs,L2,[X|Acc]).
Find the number of elements of a list.
my_length([],0).
my_length([_|L],N) :- my_length(L,N1), N is N1 + 1.
Find the K'th element of a list in prolog
element_at(X,[X|_],1).
element_at(X,[_|L],K) :- K > 1, K1 is K - 1, element_at(X,L,K1).
Find the last element of a list in prolog
my_last(X,[X]).
my_last(X,[_|L]) :- my_last(X,L).
Determining if a term is a list.
list([]).
list([X|Xs]) :- list(Xs).
?- list([a,b,c]).
yes
?- list(abc).
no
Permutation:
insert(X,L,[X|L]).
insert(X,[H|T],[H|U]) :-
insert(X,T,U).
permute([],[]).
permute([H|T],L) :-
permute(T,U),
insert(H,U,L).
ADDITION:
set x 5
set y 10
expr $x + $y
set z [ expr $x + $y]
puts "sum=$z"
output:
15
sum=15
LOOP:
set i 0
while{$i <10}{
puts $i
set i [ expr $i + 1]
}
The optional orientation values may be defined in degrees or by text like :
right (0)
right-up (45)
right-down (-45),
left (180), left-up (135), left-down (-135), up (90), down (-90).