How to traverse a possibly cyclic foaf:knows network in XsRQL:
declare prefix foaf: = <foafUri>;
declare function knowsList( RDFResource+ $persons )
{
    let $next := $persons/last()/@foaf:knows/*
    return
        if ( exists( $next )) 
        and ! exists( index-of($persons, $next)) )
        then knowsList( ( $persons, $next ) )
        else ()
};

knowsList( <bob> )
index-of() is straight from the XQuery Functions & Operators document. I'm using last() in a slightly non-standard fashion to access the last element in the $persons list that precedes it in the path.