Loading ...
Sorry, an error occurred while loading the content.

182Re: [extremeperl] Logic Programming in Perl -- Just say no

Expand Messages
  • Rob Nagler
    Mar 30, 2005
      Curtis Poe writes:
      > 1. hello: times
      > 2. (times > 100)
      > 3. ifTrue: [ Transcript show: 'You will get bored!']
      > 4. ifFalse: [1 to: times do: [:i | (Transcript show: 'Hello World') cr]]

      Code! Notice the bug? Here's a refactoring that eliminates
      redundancy and the bug:

      hello: times
      (times > 100)
      ifTrue: [self print: 'You will get bored!']
      ifFalse: [times timesRepeat: [self print: 'Hello World')]];

      print: s
      Transcript show: s; cr

      I am not a Smalltalker, but I suspect there's a way to do this in
      Smalltalk:

      sub hello {
      my($times) = @_;
      print(STDOUT
      map("$_\n",
      $times > 100 ? 'You will get bored!'
      : map('Hello World', 1 .. $times),
      ),
      );
      }

      > My code currently only touches the full power of logic programming.
      > It doesn't allow modules, there are no definite clause grammars (yet)
      > and operator support is limited. What does most of that mean? Who
      > knows?

      But what's it for? What problem are you trying to solve?

      Rob
    • Show all 9 messages in this topic