Trending Technology Machine Learning, Artificial Intelligent, Block Chain, IoT, DevOps, Data Science

Recent Post

Codecademy Code Foundations

Search This Blog

File reading writing in AI

File

Open

- The open function allows a user to open a file from the RHS and attaches a logical name to it.

- This function takes three arguments :
  • (1) the name of the file to be opened ;
  • (2) the logical name which will be used by other CLIPS I/O functions to access the file ; and
  • (3) an optional mode specifier.
  • The mode specifier must be one of the following string :
  • "r" read access only
  • "w" write access only
  • "r+" read and write access
  • "a" append access only
Syntax
  (open <file-name> <logical-name> [<mode>])
  • The <file-name> must either be a string or symbol and may include directory specifiers.
  • If a string is used, the backslash(/) and any other special characters that are part of <file-name> must be escaped with a backslash.
  • The open function returns TRUE if it was successful, otherwise FALSE.

 
Close
  • The close function a file stream previously opened with the open command. The file is specified by a logical name previously attached to the desired stream.
  • Syntax
          (close [<logical-name>])
  • If close is called without arguments, all open files will be closed.
  • The user is responsible for closing all files opened during execution. If file are not closed, the content are not guaranteed correct, however, CLIPS will attempt to close all open files when the exit command is executed.
  • The close function returns TRUE if any files were successfully closed, otherwise FALSE.

Printout
  • The function printout allows output to a device attached to a logical name.
  • The logical name must be specified and the device must have been prepared previously for output (e.g., file must be opened first).
  • To send output to stdout, use a t for the logical name.

 Syntax
  • (printout <logical-name> <expression>*)
  • Any number of expressions may be placed in a printout to be printed.
  • Each expression is evaluated and printed (without no spaces added between each printed expression).
  • The symbol crlf used as an <expression> will force a carriage return/newline and may be placed anywhere in the list of expression to be printed.
  • The printout function strips quotation marks from around strings when it prints them.
  • This function has no return value.

Read

The read function allows a user to input information for a single field. All of the standard field rules (e.g., multiple symbols must be embedded within quotes) apply.

Syntax 
   (read [<logical-name>])
  • Where <logical-name> is an optional parameter. If specified, read tries to read from whatever is attached to the logical file name.
  • If  <logical-name> is t or is not specified, the function will read from stdin.
  • If an end of file (EOF) is encountered while reading, read will return the symbol EOF.
  • If errors are encountered while reading, the string "*** READ ERROR ***" will be returned.

Readline
  • The readline function is similar to the read function, but it allows a whole string to be input instead of a single field.
  • Normally, read will stop when it encounters a delimiter.
  • The readline function only stops when it encounters a carriage return, a semicolon, or an EOF.
  • Any tabs or spaces in the input are returned by readline as a part of the string.
  • The readline function returns a string.
Syntax
     (readline [>logical-name>])
  • where <logical-name> is an optional parameter.
  • If specified, readline tries to read from whatever is attached to the logical file name.
  • If <logical-name> is t or is not specified, the function will read from stdin.
  • As with the read function, if an EOF is encountered, readline will return the symbol EOF.
  • If an error is encountered during input, readline returns the string "*** READ ERROR ***".

Rename

The rename function is used to chage the name of a file.

Syntax
     (rename <old-file-name> <new-filename>)
  • Both <old-file-name> and <new-file-name> must either be a string or symbol and may include directory specifiers.
  • If a string is used, the backslash (/) and any other special character that are part of either <old-file-name> or <new-file-name> must be escaped with a backslash.
  • The rename function returns TRUE if it was successful, otherwise FALSE.


Remove

The remove function is used to delete a file.

Syntax
    (remove <file-name>)
  • The <file-name> must either be a string or symbol and may include directory specifiers.
  • If a string is used, the backslash (/) and any other special characters that are part of <file-name> must be escaped with a backslash.
  • The remove function returns TRUE if it was successful, otherwise FALSE.

No comments:

Post a Comment

Popular Posts