about function "close"

27 views
Skip to first unread message

denis.be...@gmail.com

unread,
Jan 11, 2025, 12:55:11 AMJan 11
to CLIPSESG
I find it strange that function "close"  sees data beyond its lexical scope.
Here's a simple example of what I mean (both in 6.3 and 6.4):

(deffunction foo1 (?file1)

    (close)

    (open ?file1 "file1" "r")

    (readline "file1")

   (close "file1")

)

(deffunction foo2 (?file1 ?file2)

    (open ?file2 "file2" "r")

    (foo1 ?file1)

    (readline "file2")

    (close "file2")

)

 (foo2

    file1.txt

    file2.txt

)

Logical name 'file2' was not recognized by any routers.

[PRCCODE4] Execution halted during the actions of deffunction 'foo2'.


The call to foo1 inside foo2 closes the "file2" stream in spite of foo1 having no lexical visibility on "file2". 
This is because symbols and strings behave as global constants. I think some caution about this should be added to the User Manual, where there's only a vague sentence in section "12.4.2.1 open":
"The logical name should not have been used previously."
Here "previously" means in the whole dynamical scope - a strong breach to lexical scoping.

CLIPS Support

unread,
Jan 12, 2025, 12:38:41 PMJan 12
to CLIPSESG
I'll add a note.
Reply all
Reply to author
Forward
0 new messages