Prolog within Perl? 
Author Message
 Prolog within Perl?

I wonder if anyone has written a simple rule based processor
similar to Prolog that would run within Perl.  I'm having
such a good time using all of Perl's powerful features,
but occasionally, I'd like to be able to run some
pieces that work like non-deterministic forward or backward
chaining engines.

Anyone done such a thing using Perl?



Sun, 05 Mar 1995 05:51:00 GMT  
 Prolog within Perl?

   I wonder if anyone has written a simple rule based processor
   similar to Prolog that would run within Perl.  I'm having
   such a good time using all of Perl's powerful features,
   but occasionally, I'd like to be able to run some
   pieces that work like non-deterministic forward or backward
   chaining engines.

I routinely run Prolog on the ends of a pipe from Perl.  I find this
works extremely well, and lets me use Prolog for what it does best,
but not trying to force it to do what Perl is much better suited for.

I just wish that Prolog and Perl didn't both claim the ".pl" file
extension.

--
John Dowding



Tue, 07 Mar 1995 04:47:04 GMT  
 Prolog within Perl?
: I just wish that Prolog and Perl didn't both claim the ".pl" file
: extension.

Perl doesn't claim ".pl" except for library files (and that only by
convention).  The "l" there is for "library", not for "language" or
"lister".  People who add ".pl" to ordinary Perl executables are
confusing the issue.  How many shell scripts have ".sh" on them,
anyway?

Larry



Wed, 08 Mar 1995 09:45:23 GMT  
 Prolog within Perl?

Quote:

> People who add ".pl" to ordinary Perl executables are confusing the issue.

Or we're underpriveleged MS-DOS users, who have seen enough light to use
4dos and declare .pl as an executable extension.  
--
Roy M. Silvernail --    [my machine ] "Sometimes, you're the windshield....




Thu, 09 Mar 1995 02:46:20 GMT  
 Prolog within Perl?

|>
|>> People who add ".pl" to ordinary Perl executables are confusing the issue.
|>
|>Or we're underpriveleged MS-DOS users, who have seen enough light to use
|>4dos and declare .pl as an executable extension.  

Or we're emacs users who need to use _some_ convention to tell emacs what
mode to set up for the file.

Lezz "Just another Emacs hacker" Giles



Sat, 11 Mar 1995 01:19:59 GMT  
 Prolog within Perl?


Quote:


>|>
>|>> People who add ".pl" to ordinary Perl executables are confusing the issue.
>|>
>|>Or we're underpriveleged MS-DOS users, who have seen enough light to use
>|>4dos and declare .pl as an executable extension.  

>Or we're emacs users who need to use _some_ convention to tell emacs what
>mode to set up for the file.

emacs is much smarter than that. i have taught mine to automagically sniff
out perl files by scanning for "bin/perl" in the first 100 bytes like this..
(a snippet from my .emacs file) -- i always start my perlies with #!/usr/local/bin/perl

;;; find-file-hooks is a list of functions ...
(setq find-file-hooks '(my-find-file-hook))
(defun my-find-file-hook ()
  "Runs with each new file found"

  ;; (message (concat "hello from the hook: " (buffer-file-name)))
  ;; (sit-for 2)

  (save-excursion
    (save-restriction

      ;; is this a perl file ??
      (if (search-forward "bin/perl" 100 t)
          (perl-mode))

      ;; can you find a script: line??
      ;; setup for sdsbuild then..
      ;; ...stuff deleted...

      )
    )
  )

hope that helps,
paul

--

Paul Kent (SQL r&d)                   " nothing ventured, nothing disclaimed "



Sat, 11 Mar 1995 04:35:46 GMT  
 Prolog within Perl?



   >|>
   >|>> People who add ".pl" to ordinary Perl executables are confusing the issue.
   >|>
   >|>Or we're underpriveleged MS-DOS users, who have seen enough light to use
   >|>4dos and declare .pl as an executable extension.  
   >
   >Or we're emacs users who need to use _some_ convention to tell emacs what
   >mode to set up for the file.

Can do without suffixes at all.  Append following to script ...

#Local Variables:
#mode: perl
#End:

--

...!uunet!ascent!paul



Sat, 11 Mar 1995 22:51:15 GMT  
 Prolog within Perl?

Quote:
(Paul Foley) writes:



      >Or we're emacs users who need to use _some_ convention to tell
      >emacs what mode to set up for the file.

   Can do without suffixes at all.  Append following to script ...

   #Local Variables:
   #mode: perl
   #End:

Suffixes strike me as messy because I don't *want* to have to type
``cmd.pl'' (or ``cmd.csh'', etc.) instead of cmd.  Local variables
work, but they mean that we Emacs users have to go out and modify
every shell script in the world.  So I came up with the following
hack.  Been using it for nearly a year now with no problems.

;;; Scripts to be automatically run by shells usually lack extensions;
;;; the following code parses the #! magic at the start of the script
;;; instead.  As written, this overrides auto-mode-alist; that could
;;; be changed by having parse-script-magic check for Fundamental mode
;;; first.

(setq script-magic-alist '(("^#!.*perl"           . perl-mode)
                           ("^#!"         . unix-script-mode)))
(defun parse-script-magic ()
  (let ((mode (save-excursion
                (goto-char (point-min))
                (let ((codes script-magic-alist))
                  (catch 'found
                    (while codes
                      (let ((key  (car (car codes)))
                            (mode (cdr (car codes))))
                        (if (looking-at key)
                            (throw 'found mode)))
                      (setq codes (cdr codes)))
                    nil)))))
    (if mode (funcall mode))))

(setq find-file-hooks (cons 'parse-script-magic find-file-hooks))
--
Dan L. Pierson          Digital Equipment Corporation



Mon, 13 Mar 1995 01:35:28 GMT  
 Prolog within Perl?

Quote:

>(Paul Foley) writes:


>      >Or we're emacs users who need to use _some_ convention to tell
>      >emacs what mode to set up for the file.

>   Can do without suffixes at all.  Append following to script ...

>   #Local Variables:
>   #mode: perl
>   #End:

> .... find-file-hooks stuff deleted...

Or you can use as the first line

        #!/usr/bin/perl -- # -*- Perl -*-



Mon, 13 Mar 1995 05:54:58 GMT  
 Prolog within Perl?
 dan> (setq script-magic-alist '(("^#!.*perl"          . perl-mode)
 dan>                           ("^#!"         . unix-script-mode)))
 dan> (defun parse-script-magic ()
 dan> ...
 dan> (setq find-file-hooks (cons 'parse-script-magic find-file-hooks))

My hack looks like this...I use the auto-mode-alist to select a
'scan-for-mode' function that can have a little more logic in it. It doesn't
handle the case of an unknown file with dots in the name (I only trigger the
scan-for-mode function for filenames without dots). I like the idea of putting
it on the find-file-hooks, so it doesn't rely on the filename at all if need
be. Here it is anyways.

(defun sab-scan-for-mode ()
  (save-excursion
    (cond
     ((and (goto-char (point-min))
           (looking-at "#![ \t]*[^ \t]+/perl"))
      (perl-mode))
     ((and (goto-char (point-min))
           (looking-at "%!PS-Adobe"))
      (postscript-mode))
     ((and (goto-char (point-min))
           (looking-at ";; Database file written by EDB"))
      (require 'database)
      (db-this-buffer))
     )
    )
  )

(setq auto-mode-alist
      (append '(
                ("\\.pl$" . perl-mode)
                ("\\.gwm$" . lisp-mode)
                ("\\.pas$" . Pascal-mode) ("\\.p$" . pascal-mode)
                ("\\.ftn$" . fortran-mode)
                ("\\.outl$" . outline-mode) ("\\.otl$" . outline-mode)
                ("\\.awk$" . awk-mode) ("\\.nawk$" . awk-mode)
                ("\\.[eE]?[pP][sS]$" . postscript-mode)
                ("ps\\..*\\.in$" . postscript-mode)
                ("^ps\\.out\\." . postscript-mode)
                ("^[^.]*$" . sab-scan-for-mode)
                ("/[^./]*$" . sab-scan-for-mode))
              auto-mode-alist)
      )

--
Scott Blachowicz    Ph: 206/283-8802x240      USPS:  Statistical Sciences, Inc
                                                      1700 Westlake Ave N #500




Mon, 13 Mar 1995 10:43:43 GMT  
 Prolog within Perl?

Quote:




>   >|>
>   >|>> People who add ".pl" to ordinary Perl executables are confusing the issue.
>   >|>
>   >|>Or we're underpriveleged MS-DOS users, who have seen enough light to use
>   >|>4dos and declare .pl as an executable extension.  

>   >Or we're emacs users who need to use _some_ convention to tell emacs what
>   >mode to set up for the file.

>Can do without suffixes at all.  Append following to script ...

>#Local Variables:
>#mode: perl
>#End:

Or do this at the beginning:

        #!/usr/local/bin/perl -- # -*- perl -*-

From the GNU emacs manual (18.57):

  You can specify which major mode should be used for editing a certain
file by a special sort of text in the first nonblank line of the
file.  The mode name should appear in this line both preceded and
followed by `-*-'.  Other text may appear on the line as well.

Jeff

--

Advanced Micro Devices, M/S 45  |---------------------------------------
PO Box 3453                     |  The above opionions are mine,
Sunnyvale, Ca 94088             |  not AMD's.



Mon, 13 Mar 1995 03:35:16 GMT  
 
 [ 21 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Prolog interpreter in Perl?

2. Calling prolog from perl

3. Perl and Prolog

4. Perl and prolog

5. Perl and Prolog

6. Perl and Prolog

7. Piping fails within a subshell within Perl?

8. tkperl - finding prolog.ps and font name formats

9. Prolog module available in alpha

10. ANNOUNCE: Language::Prolog::Yaswi

11. Escaping a $ within a variable within a grep...

12. Newbie: best way to call perl scripts from within a perl script

 

 
Powered by phpBB® Forum Software