LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Classic View

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

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

Print Reply
Marcin Wolinski <[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
misleading.

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:

\newskip\barskip

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

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

% UseTemplate:

% \mycommand accepts two arguments
\def\mycommand{%
        \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:

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

(with instantiation as above)

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

Marcin

ATOM RSS1 RSS2