 Keep It Simple, Stupid PerlMonks

pissed off about functional programming

by mstone (Deacon)
 on Apr 24, 2005 at 11:46 UTC Need Help??

^f(x) ::= x f(x)

0   - f(x)
1   - x f(x)
2   - x x f(x)
3   - x x x f(x)
...

^g(x) ::= x x

g(f(x))

0   - g(f(x))
1   - f(x) f(x)
2   - x f(x) x f(x)
3   - x x f(x) x x f(x)
...

my \$x = 3;
my \$y = 3;
...
if (3 == \$y) {                  # substitutability fails
print "\$x equals \$y.\n";
}

my \$x = 3;      # start frame of reference for variable \$x
# start frame of reference for value \$x==3
...
# end frame of reference for variable \$x
# end frame of reference for value \$y==3
# end frame of reference for variable \$y

p1  ::= 'the morning star' equals 'the planet venus'
p2  ::= 'the evening star' equals 'the planet venus'
...
the same thing, equal each other'

=>  ::= an operator which means 'this rule produces this result'

p1 (+) p2 => p3
p1 (+) p3 => p2
p2 (+) p3 => p1

j1  ::= john knows 'the morning star' equals 'the planet venus'
j2  ::= john knows 'the evening star' equals 'the planet venus'
j3  ::= john knows 'the morning star' equals 'the evening star'

j1 (+) p2 => j3
p1 (+) j2 => j3
...
p1 (+) j3 => j2
j2 (+) p3 => j1
p2 (+) j3 => j1

sub outer_1 {
local (\$x) = 1;
...
my \$y = shift;
return (\$x + \$y);
}

sub equals {
my (\$str, \$num) = @_;
...
return 0;
}
}

my \$inc  = sub { return (\$_ + 1) };
my \$dec  = sub { return (\$_ - 1) };
...
----

output == '0 1 2 3 2 3 2 1 2 0 1 2 3'

sub apply {
my (\$val, \$func, @etc) = @_;
...
return (\$func->(\$val));
}
}

my @x = (\$inc, \$inc, \$inc);
my @y = (\$inc, \$inc, \$inc);
...
printf "%d equals %d.\n", counter (@x), counter (@y);
}
}

Create A New User
Node Status?
node history
Node Type: perlmeditation [id://450922]
Approved by Joost
Front-paged by ghenry
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2019-10-17 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2019 the site I miss most is:

Results (42 votes). Check out past polls.

Notices?