gdl icon indicating copy to clipboard operation
gdl copied to clipboard

Interpreter errors using concatenation ("&")

Open maynardGK opened this issue 6 years ago • 2 comments

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

maynardGK avatar Jan 05 '20 23:01 maynardGK

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$

maynardGK avatar Jan 20 '20 07:01 maynardGK

concerning the second point

IDL> resu2a=FILE_WHICH('../src/', filetest) && print,resu2a
% Keyword RESU2A not allowed in call to: PRINT
% Execution halted at: $MAIN$     

GillesDuvert avatar Jun 25 '21 09:06 GillesDuvert