Difference between revisions of "Nyquist Property List Tutorial"

From Audacity Wiki
Jump to: navigation, search
(Moved from Nyquist_Plug-ins_Reference)
(Variables and Property Lists: Add link to XLisp manual)
Line 19: Line 19:
   return get(quote(*TRACK*), quote(NAME)) ; SAL
   return get(quote(*TRACK*), quote(NAME)) ; SAL
{{advice|See also [http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/xlisp/xlisp-man/xlisp-man-014.htm Property List Functions] in the XLisp manual.}}

Revision as of 17:26, 19 April 2018

Variables and Property Lists

In general terms, a variable is a symbol which contains a value. The symbol can be any valid name, and its value may be changed (hence "variable"). In Nyquist, the value may be of any data type (for example, a number, a character, or even a sound) and may be changed from one data type to another. Unlike some programming languages, variables do not need to be declared before use - they can just be set, and then they exist.

Setting the value of a symbol "binds" the value to the symbol. A symbol that has no value (not even "nil") is said to be "unbound".

In addition to the value of a symbol, we can also attach properties. This is a way of associating a list of items, each with their own value, to a single variable. Each item is called a key or indicator, and we can give each key a value. This list of items is called a "property list" (or plist for short).

To get the value of a property, we use the GET command.

When getting the value of a property, we do NOT want to evaluate either the variable (symbol) or the key symbol, so we must "quote" both symbols to prevent evaluation.

 (GET 'varaiable-name 'property-name) ; Lisp syntax
 set v = get(quote(varaiable-name ), quote(property-name)) ; SAL syntax

As an example, if we have a variable called *TRACK* (which we do in version 4 plug-ins), and it has a property called NAME (which it does), then we can "get" the value of that property with:

 (GET '*TRACK* 'NAME) ; Lisp
 return get(quote(*TRACK*), quote(NAME)) ; SAL

Warning icon See also Property List Functions in the XLisp manual.