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" +; }
In reply to Re: Lisp vs. Perl Round 3: Operator Associativity and Manipulation
by Sifmole
in thread Lisp vs. Perl Round 3: Operator Associativity and Manipulation
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |