in reply to Lisp vs. Perl Round 3: Operator Associativity and Manipulation
Not even golfed.#!/usr/bin/perl -w use strict; my $pat = '"%d %s %d is %d" if (%d %s %d == %d)'; matchIf($pat, 3, '+', 4, 7); matchIf($pat, 5, '*', 4, 20); matchIf($pat, 5, '%', 4, 20); matchIf($pat, 5, '-', 4, 20); sub matchIf { my ($pat, $x, $op, $y, $z) = @_; my $foo = sprintf($pat, $x, $op, $y, $z, $x, $op, $y, $z); print eval ($foo),"\n"; }
Not nearly as wacky as you made it out to be. BTW, I spent 3 semesters doing Artificial intelligence work with Lisp in college and I actually love working with it; But your arguement here just shows that either you didn't bother to learn the tool (Perl) well enough to do the job right, or you intentionally misrepresented things to serve your point.
And as a note: Most people do not consider the Lisp method of using Reverse Polish notation for conditionals and mathmatics particularly simple. Most people would understand "x op y = z" but only a programmer (or maybe a mathematician) could love "op op x y z".
Update Figured I would add that the development time on this was ~5 minutes.
Update And just a couple more showed that we can do this....
To make the ordering configurable as well.#!/usr/bin/perl -w use strict; my $pat = '"%d %s %d is %d" if (%d %s %d == %d)'; my $order = '[$_[0], $_[1], $_[2], $_[3]]'; matchIf($pat, $order, 3, '+', 4, 7); matchIf($pat, $order, 5, '*', 4, 20); matchIf($pat, $order, 5, '%', 4, 20); matchIf($pat, $order, 5, '-', 4, 20); sub matchIf { my ($pat, $order) = (shift, shift); print eval sprintf($pat, @{eval $order}, @{eval $order}), "\n" +; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Lisp vs. Perl Round 3: Operator Associativity and Manipulation
by hding (Chaplain) on Jun 08, 2001 at 22:45 UTC | |
Re: Re: Lisp vs. Perl Round 3: Operator Associativity and Manipulation
by princepawn (Parson) on Jun 08, 2001 at 23:33 UTC | |
by Sifmole (Chaplain) on Jun 08, 2001 at 23:54 UTC | |
by hding (Chaplain) on Jun 09, 2001 at 02:23 UTC |