Topics

Behavior of 'include' inside 'if' statement

Pablo Arantes
 

Fellow users,

On a script, I would like to include an external script conditional on the value of a variable.

A simplified version of the relevant bit would be something like the following:

if option = 1
include external1.praat
else
include external2.praat
endif

('includes' are not indented following instructions on section 5.8 of Praat's Manual)

I was expecting that if 'option' gets '1', 'external1.praat' would be included but 'external2.praat' would not. Conversely, if 'option' gets a value other than '1', then 'external2.praat' would be included but not 'external1.praat'.

What I'm getting, though, is that 'external1.praat' is always included, regardless of the value of 'option', as if 'include' ignores that it is nested inside an 'if' statement. Is it the intended behavior? Is there another way to implement what I described in the paragraph above?

Regards,

Pablo

--
www.pabloarantes.net

Boersma Paul
 

On 17 Jan 2020, at 03:39, Pablo Arantes via Groups.Io <pabloarantes=protonmail.com@groups.io> wrote:

if option = 1
include external1.praat
else
include external2.praat
endif
The "include" statement just includes the contents of a file; that's why it is not indented. So if external1.praat contains
AA
BB
CC
end external2.praat contains
DD
EE
FF
then the resulting script is

if option = 1
AA
BB
CC
else
DD
EE
FF
endif

This is the same as in many other programming languages. It allows interesting stuff (such as including the contents of a "for" loop), and, relatedly, it does not take part in normal execution flow logic.

Analogously, the following does no choose between wo procedure definitions:

if option = 1
procedure x
do this
endproc
else
procedure x
do that
endproc
endif

_____

Paul Boersma
Professor of Phonetic Sciences, University of Amsterdam

Visiting address: Spuistraat 134, room 632, Amsterdam
Mail: P.O. Box 1642, 1000BP Amsterdam, The Netherlands
Website: http://www.fon.hum.uva.nl/paul/