Hi,
I have two sets of numbers, and I would like to write a for-loop for comparison, so that I get only the first match between the numbers. I was thinking of a double for-loop, but I do not know how to exit the comparison as soon as I get the first match. Any idea? Thanks.
Joseph
Hello Joseph,
to be honest, this doesn't sound particularly like functional programming. The nice thing about functional programming is that you shouldn't care about such optimization stuff (like breaking out of a for loop), but instead our optimizer should be clever enough to stop executing the function once he has enough results. So simply request the first result and you should be fine. Something like this:
(for $a at $pos in $seq1 where $a = $seq2[$pos] return $a)[1]
Cheers
Dirk
On 02/27/2017 09:42 PM, Joseph wrote:
Hi,
I have two sets of numbers, and I would like to write a for-loop for comparison, so that I get only the first match between the numbers. I was thinking of a double for-loop, but I do not know how to exit the comparison as soon as I get the first match. Any idea? Thanks.
Joseph
Hi Joseph,
Maybe hof:until [1] and hof:take-while [2]?
[1] http://docs.basex.org/wiki/Higher-Order_Functions_Module#hof:until [2] http://docs.basex.org/wiki/Higher-Order_Functions_Module#hof:take-while
--Marc
On 27 feb. 2017, at 19:25, Dirk Kirsten dk@basex.org wrote:
Hello Joseph,
to be honest, this doesn't sound particularly like functional programming. The nice thing about functional programming is that you shouldn't care about such optimization stuff (like breaking out of a for loop), but instead our optimizer should be clever enough to stop executing the function once he has enough results. So simply request the first result and you should be fine. Something like this:
(for $a at $pos in $seq1 where $a = $seq2[$pos] return $a)[1]
Cheers
Dirk
On 02/27/2017 09:42 PM, Joseph wrote: Hi,
I have two sets of numbers, and I would like to write a for-loop for comparison, so that I get only the first match between the numbers. I was thinking of a double for-loop, but I do not know how to exit the comparison as soon as I get the first match. Any idea? Thanks.
Joseph
-- Dirk Kirsten, BaseX GmbH, http://basexgmbh.de |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 91 68 276, Fax: 0049 7531 20 05 22
basex-talk@mailman.uni-konstanz.de