[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
error in dynamic compiled code?
From: |
Erick Alphonse |
Subject: |
error in dynamic compiled code? |
Date: |
Fri, 22 Oct 2004 17:20:32 +0200 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040923) |
Hello,
The behaviour of my program changes whenever a predicate definition is
defined as dynamic or not. This occurs only when the program is
compiled, not interpreted.
The source code is given below, and further below is given the trace of
the compiled program. It seems that the cut in the first predicate
definition of code_type/2 is not applied. It is compiled with the latest
unstable gprolog released.
086$ uname -a
Linux mig195 2.6.3-7mdkenterprise #1 SMP Wed Mar 17 15:00:05 CET 2004
i686 Intel(R) Pentium(R) 4 CPU 2.40GHz unknown GNU/Linux
1114$ gplc --no-top-level top.pl
1115$ ./top
word([119,111,114,100])
% normal behaviour
% now, the dynamic directive is uncommented (see code below)
1116$ gplc --no-top-level top.pl
1117$ ./top
word([119,111,114,100])
punct([119])
%%%%%%%%%%%
:- initialization(top).
%:- dynamic(code_type/2).
top :-
open_input_atom_stream('word',S),
repeat,
read_code_list_token(S,T),
( T \== end_of_file ->
write(T),nl,
fail
;
true
),
!,
close_input_atom_stream(S).
% read_code_list_token(+Stream,-Token)
% lit un Token a partir du flux Stream
read_code_list_token(Stream,Token) :-
get_code(Stream,Code),
( Code == -1 ->
Token = end_of_file
;
code_type(Code,Type),
aux_read_code_list_token(Type,Code,Stream,Token)
).
aux_read_code_list_token(punct,C,_,punct([C])).
aux_read_code_list_token(letter,C,Stream,word([C|Cs])) :-
word(Stream,Cs).
word(Stream,[Code|Cs]) :-
peek_code(Stream,Code),
code_type(Code,letter),
!,
get_code(Stream,_),
word(Stream,Cs).
word(_,[]).
%%
%% Typage des caracteres (codes ASCII)
%%
% code_type(+Code,-Type)
code_type(Code,letter) :-
(
97 =< Code,
Code =< 122
;
65 =< Code,
Code =< 90
),
!.
code_type(_,punct).
%%%%%%%%%%%
% trace
1126$ gplc top.pl
1127$ ./top
word([119,111,114,100])
punct([119])
GNU Prolog 1.2.18
By Daniel Diaz
Copyright (C) 1999-2004 Daniel Diaz
| ?- trace.
The debugger will first creep -- showing everything (trace)
yes
{trace}
| ?- top.
1 1 Call: top ?
2 2 Call: code_type(119,_42) ?
3 3 Call: '$code_type/2_$aux1'(119,_42) ?
3 3 Exit: '$code_type/2_$aux1'(119,letter) ?
2 2 Exit: code_type(119,letter) ?
4 2 Call: code_type(111,letter) ?
5 3 Call: '$code_type/2_$aux1'(111,letter) ?
5 3 Exit: '$code_type/2_$aux1'(111,letter) ?
4 2 Exit: code_type(111,letter) ?
6 2 Call: code_type(114,letter) ?
7 3 Call: '$code_type/2_$aux1'(114,letter) ?
7 3 Exit: '$code_type/2_$aux1'(114,letter) ?
6 2 Exit: code_type(114,letter) ?
8 2 Call: code_type(100,letter) ?
9 3 Call: '$code_type/2_$aux1'(100,letter) ?
9 3 Exit: '$code_type/2_$aux1'(100,letter) ?
8 2 Exit: code_type(100,letter) ?
10 2 Call: code_type(-1,letter) ?
11 3 Call: '$code_type/2_$aux1'(-1,letter) ?
11 3 Fail: '$code_type/2_$aux1'(-1,letter) ?
11 3 Call: '$code_type/2_$aux2'(-1,letter) ?
11 3 Fail: '$code_type/2_$aux2'(-1,letter) ?
10 2 Fail: code_type(-1,letter) ?
word([119,111,114,100])
2 2 Redo: code_type(119,letter) ?
3 3 Call: '$code_type/2_$aux2'(119,_42) ?
3 3 Exit: '$code_type/2_$aux2'(119,punct) ?
2 2 Exit: code_type(119,punct) ?
punct([119])
1 1 Exit: top ?
(5 ms) yes
{trace}
| ?-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- error in dynamic compiled code?,
Erick Alphonse <=