LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Marcin Wolinski <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Tue, 7 Dec 1999 23:02:53 +0100
text/plain (84 lines)
Hans Aberg wrote:
> There are two separate aspects of what is called OOP  or object oriented
> programming, one that the objects are dynamic (as you say), and another
> that the objects constitute localized namespaces.
> [...]
> I think I pointed that the dynamic aspect does not appear to make sense in
> TeX. Therefore I concentrated on the static, namespace, aspect, which just
> as templates just requires macro expansions.

The problem is you cannot fully implement static namespaces in TeX ---
not for all primitive datatypes present.

Note that templates do not allocate <storage-bin>s.  For some types
(e.g. macro names) this is not needed.  For others (dimension
registers, counters) it is.  But precisely for those we do not want to
allocate registers inside the template code.  Moreover assignments
done by template code are not local to that piece of code --- no
grouping done by the template mechanism itself.

Some more perverse templates use for <storage-bin>s TeX's internal
parameters such as \leftskip, \rightskip or \parindent.  And the
assignment done has to last past the end of execution of template
code.  It can be argued whether this is use or abuse, anyway it seems
very useful.

So the seemingly obvious similarity to objects is in fact rather

A real TeX hacker would probably say that templates are a useless thin
wrapper around calc that provides no new interesting features besides
the ability to freeze calc computed values.  :-)

Here is real hacker's implementation of templates:


% \DeclareTemplate{mytemplate} (two template arguments):

        \def\foo##1{##1}% default \foo
        \barskip=42dd   % default \barskip
        #1%  this is DoParametersAssignments
        % template code here:
        \hbox@to\textwidth{\foo{#2}\hfil #3}% whatever

% UseTemplate:

% \mycommand accepts two arguments
        \mytemplate{\def\foo##1{\textbf{##1}}% not sure whether to
                                             % quadruple #'s here - i'm
                                             % not a real TeX hacker
% we use the default value for \barskip here

% And in the document:

\mycommand{real hacker}{13}

And an optimizing hacker with syntactic sugar would provide this
implementation instead:

        #1%  this is DoParametersAssignments
        % template code here:
        \hbox@to\textwidth{\foo{#2}\hfil #3}% whatever

(with instantiation as above)

So maybe we should abandon all this strange template stuff and start
real programming?  Just kidding.