Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created June 24, 2012 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zr-tex8r/2983511 to your computer and use it in GitHub Desktop.
Save zr-tex8r/2983511 to your computer and use it in GitHub Desktop.
Something about subcommand & object packages
\documentclass{article}
\usepackage{subcommand}
\begin{document}
\def\mycmd{!?}
\subcommand\mycmd[:foo]#1{\textit{foo}(#1)}
\subcommand\mycmd[:fool]#1{\textit{fool}(#1)}
\mycmd:foolish % (\mycmd:fool{i}) + (sh)
\mycmd:footware % (\mycmd:foo{t}) + (ware)
%\mycmd:fantasy % ERROR!
\end{document}
\documentclass{article}
\usepackage{object}
\begin{document}
% Let's make the 'hoge' class.
\def\makehoge#1{%
\def#1{}%
\object::field#1{foo}%
}
\makehoge\hogeA
\hogeA.foo = {Piyo}
(\hogeA.foo)%==>(Piyo)
% This is reference-copy.
\def\foovalue{\hogeA.foo}
% How to do value-copy?
%\let\foovalue=\hogeA.foo% make no sense
%\edef\foovalue{\hogeA.foo}% ERROR!
\makehoge\hogeB
% How to do value-copy?
\hogeB.foo := {\hogeA.foo}% said "call-by-value"
(\hogeB.foo) %==>(Piyo)
\hogeA.foo = {Fuga}%
% That does not change \hogeB... really?
(\hogeB.foo) %==>(Fuga) % OOPS!
% I want to do arithmetic!
\newcount\countA \countA=6
\hogeA.foo = {9}
%\multiply\countA by \hogeA.foo % ERROR!
(\the\countA)
% Do it again, with subcommand.
\def\cmdA{}
\subcommand\cmdA[:nine]{9}
%\multiply\countA by \cmdA:nine % ERROR!
(\the\countA)
\end{document}
\documentclass{article}
\usepackage{pgf}
\usepgfmodule{oo}
\makeatletter %-------------------------
\newcount\xx@count
\pgfooclass{counter}{%
\attribute -val=0;
\method counter() {}
\method up() {%increments the value
\xx@count=\pgfoovalueof{-val}\relax
\advance\xx@count1\relax
\edef\xx@tempa{\the\xx@count}
\pgfoolet{-val}\xx@tempa
}
\method let-to(#1) {% lets #1 equal the value
\edef#1{\pgfoovalueof{-val}}
}
\method get() {% this would be nice, but...
\pgfoovalueof{-val}
}
}
\makeatother %-------------------------
\begin{document}
\newcount\result
\pgfoonew\ctrA=new counter()
\pgfoonew\ctrB=new counter()
\ctrA.up()\ctrB.up()\ctrA.up()\ctrB.up()\ctrA.up()
%\result=\ctrA.get()% ERROR!
\ctrA.let-to(\theval)\result=\theval
\ctrB.let-to(\theval)\multiply\result by \theval
(\the\result) %==>(6)
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment