I am trying to understand the syntax of .bst-files using the Guide Tame the Beast. For starters, I want to understand the example of the multiplication function on page 39 (The functions skip$ and if$ are explained on pages 33 to 35):

The first assignment in the function looks like this:

'a :=

Which is described as "We store the first value".

I know about stack-oriented programming and reverse polish notation, but I never actually coded it myself. What does the apostrophe do here? Is it related to "storing"? Sometomes I also see functions (such as skip$) with a preceding apostrophe. What is the meaning of this?

  • 'skip$ means “put skip$ on the stack”, rather than making it act. – egreg Aug 2 '17 at 16:20
  • skip$ is a function, how do I put a function on the stack? – AlphaOmega Aug 2 '17 at 16:22
  • 1
    Everything is put on the stack, but this way, skip$ will do its work later on, when it happens to be at the top of the stack. – egreg Aug 2 '17 at 16:23

The ' here means that rather than trying to evaluate a here, BibTeX will use the name itself. It the construct

'a :=

there will be some integer on the stack (let's call it 1), so we actually have

#1 'a :=

This will assign variable a as 1. If we didn't have the ', BibTeX would try to evaluate a here. As a will have been declared as an integer, that would mean that the value would be placed into the stack here. So something like

#1 'a :=
#2 a =
   { } % True code
   { } % False code

works (and here is false): the second use of a inserts the value into the sack so we can do the comparison.

The ' syntax is also used to avoid needing to have brace groups around a one step branch in a conditional. It's used in constructs such as

  'skip$ % True branch
  { }    % False branch

most commonly with skip$ (do nothing) or pop$ (pop the top item from the stack). Without the ' and the { } group, BibTeX would try to execute the function at the wrong time, and odd errors would result. (Here of course one could just use a brace group for the desired outcome.) The underlying concept is the same as the first case: put the quoted thing on the stack.

| improve this answer | |
  • 1
    Well, in the example a and b are declared to be integer variables, but this doesn't really change the description. – egreg Aug 2 '17 at 16:14
  • Ok so if I understood correctly, it's equivalent to the single equal sign "=" for an assqignment vs double equals "==" for an evaluation? – AlphaOmega Aug 2 '17 at 16:18
  • @egreg I'd missed that this came from a set up where a is an integer: I've adjusted – Joseph Wright Aug 2 '17 at 16:23
  • 1
    @AlphaOmega Well not really as BibTeX uses = for the test and := for the assignment, so those distinctions also apply – Joseph Wright Aug 2 '17 at 16:24
  • 2
    @AlphaOmega At the risk of explaining all of BibTeX in one answer + comments: strings are added to the stack by quoting in the form "...", integers are added to the stack in the form #.... – Joseph Wright Aug 2 '17 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.