I have a list (aList) of which item 1 is
{{issued:{|date-parts|:{{2000, 11}}}, |number|:"CMU/SEI-2000-TR-030", |id|:"noauthor_cmmi_2000", title:"CMMI SM for Systems Engineering/ Software Engineering/ Integrated Product and Process Development, Version 1.01 (CMMI-SE/SW/IPPD, V1.01). Staged Representation.", |citation-key|:"noauthor_cmmi_2000", language:"en", publisher:"Carnegie Mellon Software Engineering Institute", |type|:"report"}}
from which I want to retrieve the 'number' item. Other list items may not have a number item or a different number of items and hence I want to try and retrieve the value ("CMU/SEI-2000-TR-030") using the item's key - 'number' rather than the order position
i.e.
try
set documentID to ". " & number of item 1 of aList
end try
which fails because number
is a reserved term.
Is there a way to get around this to retrieve this?
CodePudding user response:
The pipe character (|) that many of your variables are surrounded with, force the enclosed characters to be treated as a variable. As an item within 'aList', you use |number|, so continue to surround 'number' with pipes when you use it later.
set documentID to ". " & |number| of item 1 of alist
FWIW, this is discussed under Identifiers in the Language Guide (as vertical bar character in identifiers) and the practice is not recommended.