The transformed image or map of a list under some function?

The collect operator lets us map a list of Notes to a corresponding list of their values for a particular Attribute.

Does anyone have a view on the simplest way to do something analogous with:

  • a list of simple values (e.g. Strings, Numbers or Bools, rather than Notes),
  • and the evaluation of any expression involving such a value.

For example, what might be the cleanest Action code routes from:

list("1;2;3;4;5")

to (n -> 2 * n)

"2;4;6;8;10"

or (n -> n repetitions of a given character)

"★;★★;★★★;★★★★;★★★★★"

(or the reverse of either of those list to list mappings)

?

Not as such, but .each(), var, and eval() are likely part of the route to this. What is the underlying use case for doing this in action code? In the past, more complex programming is normally passed out to the shell via runCommand().

Thanks.

The use case is simply thinking through the details of a minimal osascript (mostly action and export code) rewrite of a comparison table generated from the notes selected in the GUI.

(Reflections prompted by @cremoer 's question on that topic)

Once we have a list of which notes the user has selected for comparison:

  • The collect operator works well for the rows of attribute values for each note,
  • and probably even for re-rendering true boolean values as ticks and the review integers as star-lists, etc
  • but more generally, I think the casual scripter is served well by not having to fiddle too much with var declarations and looping increments and mutations, around which bugs are prone to cluster, and in which time has a tendency to evaporate.

If I were going to shift some of what I do from JS to action script and export script, I think I would want to paste some boilerplate that would enable me to think in terms of map and fold kinds of pattern (just to protect myself and my time a bit from detail and from accident)

( But perhaps, as you suggest, complexity of any kind is really best pushed out to runCommand and osascript )

Even in AppleScript, for example, I find it more reliable and less fiddly to write:

map(double, {1, 2, 3, 4, 5})

than to always start from fresh each time by assembling the various pieces of:

set lst to {}
repeat with n in {1, 2, 3, 4, 5}
    set end of lst to 2 * n
end repeat
return lst

Thanks. One thing this thread flags up that does have general application is a putative getSelection action which would return a list of references (paths) to the apps current selection (the list’s default sort order is something still to consider). That list could then be iterated to generate an HTML based table - to all sorts of other visualisations of an arbitrary selection’s.

But, in ROI terms, one could argue the this is extra engineering to achieve an end that could easily be accomplished by a slightly different route - applying a custom value to an attribute of the selected notes and then using existing action code methods.

Going further down the rabbit hole, I appreciate the ease-of-use-for-the-less-tech-user angle but that ease normally comes with more complexity (handling of user-error edge cases etc) behind the curtain. The ROI assessment is one for the developer but I don’t see great upside apart from making one thing easier which may not be much used. I say that as one whose pushed for a number of features over the years and mindful of how some ideas, though cool and great for the user, didn’t add to the value of the app overall. I’m quite happy to be wrong here, as I may be missing valid wider use (and thus better engineering ROI).

Separately, I’m not an AppleScript export and map and fold are new to me and not well described. The only reference I can find is a discussion (involving you!) at the LateNight Software forums.

1 Like

That sounds right – it may be that the answer (in my particular case) is just to stick to JS for most things.

(map and fold (JS and some other languages call fold ‘reduce’) can be written in most languages, and are provided in many – they arise from basic operations over ordered sets – and the Mozilla JS docs describe them reasonably well)

See in particular the examples on these pages:

1 Like

Or in another language (with more examples)

1 Like

By the way - my question in the other thread came up because of your export tutorial. I thought, that perhaps it could be possible to build something similar to Rob’s JS script with Tinderbox alone, as TB has some powerful export features.

But I also think, that export is - unfortunately and wrongfully - not used too much by most of the users.

1 Like

I think something like this might work:

$MyList=“1;2;3;4;5”;
$ResultList=“”;
$MyList.each(x){$ResultList=$ResultList+2*x;}

Apropos of nothing, I want to observe that Tinderbox is not intended to be LISP.

3 Likes

Since nobody knows what Tinderbox REALLY is, we obviously mixed it up :wink:

Thanks, I just wanted to check that I wasn’t missing any scope for laziness – not intended as a feature request.

(For lambdas, when we need them, we do have JS and AS now, and for lisp, there is always emacs)

By the way – just in case anyone gets frustrated; I’ve seen hair pulled on this forum before because of auto-correct creating unparseable curly quotes:

@eastgate 's code will only evaluate successfully if “1;2;3;4;5”; is edited to "1;2;3;4;5"; (purging those lurking “ ”)

(My personal recipe for sane living under macOS is to turn straight to System Preferences > Keyboard > Text and clear every auto-correct rule and option in sight :slight_smile: )

1 Like

I think, you mean curly quotes?

1 Like

quotes - exactly - thanks

(amended above)

If citing ‘code’, especially with quotes in use a back-tick ` before and after. Thus ‘this’ can be made to render as this 'this'. In both cases I just typed an apostrophe but in the first case the forum software auto-corrected it to ‘curly’ (typographic) quote style.

So for using code inline in text or for single lines of code use back-ticks or select the relevant text and use the </> button at the top of the message drafting box in the browser.

For multi-line code use three back-ticks on a separate line before and after the lines of code. Thus you type:
```
$Color = “bright red”;
$Price = 42;
$Answer = “42”;
```
N.B. here, the forum is changing the srtriaght double quote I typed to curly ones. The above, when posted, is rendered as:

$Color = "bright red";
$Price = 42;
$Answer = "42";

The syntax colouring is a by-product and an approximation as the forum software doesn’t have Tinderbox-specific code syntax plug-in. However, it is generally helpful—as in the last example: the attribute references are in cyan, quoted strings are in red and numbers are in black. Notice how the twop instances of the value 42 are rendered differently as one is a string and one a number.

Using the quote mechanism, i.e. the button in the drafting box with a right double curly quote symbol, will not stop the forum altering the quote style though some poster seem to hope it will!

Side-note to self. This is probably the germ of what should be a sticky post in the forum to help new (forum)n users.

Good idea! (I must write at least 20 chars… please ignore the text in those parentheses :grinning: )

The best thing about bringing a product to market is, of course, that you lose control over what people do with it.

(Had projected motion pictures been used in the way that was intended, we would still be watching boxing matches, performing dogs, and Le Débarquement du congrès de photographie à Lyon.)

2 Likes

(Tho to be fair, if HTML had been used in the way that was intended, we would still have bookshops, sustainable newspapers, and functioning democracies)

( And if the printing press had been used in the way that was intended, we could have skipped the Reformation and the horrors of the French Revolution : - )

1 Like