Tinderbox Forum

Initiating and Editing Lists and Sets

Questions:

  1. How do I create a list or set
  2. How do I edit a list or set
  3. What is the correct syntax for the list

So Far:
I created a “User” attribute by selecting the “User” in the list of attributes in the note pane. Gave the attribute a name and added a couple of entries.
Made a mistake on one of the entries and wanted to edit it.

At this point it occurred to me that there ought to be a formal way of creating a list or set. At least more formal than simply adding it in the text pane attributes popup. But perhaps not.
Having made a mistake I wanted to edit the list and again it occurred to me that there ought to be a way to see and edit the list (or set). But perhaps not.

So far I can’t see any formal way to create a list or to edit it.

What do I mean by formal? Something like having a menu option that says create list and also offers a way to edit established lists. This would something akin to creating a pick list in a database on the Mac.

It seems to me that the way I created the attribute is a little ad hoc and although that works I cannot see a way to edit an existing list/set.

I’d appreciate any guidence/education or pointers to help increase my knowledge on this subject.

Thanks.

List and sets are delimited by semicolons:

Ithaca;Utica;Saratoga

You typically create a LIST ATTRIBUTE in the user attribute inspector:

The most common way to edit the value of a list attribute is the displayed attributes table. But the attribute pane of Get Info is also common, and Quickstamp Inspector is often useful as well.

Getting Started With Tinderbox, in the Help menu, may be useful to you.

You can also view and edit items in the attribute browser. The Attribute Browser is one of my favorite views in Tinderbox for gaining understanding and using attributes.

Did you look at the notes on aTbref? There is quite a lot of info on the List data type and Set data type and the a range of action codes can work on Lists or Sets—see more

When making the user attribute, you would also want to set the data type (see links above) to List—in the Document Inspector’s User tab as these are the only two data types that understand their data as being a list of values, i.e. a multiple-value attribute.

Values for an attribute are held per-note but you can set a default and suggested value(s) via the Inspector (link above).

If you want to find all the discrete values currently used in the document for a given attribute see values().

@eastgate

Thanks.

Your directions of editing in the “Displayed Attributes Table” appeared to present a problem for me. I had a misspelled word in the list. On a note I selected the related attribute from the user list of attributes. Once displayed I corrected the spelling and hit return.

The result was that I now had two versions of the word. The misspelled version and the corrected version.
Clearly I’m in error but I don’t see any other way to perform an edit.

Would you clarify how the edit should be made.

Thanks.

@TomD

Thanks. Really helpful.

@mwra

Thanks for the detailed response.

Yes, I had looked at the notes but in “wandering around” had possibly missed the answers to my questions.

You did bring up one item that isn’t clear to me.

If you want to find all the discrete values currently used in the document for a given attribute see [values()

I looked at the reference but its not clear to me how to use this. I don’t see how the results would be displayed. Is this a query for an agent and so does it produce a list of notes. I did experiment but couldn’t produce a result so I clearly am missing something.

As far as I understand (i.e. in the most basic terms…):

The dropdown lists for a list/set attribute in the Display Attributes pane are generated dynamically and they contain a) the ‘suggested values’ as explained above, and b) every single value that the attribute has been given in any note in the project. i.e. if you’ve entered a value for this attribute on any note, it will immediately become available in the dropdown list for you to use elsewhere.

The corollary of that is that if you delete all the notes which have that value (or you correct the misspelling in every note), then it will immediately disappear from the list.

So in your case, you need to identify all the notes with the misspelt value (e.g. by using an Agent or filtering) and change them all to the correct one. Once you’ve amended the last incorrect value, that value will disappear from the list.

HTH.

As documented, values() returns a list. So you decide what to do with that list. For instance, do you want to see all the values of $MyList as discrete lines in a note?

$Text = values("MyList").format("\n");

The values() returns the list of discrete values, the .format() replaces the semi-colon value delimiters with line breaks and the result is put in the current note’s text as one value for each (single-line) paragraph.

I’m sorry if the docs are confusing but action code is an Erector Set (or Lego or Meccano if you prefer). You do the making by deciding which parts (tools) in the box to use. aTbRef is a reference and deliberately not a how-to as the permutations and variations are nigh infinite; if I tried to guess and document and keep updated every person’s ‘obvious-in-the-moment-only’ task Ie’d never be done. So, use the reference and if stuck, come and ask here, as you have :slight_smile:

I’d argue though that the notes on values() are clear. The problem here is an incorrect approach to a toolset. Rather than look for something like the end-point like “see all the values”, break it down to tasks. The thinking might go like this:

*“How to I get all the values of a particular attribute?” Ah, values() does that. So, I’ll set a List type attribute to the output of values.

  • "It gives me back a Set-type list, so I know I get de-duped list so I don’t have to do that step.
    “It’s sorted, but I might want a different sort - let’s park that for now until we see the list.
    *“Now, how do I see a list?”. Put it into $Text?”. Nope, I get the literal list - one long string with semi-colons between items.
  • “I can format a list using `.format()”. Aha, if I replace each semi-colon with a line break I should get a $Text with one value per line" Tada!

Sorting, you might want a different sort, let’s say case-insensitive in reverse order. So in our above example we’d modify it:

$Text = values("MyList")..isort.reverse.format("\n");

Notice how we simply chain in two extra operators. the aTbRef action code listing uses data-type prefixes where pertinent as some codes like .format() work differently with different data types. In the last case above is would enable you to check the difference of using .sort or .isort or .nsort in a list.

Please don’t read this explanation as rebuke, or an attempt to patronise. I’m just trying to help show how to break down a task and uses the references available. Failing that, there is the forum. If asking, though one tip for everyone: don’t just say what didn’t happen as that’s not actionable info. start what you tried: what you got vs what you expected. Or state what you envisaged being possible. Referring to some other app’s norm’s is rarely helpful as it assumes others use that app. Better is to be explicit about how [other app] does something. You may well find in describing [other app]'s process that you start to see how to use Tinderbox’s tools to the same or similar end (even if not in exactly the same way as [other app]).

HTH :slight_smile:

1 Like

After all the above I forgot the other issue. How to fix a typo in a list. I’cve just done this very thing. Editing aTbRef for v9, I noticed my $OPType value pop-up in Displayed Attributes showed a “Data Manipulation” and a “Date manipulation” value, the latter being wrong. If I knew there was only one note with the wrong value, I’d just edit the Displayed Attributes by either:

  • Click into the desired attribute’s value box and edit the new value.
  • Click the desired attributes value pop-up listing and click the bad value, this un-tick/removes it from this note. Now click the correct value if listed in the pop-up or manually add the new value - remember to put a semicolon after the existing last item before typing.
  • Note the bad value may still show in the pop-up until you select a new now and the value list is refreshed.

More likely, and as in my case, I knew there were several notes amongst possibly >100 with the wrong value. An agent is the way to go. Make an agent. In my case the attribute was a String-type attribute OpType. So the query is:

$OpType=="Data manipulation"

And we add an action setting the correct value:

$OpType="Data Manipulation";

note the use of a == equality test in the query vs. the = assignment operator in the action.

The agent will briefly detect and make alaises for the notes with bad values. this updates their $OpType value, causing them to cease to match the query. Once the agent is empty again, the job is done and you can delete the query, or address another discrete spelling issue in the same or another attribute, amending query and action accordingly.

But, what is this were a multi-value (Set or List) attribute, such as $Tags. Let’s do the same exercise for that. We can use == with a multi-value attribute but so we use contains() or .contains() to match whole values (regex are not supported in this context). As the error is a typo, we want a case-sensitive match. So the agent query is:

$Tags.contains("Data manipulation")

That finds notes with the bad value. Now, we need to remove the bad value and add the correct one. But as the removal affects the query, I always add first and subtract second. It’s all in one action and it shouldn’t matter; but, belt & braces! So, the action is:

$Tags = $Tags + "Data Manipulation";
$Tags = $Tags - "Data manipulation";

As in the earlier case, the agent will run, find the ‘bad’ items, correct their values and the agent will empty as all the errors are fixed.

HTH

To the contrary, I thought your comments very edifying.

Just FYI, no comment needed. Also I’m writing my results in case another visitor could use the information.

I think the problem for me was that I didn’t know enough to ask the correct questions. Had I done something like the following I suspect I would have found my answer in less time.

Q: Is it possible to display all the items in a List or Set?
A: Y.

Q: Where can you display the items?
A: In the text body of a note

Q: What methods are required to display the list in a text body?
A: There are at least two methods (there could be more but they haven’t occurred to me). One is to create a Stamp and with the correct commands/code in the Action panel of the Stamp you can display the items in the body panel of the note. The second method will present the items in a note body by writing code in the parent note. This appears to act like an OnAdd command so that when a new note is added to the parent the text body of the new child will present the items. Using this method the code must be inserted in the Action panel of the Action Inspector as opposed to the Action Panel of the Stamp. This seems a little confusing at first since one might intuitively expect that these panels having the same name would represent the same list of actions.
These methods work for Lists and Sets. I also tested both methods in Notes and Agents.

Q: What code is required to present the items in the list?
A: $Text = values("ListAttributeName").format("\n");

All of the above is subject to correction by people who know far more than me.

1 Like