Примеры подготовки пакетов расширений
Пакет расширения графики
Следующий пример иллюстрирует подготовку графического пакета расширения, который строит графики ряда функций с автоматической установкой стиля линий каждой кривой.
(*:Title: Plot *) (*:Context: ProgramminglnMathematica"Plot" *) BeginPackage["ProgramminglnMathematica4 Plot4"] Plot::usage = Plot::usage <> " If several functions are plotted, different plot styles are chosen automatically."Begin["'Private'"] protected = Unprotect[Plot] $PlotActive = TruePlot[f_List, args__]/; $PlotActive: = Block[{$PlotActive = False}, With[{styles = NestList[nextStyle, firstStyle, Length[Unevaluated[f]]-1]}, Plot[f, args, PlotStyle > styles] ] ] (* style definitions *) unit = 1/100 max = 5firstStyle = Dashing[{}] nextStyle[Dashing[{alpha__, x_, y_, omega__}]] /; x > y + unit: =Dashing[{alpha, x, y + unit, omega}] nextStyle[Dashing[l_List]]: =Dashing[Prepend[Table[unit, {Length[1] +1}], max unit]] Protect! Evaluate[protected] ] End[ ] EndPackage[ ]Рисунок 10.6 показывает применение данного пакета.

Рис. 10.6. Пример применения функции Plot из пакета расширения plot.m (*:Name: Algebra"CountRoots' *)
