Perl: the Markov chain saw PerlMonks

### eval unexpected return value '1'

 on Mar 29, 2008 at 08:42 UTC Need Help??

ady has asked for the wisdom of the Perl Monks concerning the following question:

Guys & gulls, --
I'm playing with The unknowable (hereby recommended :) and on the way casting the LISP programs to Perl.

In the statement (from the Gödel proof):
I expect eval to return :
\$is_unprovable('\$value_of('&\$g('&\$g')')')
-- but I get a '1'.

How come?
```#!/usr/bin/perl -w
use strict;
use warnings;

# ====================================================================
+==========
# Fixpoint
# f(x): x -> (('x)('x))
# In LISP:
# define (f x)
#    let y [be] cons "' cons x nil [y is ('x) ]
#    [return] cons y cons y nil    [return (('x)('x))]

# In Perl:
my \$f = sub { my \$x = \$_[0]; return "\$x('\$x')"; };

print &\$f('x'), "\n";
print &\$f('&\$f'), "\n";
print eval &\$f('&\$f'), "\n";
print eval eval eval eval eval &\$f('&\$f'), "\n";
print '&\$f(\'&\$f\')' eq eval eval eval eval eval &\$f('&\$f'), "\n";

# Run :
# x('x')
# &\$f('&\$f')
# &\$f('&\$f')
# &\$f('&\$f')
# 1

# ====================================================================
+==========
# Gödel
# g(x): x -> (is-unprovable (value-of (('x)('x))))]
# In LISP:
# define (g x)
#   let (L x y) cons x cons y nil  [Makes x and y into list]
#   (L is-unprovable
#   (L value-of (L (L "' x) (L "' x))))

# In Perl:
my \$is_unprovable = '\$is_unprovable';
my \$value_of      = '\$value_of';
sub cadr { return (\$_[0]) =~ /\(\'(.*)\'\)/; };

my \$L = sub {  my (\$x, \$y) = @_; return "\$x('\$y')"; };
my \$g = sub {  my \$x = \$_[0];
&\$L(\$is_unprovable, &\$L(\$value_of, "\$x('\$x')")); };

print '&\$g(\'x\')   -> ', &\$g('x'), "\n";
print '&\$g(\'&\$g\') -> ', &\$g('&\$g'), "\n";
### \$is_unprovable('\$value_o
+f('&\$g('&\$g')')')

# Run :
# &\$g('x')   -> \$is_unprovable('\$value_of('x('x')')')
# &\$g('&\$g') -> \$is_unprovable('\$value_of('&\$g('&\$g')')')
# &\$g('&\$g')
# 1                                       ### but it returns 1 ???

Best regards,
Allan dystrup

Replies are listed 'Best First'.
Re: eval unexpected return value '1'
by shmem (Chancellor) on Mar 29, 2008 at 09:13 UTC
How come?

That's because your sub cadr returns 1 upon match, not the capture. Try

```sub cadr { \$_[0] =~ /\(\'(.*)\'\)/ and return \$1 }

--shmem

```_(\$_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
/\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.(\$e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;\$e.e && print}```
Right you are !
(I thought that was the gerenal area where the dog was burried, but couldn't quite locate it...)
Tnx! Allan

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://677187]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2022-08-12 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?