File: whereis.pl

package info (click to toggle)
swi-prolog 3.1.0-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 8,772 kB
  • ctags: 12,869
  • sloc: ansic: 43,657; perl: 12,577; lisp: 4,359; sh: 1,534; makefile: 798; awk: 14
file content (41 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*  $Id: whereis.pl,v 1.2 1994/11/22 15:10:29 jan Exp $

    Copyright (c) 1990 Jan Wielemaker. All rights reserved.
    jan@swi.psy.uva.nl

    Purpose: Find predicates
*/

:- module(whereis,
	[ whereis/1
	]).

:- module_transparent
	whereis/1.

%	whereis(+Spec)
%	Find predicate definition.

whereis(Spec) :-
	'$find_predicate'(Spec, List),
	member(Head, List),
	'$predicate_name'(Head, PredName),
	(   '$defined_predicate'(Head)
	->  predicate_property(Head, file(File)),
	    predicate_property(Head, line_count(Line)),
	    format('~t~8|~w is in ~w:~d~n', [PredName, File, Line])
	;   '$strip_module'(Head, Module, H),
	    functor(H, Name, Arity),
	    '$find_library'(Module, Name, Arity, _, Lib),
	    libname(Lib, LibName),
	    format('~t~8|~w is in ~w~n', [PredName, LibName])
	),
	fail ; true.

libname(File, library(LibName)) :-
	findall(LN, ( library_directory(X),
		      concat(X, LN, File)),
		[LN0]),
	(concat('/', LN1, LN0) -> true ; LN1 = LN0),
	(concat(LibName, '.pl', LN1) -> true ; LibName = LN1).