Operating System - OpenVMS
1753974 Members
6886 Online
108811 Solutions
New Discussion юеВ

Re: DCL logical operator

 
SOLVED
Go to solution
sbisht
New Member

DCL logical operator

i wrote following code

if (f$search("ABC.DAT") .nes. "") .and. f$attribute("ABC.DAT","EOF") .ne. 0)
then
! do something
endif

this code doent work when file in not present. f$attribute throws error.
Why is second expression evaluated when first is not true ?
8 REPLIES 8
abrsvc
Respected Contributor
Solution

Re: DCL logical operator

If memory serves me correctly:

Because DCL is an interpretive "language", the entire line is parsed at the same time with symbol substitutions done "in-line". In this case, both expressions are equated to "temporary" symbols and then evaluated for the equivalences and logic tests.

In a case like this the statement should be in the following format:

IF f$search("abc.dat") .eqs. "" then skip_it

ELSE
IF F$attribute...
then
!do something
endif
ENDIF



Dan
Hoff
Honored Contributor

Re: DCL logical operator

I'm going to guess that you're familiar with compilers, and less so with old-school interpreters.

The DCL interpreter processes the whole command for symbol substitutions (in a couple of phases), and then figures out what to do with the results.

DCL is an old-school and comparatively ancient command interpreter, and DCL procedures can thus have all sorts of interesting and even self-modifying behaviors. Which is why DC interpreter tends to process the whole command.

The definition of DCL syntax (for what that is) doesn't particularly lend itself to compilation, either.

There are other interesting behaviors you may encounter on your journey, such as specific cases where the contents of DCL comments can be executed. Not ignored.

Regardless of how it works or how you might think it should work, DCL processing is also comparatively unlikely to change in any significant fashion, given its existing and massive installed-base problem. The comment case was an old bug in DCL, and code became dependent on it, so DCL was changed (back) to allow the cases that were used.
sbisht
New Member

Re: DCL logical operator

Thank you Dan, of course I did it other way but needed a better explanation.

Thanks Hoff for further insight and interesting fact.
Hein van den Heuvel
Honored Contributor

Re: DCL logical operator


just to be clear, you really used f$file() right?

The behaviour stands, but just to be clear.

Hein
John Gillings
Honored Contributor

Re: DCL logical operator

For completeness and generality...

Note that your expectation of shortcut logical evaluation depends on the rules of the language. Even for compiled languages, there are numerous different rules which may be applied.

Some languages always shortcut, some never shortcut, some have different operators for complete or shortcit evaluation, and others (notably Fortran) are defined to allow the compiler to rearrange a logical expression as it sees fit.

In situations such as yours, where the validity of one term in the expression is dependent on another, or where side effects of evaluating one term may affect another, you need to be careful that your assumptions match the rules of the language.
A crucible of informative mistakes
P Muralidhar Kini
Honored Contributor

Re: DCL logical operator

Hi,

>>if (f$search("ABC.DAT") .nes. "") .and. f$attribute("ABC.DAT","EOF") .ne. 0)
Couple of things about this
* There is nothing like f$attribute. I guess you meant f$file_attributes

* There is syntax error in the above line. the second expression is missing a
bracket. It should rather be
$if (f$search("ABC.DAT") .nes. "") .and. (f$file_attribute("ABC.DAT","EOF") .ne. 0)


>>Why is second expression evaluated when first is not true ?
You would expect this to work in a C program for example.
But as others have already explained, DCL parsing stuff does not work like that.

You have to modify your program based on how DCL works. Something like -

$ if (f$search("ABC.DAT") .eqs. "") then GOTO skip_file
$ if f$file_attribute("ABC.DAT","EOF") .ne. 0
$ then
$ ! Handle file ...
$ endif
$
$ skip_file:
$ !skip file handling
$ ...

Hope this helps.

Regards,
Murali
Let There Be Rock - AC/DC
P Muralidhar Kini
Honored Contributor

Re: DCL logical operator

sbisht,
Looks like you are new to the forum.

Check the following link which says how to thank the forum -
http://forums11.itrc.hp.com/service/forums/helptips.do?#28

Regards,
Murali
Let There Be Rock - AC/DC
sbisht
New Member

Re: DCL logical operator

I got explanation for the error..hence closing the thread.