The plists Module

Overview

Property lists associate values with keys, but without the overhead of a <table>. These are generally useful for a small number of keys or where memory usage is a concern.

This implementation allows plists to be stored in either a <list> or a <vector>. The keys are commonly called indicators and are typically a <symbol>. The values can be any <object>.

In memory, the plist is arranged with keys and values alternating in a single sequence:

#[key1:, 1, key2:, 2]

Conveniently, this is the same layout as a sequence of arguments when using #rest in conjunction with keyword arguments and #all-keys as can be seen in the example using with-keywords-removed.

Reading

Modifying

Iterating

Reference

get-property Generic function

Return the value for an indicator, with a default should it not exist.

Signature:

get-property plist indicator #key default => property

Parameters:
Values:
keyword-sequence Generic function

Returns a sequence containing the indicators in the plist.

Signature:

keyword-sequence plist => keywords

Parameters:
Values:
See also:

put-property! Statement Macro

Modify the plist, adding indicator with the given value.

Macro Call:

put-property!(plist, indicator, value)

Parameters:
Example:
put-property!(buffer-contents-properties(buffer),
              #"optimization-colors", #f)
See also:

remove-keywords Generic function

Returns a copy of the plist with keywords removed.

Signature:

remove-keywords plist keywords => plist

Parameters:
Values:
See also:

remove-property! Statement Macro

Modify the plist, removing indicator, returning the old value, if any.

Macro Call:

remove-property!(plist, indicator)

Parameters:
Values:
Example:
remove-property!(buffer-properties(buffer), #"project");
See also:

value-sequence Generic function

Returns a sequence containing the values in the plist.

Signature:

value-sequence plist => values

Parameters:
Values:
See also:

with-keywords-removed Statement Macro
Macro Call:

with-keywords-removed(var = plist, keywords) body end

Parameters:
  • var – A Dylan name BNF.

  • plist – An instance of <sequence>.

  • keywords – An instance of <sequence>.

  • body – A Dylan body BNF.

Discussion:

Executes the body, with the keywords removed from plist and the modified plist available as var.

Example:
define sealed method make
    (class == <interval-stream>, #rest initargs,
     #key buffer, interval, direction, #all-keys)
 => (stream :: <interval-stream>)
  ignore(direction);
  let (start-bp, end-bp)
    = values(interval-start-bp(buffer | interval),
             interval-end-bp(buffer | interval));
  let buffer
    = buffer
      | select (interval by instance?)
          <buffer>  => interval;
          otherwise => bp-buffer(start-bp);
        end;
  with-keywords-removed (initargs = initargs, #[interval:])
    apply(next-method, class,
          start-bp: start-bp, end-bp: end-bp,
          buffer: buffer, initargs)
  end
end method make;
See also: