Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday May 26, 2005
08:15 PM

Various AI::Prolog thoughts

[ #24894 ]

I just had an epiphany about how to make the AI::Prolog parser work much better. It would be cleaner and faster and probably allow for proper operators. The latter would allow me to do this:

X is Y + Z * 2.

Instead of:

is(X, plus(Y, mult(Z, 2))).

The latter, of course, is just plain ugly. I've also figured out a better way to handle precedence which might allow me to change the Prolog syntax at runtime (op/3 allows this in normal Prolog).

The only problem with my new idea is that I don't have time :(

In other news, Randal found a nifty solution to a weird problem. Someone wanted to count all instances of a string in another string, even if they were overlapping. So 'AA' can be found in 'AAAA' 3 times. Randal's solution, though Perl, is straight from Prolog:

sub match_count {
  my ($string, $pattern) = @_;
  my $n = 0;
  $string =~ /$pattern(?{ $n++ })(?!)/;
  return $n;

Neat, eh?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • The latter, of course, is just plain ugly.

    What are you talking about? </lisp-guy>

    In other news, Randal found a nifty solution to a weird problem.

    That’s straight from Mastering Regular Expressions, basically. :-)

    • It might be from MRE (Meal, Ready to Eat?), but Randal did give credit specifically to Prolog :) In this case, it's a very common Prolog idiom to force something to fail in order to backtrack and cover all solutions:


      report :-
        print('People:'), nl,
        person(X), print(X), nl, # fail forces this to be resatisfied

      Thus learning Prolog well enough makes solutions like Randal's seem natural.