Welcome to W3Courses
 Like Us on Facebook

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:

  1. First create a view
  2. Select the fields you want
  3. Select an argument uid and connect it to currewnt logged in user
  4. Create a page called user/%/favorites

Share

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


 

Share

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).

Share

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

Share

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)))))))

Share

Delete the Third Occurrence of an Element from a List Using Scheme Source Code

The following code deletes the third occurrence of an element from a list

Share

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!

Share

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!

Share

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)

Share

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

Share