×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem with copy_stream_data

Problem with copy_stream_data

Problem with copy_stream_data

(OP)
Hi there!
I'm trying to use the copy_stream_data predicate to copy user's input to a file.
The syntax is:
copy_stream_data(+StreamIn, +StreamOut)
So,SreamIn is the standard user input(the screen) and StreamOut I want it to be the file mytext.txt.
When i try writing copy_stream_data(user_input, 'mytext.txt') it gives me the following error:
ERROR: copy_stream_data/2: stream `mytext.txt' does not exist
what is it that i'm doing wrong??
I 'd really appreciate your help.

Renata.
 

RE: Problem with copy_stream_data

First of all, the standard user input is the keyboard. The screen is the standard user output, but that's probably due to rushing :)

Ok, to read from a file or to write to a file, you need a file descriptor. You associate a file descriptor to a file when you open that file and all the subsequent file operations will be done using the file descriptor.

CODE

print_to_file :-
    open('C:/mytext.txt', write, Descriptor),
    copy_stream_data(user_input, Descriptor),
    close(Descriptor).

When you run print_to_file, it lets you type multiple atoms. You can finish with Ctrl-Z and then you can inspect the contents of your file (C:/mytext.txt in this case) - if you don't supply a full path, you have to be able to locate the file yourself depending of the user settings for your account.

RE: Problem with copy_stream_data

(OP)
Yeah... it's due to rushing...!

I tried your solution and it works perfectly. Thanks for  your help.

Renata.  

RE: Problem with copy_stream_data

(OP)
Hi! I'd like to pose one more question...
i have this code that deletes a lesson from a knowledge base. Because there is a posiibility that information associated with the lesson may be stored elesewhere i want them gone too..
The problem is that although the code works and does remove the lesson from base.pl does not do the same thing with the associated information in explaination.pl and optional_courses.txt... Is there a reason for that??
I'm guessing it has something to do with variable Lesson... if so, how can i fix it? thanks in advance.

CODE

delete_lesson:-
    write('*****All inputted information must be in lowercase followed by period*****'),nl,
    write('Please enter the title of the cource you wish to delete:'),nl,
    read(Lesson),nl,
    write('Now enter the semester is offerred in:'),
    read(Semester),
    nl,
    retract(offerred_in(Lesson, Semester)),
    write('Deleting the given lesson in the knowledge base...'),nl,
    tell('base.pl'),
    write(':-dynamic(offerred_in/2).'),nl,
    listing(offerred_in),
    told,
    write('phase 1/3 completed'),nl,
    retract(explain(Lesson)),
    tell('explaining.pl'),
    write(':-dynamic(explain/1).'),nl,
    listing(explain),
    told,
    write('phase 2/3 completed'),nl,
    %tell('optional_courses.txt'),
    %retract(optional_course_is(Lesson)),
    %told,
    write('phase 3/3 completed'),nl,
    write('Lesson successfully deleted.\n'),
    write('Delete another lesson?\nPress y to confirm:'),
    read(Answer),
    Answer='y',
    delete_lesson,
    nl.

RE: Problem with copy_stream_data

From my point of view there is no problem with the code above, however there could be some problems elsewhere, depending how you defined offerred_in and explain.

I didn't understand exactly how does the code run for you (because I made it run fine on my machine, with both base.pl and explaining.pl being modified properly):

- does it bring up some errors after step 1/3 completed? - in this case, see if you made both offerred_in and explain dynamic
- or it runs without errors only there are no modifications in explaining.pl? - in this case, there could be a more subtle error

By the way, your code writes in 'explaining.pl' and you said something about a file 'explaination.pl'. Is it possible that you have 2 files and you are expecting the wrong file to get updated after the code runs?

RE: Problem with copy_stream_data

(OP)
It seems that, indeed, the code works fine. The error was coming from elsewhere.. Thanks once again.

RE: Problem with copy_stream_data

I am running a tool in prolog and after the running is finished i have the fllowing result:



Graph Size statistics: Nodes = 1 Abstract Edges = 0 Cases = 1



-- Pruning outputs --


-- Print pruned output- (clock-2) MDGs options --
No printing (Return) / Statistics only (%) /
To screen (Space) / To file (FILE-NAME) :

pruned output- (clock-2)


t


Graph Size statistics: Nodes = 1 Abstract Edges = 0 Cases = 1



Error detected!

=== The Counterexample ===

-------- Assumptions --------


-------- Initial state --------
input = z3
nxa = 1
reg_output_signal = 1

-------- Clock cycle 1 --------

-- The symbolic input --

t_ls6 = 1
glitch_signal = dg
select2 = 1

-- The symbolic state --

reg_output_signal = dgp

-------- Clock cycle 2 --------

-- The symbolic input --


-- Symbolic Output --

flag = 1

=== End of counterexample ===

Generating counter example took 0.040 seconds.



=== Property checking failed ===


=== Performance statistics ===

Compiling:
Compiling individual components took: 0.300 seconds
Building the transition relations took: 0.020 seconds
Sub-total (component+transition relation): 0.320 seconds
Compiling (loading+deriving all the relations) took: 0.530 seconds
Garbage_collection: 0.000 seconds
Memory: 535924 bytes
Nodes: 495; Abstract Edges: 1;

-- Detailed statistics --
Run time: 0.530 seconds;
System time: 0.020 seconds;
Real time: 4.196 seconds

Virtual memory in use: 535924 bytes; Virtual memory free: -535924 bytes
Program space: 142732 bytes
Global stack memory: 393192 bytes; Local stack memory: 0 bytes
Global stack in use: 763424 bytes; Global stack free: -461084 bytes
Local stack in use: 604 bytes; Local stack free: -604 bytes
Trail 200
Garbage_collection 0 times: 0.000 seconds; 0 bytes freed
Global stack shift 0 times; Local stack shift 3 times; in 0.000 seconds
Number of atoms: 6; Atom space in use: 216 bytes; free: -48 bytes
Atom Garbage_collection 0 times: 0.000 seconds; 0 bytes freed

Verification:
Building initial state MDG took 0.010 seconds
Computing reachable states took : 0.030 seconds
Misc took : 0.060 seconds
Sub-total (reachability analysis) : 0.090 seconds
Verification (rechability analysis + init states generation) : 0.100 seconds
Garbage_collection: 0.020 seconds
Memory: 68764 bytes
Nodes: 169; Abstract edges : 0



but I only need to copy aprt from it. so how can I copy it from prolog to another text file.


thanks

ghaith

RE: Problem with copy_stream_data

I don't quite understand, you need your Prolog program to write in a text file instead of writing to the screen? If this is the case, it's difficult to answer without having the Prolog code that generates this text.

If you are running the program from command line, you can also leave the original Prolog code as it is and instead redirect output to a file, like this:

shell_command_that_produces_output_text > file.txt

Instead of printing to the screen, the shell command will write its output to file 'file.txt'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close