gdl
gdl copied to clipboard
Interpreter errors using concatenation ("&")
Overall I've had little-to-no problems with command concatenation ("&") and line continuation ("$"). However as I recently have transferred scripts to a new computer I discovered this error when an extra "&" slipped into an endif-else-begin statement:
if( !version.os_name eq 'Windows' ) then begin &$
dst = "D:/f/" & Pathsep=";" & print,' Windows' & endif & else begin & $
dst ="/d/f/" & Pathsep=":" & print,'Whoops!' &endelse
This is a valid statement in GDL, but it shouldn't be, just as "else begin" by itself is not. To see this in a linux system one would reverse the logic:
if( !version.os_name ne 'Windows' ) then begin &$
dst ="/d/f/" & Pathsep=":" & print,'Not Windows' & endif & else begin & $
dst = "D:/f/" & Pathsep=";" & print,' Windows'&endelse
Another odd behavior of concatenation: "&&" should be interpreted(?) as just "&" but is not:
GDL> resu2a=FILE_WHICH('../src/', filetest) & print,resu2a
../src/gdl
GDL> resu2a=FILE_WHICH('../src/', filetest) & & print,resu2a
../src/gdl
GDL> resu2a=FILE_WHICH('../src/', filetest) && print,resu2a
% Variable is undefined: PRINT
% Execution halted at: $MAIN$
concerning the second point
IDL> resu2a=FILE_WHICH('../src/', filetest) && print,resu2a
% Keyword RESU2A not allowed in call to: PRINT
% Execution halted at: $MAIN$