Dear Bartosz,
In exist-db xmldb:store() function returns a string and there is no problem to create let/return construct.
I must confess I know too little about the update functions of eXist-db, but as far as I see, you don’t further evaluate the result of your update operation in your FLWOR expression. Instead, you seem to want to return a value in your query. BaseX is based on the semantics of the XQuery Update Facility, in which an updating query never returns results [1], but we have included the db:output() function for that [2]. Your main expression could then look as follows:
let $indexnew := local:indexget() + 1 return ( local:indexset($indexnew), db:output($indexnew) )
Hope this helps, Christian
[1] http://docs.basex.org/wiki/XQuery_Update [2] http://docs.basex.org/wiki/Database_Module#db:output