[stack] FL versus Joy
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
Here's a quick example to support the claim I've made previously that having all terms denote functions throughout the reduction process greatly simplifies things. Here's the Joy version: PRIMITIVES: [X] dup == [X] [X] [X] i == X [X] [Y] dip == Y [X] USER-DEFINED: twice = dup dip i square = dup mul double = dup add EVALUATE: 5 [sq] twice double 5 [sq] dup dip i double 5 [sq] [sq] dip i double 5 sq [sq] i double 5 dup mul [sq] i double 5 5 mul [sq] i double 25 [sq] i double 25 sq double 25 dup mul double 25 25 mul double 625 double 625 dup add 625 625 add 1250 And here's the FL version: PRIMITIVES: (C:f):x:y == (f . [~x, id]):y == f:<x:y> USER-DEFINED: twice = C:(apply.[a, apply]) square = mul . [id, id] double = add . [id, id] EVALUATE: (double . twice:sq) : 5 (double . (C:(apply . [a, apply])):sq) : 5 (double . apply . [a, apply] . [~sq, id]) : 5 (double . apply . [a, apply]) : [~sq, id] : 5 (double . apply . [a, apply]) : <~sq:5, id:5> (double . apply . [a, apply]) : <sq, id:5> (double . apply . [a, apply]) : <sq, 5> (double . apply) : [a, apply] : <sq, 5> (double . apply) : <a:<sq, 5>, apply:<sq, 5>> (double . apply) : <sq, apply:<sq, 5>> (double . apply) : <sq, apply:<mul . [id, id], 5>> (double . apply) : <sq, (mul . [id, id]) : 5> (double . apply) : <sq, mul : <id:5, id:5>> (double . apply) : <sq, mul : <5, id:5>> (double . apply) : <sq, mul : <5, 5>> (double . apply) : <sq, 25> double : sq : 25 double : ((mul . [id, id]) : 25) double : mul : [id, id] : 25 double : mul : <id:25, id:25> double : mul : <25, id:25> double : mul : <25, 25> double : 625 (add . [id, id]) : 625 add : [id, id] : 625 add : <id:625, id:625> add : <625, id:625> add : <625, 625> 1250 Forgive me for not explaining how FL works again. If you're interested, see this paper: http://www.cs.berkeley.edu/~aiken/ftp/FL.ps - John