List
Creating a list of Favorites for Users to show in their Drupal Profile
Download and enable the flags module
http://drupal.org/project/flag
Flag module is very customizable because it is more flexible and you can integrate it in views.
In order to create a tab in Users's profile, that will lsit their favorite nodes:
- First create a view
- Select the fields you want
- Select an argument uid and connect it to currewnt logged in user
- Create a page called user/%/favorites
Delete all occurrences of an Element from a List using Prolog Source Code
The following code deletes all occurrences of an element from a list
CODE
deleteall([],A,[]).
deleteall([H|T],A,Result) :- H=A, deleteall(T,A,Result).
deleteall([H|T],A,[H|Result]) :- deleteall(T,A,Result).
RESULT
?- deleteall([a,b,a,c],a,Result).
Result = [b, c]
Yes
Delete the Nth Element from the List using Prolog Source Code
The following code deletes the Nth element from the list
delN([],A,X,N,[]).
delN([H|T],A,X,N,Result) :- H=A, N=1, delN(T,A,X,X,Result).
delN([H|T],A,X,N,[H|Result]) :- H=A, N>1, N1 is N-1, delN(T,A,X,N1,Result).
delN([H|T],A,X,N,[H|Result]) :- delN(T,A,X,N,Result).
List Member Function using Prolog Source Code
The following code checks if an element is a member of a given list
CODE
member(X, [X|Y]).
member(X, [H|L]) :- member(X, L).
RESULT
?- member(b, [a,b,c]).
Yes
Delete all Occurrences of an Element from a List Using Scheme Source Code
The following code deletes all occurrences of an element from a list
CODE
(define deleteall( lambda (x y)
(if (null? y )
()
(if (eqv? (car y) x)
(deleteall x (cdr y))
(cons (car y) (deleteall x (cdr y)))))))
Delete the Nth Occurrence of an Element from a List with Set! Using Scheme Source Code
The following code deletes the Nth occurrence of an element from a List with Set!
Delete the Nth Occurrence of an Element from a List without Set! Using Scheme Source Code
The following code deletes the Nth occurrence of an element from a list without using Set!
Flatten a List using Scheme Source Code
The following code flattens a list
CODE
(define (flatten x)
(cond ((null? x) '())
((atom? x) (list x))
(else (append (flatten (car x)) (flatten (cdr x))))))
RESULT
> (flatten '(a ((c d) f) d))
(a c d f d)
> (flatten '(a (((d f g)) e) h))
(a d f g e h)
Return the Last Element from the List using Scheme Source Code
The following code returns the last element from the list
CODE
(define z 0)
(define (last-element x)
(cond ((null? x) z)
(else (set! z (car x)) (last-element (cdr x)))))
RESULT
> (last-element '(a b c d))
d
> (last-element '(d e f g h i j k))
k
