Using Applescript to transfer files from first Tab to second active Tab in finder

Forgive me – I did indeed misread you – (neither age nor lack of sleep is an adequate excuse) – and I think we agree entirely on [...] vs {...}

(I often find the former clearer, and both cleaner and more natural, both on paper and under the hood, for tail recursions over lists, as Shane Stanley points out:

Linked lists are a very good representation for recursive programs that
"walk" lists, processing one item on each recursive step. This is usually
the case when the 'rest' property is being used.

So for example, we could (without loss of performance) use a linked list version in a simple recursive expression of the Gauss schoolroom problem (using script in lieu using Gauss's optimization)

-- sum2 :: [Int] -> Int
on sum2(xs)
    if [] ≠ xs then
        (first item of xs) + sum2(rest of xs)
    else
        0
    end if
end sum2

-- enumFromTo2 :: Int -> Int -> [Int]
on enumFromTo2(m, n)
    if m ≤ n then
        set lst to []
        repeat with i from m to n
            set lst to lst & [i]
        end repeat
        return lst
    else
        return []
    end if
end enumFromTo2

on run
    set xs2 to enumFromTo2(1, 100)
    set x to 0
    
    set dteStart to current date
    repeat with i from 1 to 10000
        set x to sum2(xs2)
    end repeat
    set dteEnd to current date
    
    [dteEnd - dteStart, x]
end run


As a footnote, I notice that Script Debugger (unlike KM AS actions and Script Editor) seems a little surprised by large linked lists – its progress indicators go quiet for a while. Perhaps it automatically coerces all lists to vectors ? Not sure.

In any case, by this stage of the Applescript life-cycle, I personally find it more helpful to understand the history and real under-the-hood mechanics of the AS interpreter than to study any particular Marketing and Documentation ideology presented by Apple.

I would be surprised if, at this point, Apple really had any particular or coherent view of AppleScript at all. It's a very useful legacy project for users, but not, I suspect, very much alive in their development plans or views of the future.

1 Like