<commit_before><xh:html xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms">

    <xh:head>
        <xf:model>
            <xf:instance id="instance">
                <values>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                    <value></value>
                </values>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>

        <xf:repeat ref="value">
            <xf:input ref="."/>
        </xf:repeat>

        <xf:trigger>
            <xf:label>Run CoffeeScript</xf:label>
            <xf:action ev:event="DOMActivate">
                <xxf:script runat="server" type="text/coffeescript">
                    <![CDATA[
                    index = (list, target) ->
                      [low, high] = [0, list.length]
                      while low < high
                        mid = (low + high) >> 1
                        val = list[mid]
                        return mid if val is target
                        if val < target then low = mid + 1 else high = mid
                      return -1

                    ORBEON.controls.setValue "input2", index [10, 20, 30, 40, 50], Number(ORBEON.controls.getValue "input1")
                    ]]>
                </xxf:script>
            </xf:action>
        </xf:trigger>

    </xh:body>
</xh:html><commit_msg>Actual CoffeeScript merge sort demo missed in earlier checkin.<commit_after><xh:html xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner">

    <xh:head>
        <xh:title>Merge sort of XForms values in CoffeeScript</xh:title>
        <xf:model>
            <xf:instance>
                <values>
                    <value>23</value>
                    <value>99</value>
                    <value>13</value>
                    <value>15</value>
                    <value>9</value>
                    <value>46</value>
                    <value>35</value>
                    <value>12</value>
                    <value>87</value>
                    <value>40</value>
                </values>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>

        <xf:repeat ref="value">
            <xf:output id="my-output" ref="."/>
            <xh:br/>
        </xf:repeat>

        <fr:button>
            <xf:label>Sort them!</xf:label>
            <xxf:script ev:event="DOMActivate" runat="server" type="text/coffeescript">
                <![CDATA[

                # Merge sort function from the CoffeeScript examples
                mergeSort = (list) ->

                  return list if list.length is 1

                  result  = []
                  pivot   = Math.floor list.length / 2
                  left    = mergeSort list.slice 0, pivot
                  right   = mergeSort list.slice pivot

                  while left.length and right.length
                    result.push(if left[0] < right[0] then left.shift() else right.shift())

                  result.concat(left).concat(right)

                # Read values of all 10 controls as numbers
                unsortedValues = for index in [1..10]
                  Number ORBEON.controls.getValue "my-output·" + index

                # Sort values
                sortedValues = mergeSort unsortedValues

                # Sort and write back sorted values
                for index in [1..10]
                  ORBEON.controls.setValue "my-output·" + index, sortedValues[index - 1]

                ]]>
            </xxf:script>
        </fr:button>

    </xh:body>
</xh:html>
{'fraction_non_alphanumeric': 0.13284848484848485, 'fraction_numerical': 0.019151515151515152, 'mean_word_length': 1.2218632202477113, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2894002', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1144, 'n_words': 224}