Whee-hee! Thank you Claude -- I've always wanted a constructive proof that Pd is Turing-complete!
marmosets, Bryan
On 2006-09-28 18:25:02, Claude Heiland-Allen claudiusmaximus@goto10.org appears to have written:
Hi everybody,
Remember those long discussions about whether Pd is a programming language or (an inferior) something else?
Well, to settle the matter, I made a brainf*ck[1] interpreter in vanilla Pd using no externals[2].
Now you can be sure that you can compute anything computable[3] using your favourite multimedia tool!
As Pd's string handling sucks, output is a printout of the decimal value of each character.
Keyboard input is through [key], so you enter characters fairly naturally (wait for the yellow signal before you type each character). There is no way to indicate end-of-file.
[1] http://en.wikipedia.org/wiki/Brainfuck
[2] As Pd's string handling sucks, you need to convert your .bf source code into decimal form before loading it. A simple C program "decdump.c" to do this is attached.
[3] Provided it can be computed within the memory available, which in this interpreter is 1,000,000 cells each being an integer from 0 to 255 inclusive.
Claude
#N canvas 72 113 437 157 10; #N canvas 369 69 310 176 1008-bfi 0; #N canvas 154 456 884 419 1008-guts 0; #X obj 21 16 table $0-code; #X obj 21 36 table $0-data; #N canvas 0 0 631 385 1008-load 0; #N canvas 219 223 331 317 1008-wc-l 0; #X obj 20 18 inlet; #X text 70 18 <symbol filename>; #X obj 20 267 outlet; #X text 77 267 <float lines>; #X msg 58 91 read $1 cr , rewind; #X obj 58 141 textfile; #X obj 20 237 f; #X msg 103 172 0; #X obj 20 56 t b b a b; #X obj 39 112 until; #X obj 58 161 bang; #X obj 58 200 f; #X obj 102 200 + 1; #X connect 0 0 8 0; #X connect 4 0 5 0; #X connect 5 0 10 0; #X connect 5 1 9 1; #X connect 6 0 2 0; #X connect 7 0 6 1; #X connect 7 0 11 1; #X connect 8 0 6 0; #X connect 8 1 9 0; #X connect 8 2 4 0; #X connect 8 3 7 0; #X connect 9 0 5 0; #X connect 10 0 11 0; #X connect 11 0 12 0; #X connect 12 0 11 1; #X connect 12 0 6 1; #X restore 97 178 pd $0-wc-l; #X obj 24 44 openpanel; #X obj 46 156 t a a; #X obj 97 199 t f f; #X obj 46 221 pack s f; #X obj 24 22 r $0-load-s; #X obj 46 270 s $0-code; #X obj 24 65 t b a b; #X obj 103 149 s $0-run-r; #X msg 46 246 const 0 , resize $2 , read $1; #X obj 24 355 s $0-data; #X msg 24 333 resize $1 , const 0; #X obj 24 292 f 1e+06; #X obj 24 312 t f f; #X obj 143 200 s $0-code-size; #X obj 70 312 s $0-data-size; #X obj 225 98 0; #X obj 183 149 s $0-pause; #X obj 262 149 s $0-cp; #X obj 319 149 s $0-dp; #X connect 0 0 3 0; #X connect 1 0 7 0; #X connect 2 0 4 0; #X connect 2 1 0 0; #X connect 3 0 4 1; #X connect 3 1 14 0; #X connect 4 0 9 0; #X connect 5 0 1 0; #X connect 7 0 12 0; #X connect 7 1 2 0; #X connect 7 2 16 0; #X connect 9 0 6 0; #X connect 11 0 10 0; #X connect 12 0 13 0; #X connect 13 0 11 0; #X connect 13 1 15 0; #X connect 16 0 8 0; #X connect 16 0 17 0; #X connect 16 0 18 0; #X connect 16 0 19 0; #X restore 21 67 pd $0-load; #N canvas 0 0 303 203 1008-inc 0; #X obj 15 17 inlet; #X obj 45 57 f; #X obj 15 37 t b b; #X obj 45 97 tabread $0-data; #X obj 45 117 + 1; #X obj 45 137 mod 256; #X obj 45 157 tabwrite $0-data; #X obj 45 77 t f f; #X obj 15 177 outlet; #X obj 61 37 r $0-dp; #X connect 0 0 2 0; #X connect 1 0 7 0; #X connect 2 0 8 0; #X connect 2 1 1 0; #X connect 3 0 4 0; #X connect 4 0 5 0; #X connect 5 0 6 0; #X connect 7 0 3 0; #X connect 7 1 6 1; #X connect 9 0 1 1; #X restore 211 220 pd $0-inc; #N canvas 0 0 303 203 1008-dec 0; #X obj 15 17 inlet; #X obj 45 57 f; #X obj 15 37 t b b; #X obj 45 97 tabread $0-data; #X obj 45 137 mod 256; #X obj 45 157 tabwrite $0-data; #X obj 45 77 t f f; #X obj 15 177 outlet; #X obj 45 117 - 1; #X obj 61 37 r $0-dp; #X connect 0 0 2 0; #X connect 1 0 6 0; #X connect 2 0 7 0; #X connect 2 1 1 0; #X connect 3 0 8 0; #X connect 4 0 5 0; #X connect 6 0 3 0; #X connect 6 1 5 1; #X connect 8 0 4 0; #X connect 9 0 1 1; #X restore 282 220 pd $0-dec; #N canvas 12 396 300 301 1008-next 0; #X obj 17 17 inlet; #X obj 17 97 + 1; #X obj 17 117 t f f; #X obj 17 77 f; #X obj 17 257 s $0-cp; #X obj 33 57 r $0-cp; #X obj 47 137 >=; #X obj 63 117 r $0-code-size; #X obj 47 157 select 1; #X obj 47 237 s $0-run-r; #X msg 47 217 0; #X obj 47 177 t b b; #X obj 77 217 print bfi; #X msg 77 197 STOP; #X obj 17 37 bang; #X connect 0 0 14 0; #X connect 1 0 2 0; #X connect 2 0 4 0; #X connect 2 1 6 0; #X connect 3 0 1 0; #X connect 5 0 3 1; #X connect 6 0 8 0; #X connect 7 0 6 1; #X connect 8 0 11 0; #X connect 10 0 9 0; #X connect 11 0 10 0; #X connect 11 1 13 0; #X connect 13 0 12 0; #X connect 14 0 3 0; #X restore 397 328 pd $0-next; #N canvas 0 0 309 301 1008-left 0; #X obj 17 17 inlet; #X obj 17 77 f; #X obj 61 157 select 1; #X obj 61 237 s $0-run-r; #X msg 61 217 0; #X obj 61 177 t b b; #X obj 91 217 print bfi; #X obj 17 37 bang; #X obj 33 57 r $0-dp; #X obj 61 137 < 0; #X obj 39 257 s $0-dp; #X obj 17 117 t b f f; #X msg 91 197 data pointer underflow , ABORT; #X obj 17 277 outlet; #X obj 17 97 - 1; #X connect 0 0 7 0; #X connect 1 0 14 0; #X connect 2 0 5 0; #X connect 4 0 3 0; #X connect 5 0 4 0; #X connect 5 1 12 0; #X connect 7 0 1 0; #X connect 8 0 1 1; #X connect 9 0 2 0; #X connect 11 0 13 0; #X connect 11 1 10 0; #X connect 11 2 9 0; #X connect 12 0 6 0; #X connect 14 0 11 0; #X restore 42 219 pd $0-left; #N canvas 0 0 309 301 1008-right 0; #X obj 17 17 inlet; #X obj 17 97 + 1; #X obj 17 77 f; #X obj 61 157 select 1; #X obj 61 237 s $0-run-r; #X msg 61 217 0; #X obj 61 177 t b b; #X obj 91 217 print bfi; #X obj 17 37 bang; #X obj 33 57 r $0-dp; #X obj 39 257 s $0-dp; #X obj 17 117 t b f f; #X obj 17 277 outlet; #X obj 61 137 >=; #X obj 77 117 r $0-data-size; #X msg 91 197 data pointer overflow , ABORT; #X connect 0 0 8 0; #X connect 1 0 11 0; #X connect 2 0 1 0; #X connect 3 0 6 0; #X connect 5 0 4 0; #X connect 6 0 5 0; #X connect 6 1 15 0; #X connect 8 0 2 0; #X connect 9 0 2 1; #X connect 11 0 12 0; #X connect 11 1 10 0; #X connect 11 2 13 0; #X connect 13 0 3 0; #X connect 14 0 13 1; #X connect 15 0 7 0; #X restore 122 219 pd $0-right; #N canvas 0 0 341 700 1008-skip 0; #X obj 17 20 inlet; #X obj 39 181 until; #X obj 39 241 + 1; #X obj 39 221 f; #X obj 39 613 s $0-cp; #X obj 69 493 >=; #X obj 85 473 r $0-code-size; #X obj 69 513 select 1; #X obj 69 593 s $0-run-r; #X msg 69 573 0; #X obj 101 573 print bfi; #X msg 101 553 code pointer overflow , ABORT; #X obj 69 533 t b b b; #X obj 55 201 r $0-cp; #X obj 39 261 t f f; #X obj 39 473 t f f; #X obj 143 303 tabread $0-code; #X obj 61 81 s $0-skip-depth; #X obj 143 373 f; #X obj 198 343 r $0-skip-depth; #X obj 143 423 select 0; #X obj 182 373 f; #X obj 182 393 - 1; #X obj 143 393 + 1; #X obj 194 443 s $0-skip-depth; #X obj 39 121 f; #X obj 39 141 tabread $0-data; #X obj 39 161 select 0; #X obj 61 60 1; #X obj 55 101 r $0-dp; #X obj 143 323 select 91 93; #X obj 17 40 t b b b; #X obj 17 643 outlet; #X connect 0 0 31 0; #X connect 1 0 3 0; #X connect 2 0 14 0; #X connect 3 0 2 0; #X connect 5 0 7 0; #X connect 6 0 5 1; #X connect 7 0 12 0; #X connect 9 0 8 0; #X connect 11 0 10 0; #X connect 12 0 9 0; #X connect 12 1 11 0; #X connect 12 2 1 1; #X connect 13 0 3 1; #X connect 14 0 15 0; #X connect 14 1 16 0; #X connect 15 0 4 0; #X connect 15 1 5 0; #X connect 16 0 30 0; #X connect 18 0 23 0; #X connect 19 0 18 1; #X connect 19 0 21 1; #X connect 20 0 1 1; #X connect 20 1 24 0; #X connect 21 0 22 0; #X connect 22 0 20 0; #X connect 23 0 20 0; #X connect 25 0 26 0; #X connect 26 0 27 0; #X connect 27 0 1 0; #X connect 28 0 17 0; #X connect 29 0 25 1; #X connect 30 0 18 0; #X connect 30 1 21 0; #X connect 31 0 32 0; #X connect 31 1 25 0; #X connect 31 2 28 0; #X restore 360 220 pd $0-skip; #N canvas 0 0 341 700 1008-loop 0; #X obj 17 20 inlet; #X obj 39 211 until; #X obj 39 251 f; #X obj 39 613 s $0-cp; #X obj 69 513 select 1; #X obj 69 593 s $0-run-r; #X msg 69 573 0; #X obj 101 573 print bfi; #X obj 69 533 t b b b; #X obj 55 231 r $0-cp; #X obj 39 291 t f f; #X obj 39 473 t f f; #X obj 143 303 tabread $0-code; #X obj 143 373 f; #X obj 143 423 select 0; #X obj 182 373 f; #X obj 39 121 f; #X obj 39 141 tabread $0-data; #X obj 39 161 select 0; #X obj 61 60 1; #X obj 55 101 r $0-dp; #X obj 143 323 select 91 93; #X obj 17 40 t b b b; #X obj 17 643 outlet; #X obj 39 191 bang; #X obj 182 393 + 1; #X obj 143 393 - 1; #X obj 39 271 - 1; #X obj 69 493 < 0; #X msg 101 553 code pointer underflow , ABORT; #X obj 61 81 s $0-loop-depth; #X obj 198 343 r $0-loop-depth; #X obj 194 443 s $0-loop-depth; #X connect 0 0 22 0; #X connect 1 0 2 0; #X connect 2 0 27 0; #X connect 4 0 8 0; #X connect 6 0 5 0; #X connect 8 0 6 0; #X connect 8 1 29 0; #X connect 8 2 1 1; #X connect 9 0 2 1; #X connect 10 0 11 0; #X connect 10 1 12 0; #X connect 11 0 3 0; #X connect 11 1 28 0; #X connect 12 0 21 0; #X connect 13 0 26 0; #X connect 14 0 1 1; #X connect 14 1 32 0; #X connect 15 0 25 0; #X connect 16 0 17 0; #X connect 17 0 18 0; #X connect 18 1 24 0; #X connect 19 0 30 0; #X connect 20 0 16 1; #X connect 21 0 13 0; #X connect 21 1 15 0; #X connect 22 0 23 0; #X connect 22 1 16 0; #X connect 22 2 19 0; #X connect 24 0 1 0; #X connect 25 0 14 0; #X connect 26 0 14 0; #X connect 27 0 10 0; #X connect 28 0 4 0; #X connect 29 0 7 0; #X connect 31 0 13 1; #X connect 31 0 15 1; #X restore 440 220 pd $0-loop; #N canvas 0 0 343 291 1008-input 0; #X obj 55 18 inlet; #X obj 18 247 outlet; #X obj 55 42 t b b; #X obj 85 86 s $0-pause; #X obj 85 65 1; #X obj 18 108 spigot; #X obj 55 65 1; #X obj 18 83 key; #X obj 18 132 t b b f b; #X obj 129 111 0; #X obj 163 159 f; #X obj 179 136 r $0-dp; #X obj 37 221 s $0-pause; #X obj 37 200 0; #X obj 56 179 tabwrite $0-data; #X msg 180 64 color 15 22; #X obj 180 84 s $0-background-r; #X obj 134 242 s $0-background-r; #X msg 134 222 color 16 22; #X obj 141 200 loadbang; #X connect 0 0 2 0; #X connect 2 0 6 0; #X connect 2 1 4 0; #X connect 2 1 15 0; #X connect 4 0 3 0; #X connect 5 0 8 0; #X connect 6 0 5 1; #X connect 7 0 5 0; #X connect 8 0 1 0; #X connect 8 1 13 0; #X connect 8 1 18 0; #X connect 8 2 14 0; #X connect 8 3 9 0; #X connect 8 3 10 0; #X connect 9 0 5 1; #X connect 10 0 14 1; #X connect 11 0 10 1; #X connect 13 0 12 0; #X connect 15 0 16 0; #X connect 18 0 17 0; #X connect 19 0 18 0; #X restore 520 220 pd $0-input; #N canvas 0 0 324 165 1008-output 0; #X obj 19 15 inlet; #X obj 19 135 outlet; #X obj 19 35 t b b; #X obj 49 115 print bfi; #X msg 49 95 output $1; #X obj 49 55 f; #X obj 65 35 r $0-dp; #X obj 49 75 tabread $0-data; #X connect 0 0 2 0; #X connect 2 0 1 0; #X connect 2 1 5 0; #X connect 4 0 3 0; #X connect 5 0 7 0; #X connect 6 0 5 1; #X connect 7 0 4 0; #X restore 611 220 pd $0-output; #X obj 295 138 select 60 62 43 45 91 93 44 46 35; #N canvas 0 0 429 244 1008-debug 0; #X obj 13 13 inlet; #X obj 13 213 outlet; #X obj 35 73 f; #X obj 35 153 pack f f f; #X obj 70 93 f; #X obj 13 33 t b b b; #X obj 70 113 t f f; #X obj 100 133 tabread $0-data; #X obj 86 73 r $0-dp; #X obj 51 53 r $0-cp; #X msg 35 173 code pointer $1 , data pointer $2 , data contents $3; #X obj 35 193 print bfi; #X connect 0 0 5 0; #X connect 2 0 3 0; #X connect 3 0 10 0; #X connect 4 0 6 0; #X connect 5 0 1 0; #X connect 5 1 2 0; #X connect 5 2 4 0; #X connect 6 0 3 1; #X connect 6 1 7 0; #X connect 7 0 3 2; #X connect 8 0 4 1; #X connect 9 0 2 1; #X connect 10 0 11 0; #X restore 708 220 pd $0-debug; #N canvas 0 0 322 105 1008-nop 0; #X obj 13 9 inlet; #X obj 13 29 bang; #X obj 13 49 outlet; #X connect 0 0 1 0; #X connect 1 0 2 0; #X restore 793 220 pd $0-nop; #X obj 295 118 tabread $0-code; #X obj 295 98 f; #X obj 311 78 r $0-cp; #N canvas 331 388 318 296 1008-clock 0; #X obj 39 225 outlet; #X obj 39 205 spigot; #X obj 76 166 r $0-pause; #X obj 76 185 == 0; #X obj 39 26 r $0-run-s; #X obj 97 46 r $0-speed-s; #X obj 97 126 pow; #X obj 97 106 swap 2; #X obj 97 86 -; #X obj 97 66 swap 7; #X obj 39 146 metro 128; #X connect 1 0 0 0; #X connect 2 0 3 0; #X connect 3 0 1 1; #X connect 4 0 10 0; #X connect 5 0 9 0; #X connect 6 0 10 1; #X connect 7 0 6 0; #X connect 7 1 6 1; #X connect 8 0 7 0; #X connect 9 0 8 0; #X connect 9 1 8 1; #X connect 10 0 1 0; #X restore 295 58 pd $0-clock; #X connect 3 0 5 0; #X connect 4 0 5 0; #X connect 6 0 5 0; #X connect 7 0 5 0; #X connect 8 0 5 0; #X connect 9 0 5 0; #X connect 10 0 5 0; #X connect 11 0 5 0; #X connect 12 0 6 0; #X connect 12 1 7 0; #X connect 12 2 3 0; #X connect 12 3 4 0; #X connect 12 4 8 0; #X connect 12 5 9 0; #X connect 12 6 10 0; #X connect 12 7 11 0; #X connect 12 8 13 0; #X connect 12 9 14 0; #X connect 13 0 5 0; #X connect 14 0 5 0; #X connect 15 0 12 0; #X connect 16 0 15 0; #X connect 17 0 16 1; #X connect 18 0 16 0; #X restore 53 146 pd $0-guts; #X obj 11 11 cnv 15 158 126 $0-background-s $0-background-r bfi::control 9 14 0 14 -24198 -1 0; #X obj 94 38 bng 64 250 50 0 $0-load-s $0-load-r load 10 14 0 12 -258699 -1 -1; #X obj 22 38 tgl 64 0 $0-run-s $0-run-r run 16 12 0 12 -258699 -1 -1 0 1; #X obj 22 110 hradio 17 1 0 8 $0-speed-s $0-speed-r speed 40 9 0 12 -258699 -1 -1 7; #X coords 0 -1 1 1 160 128 1 10 10; #X restore 11 10 pd $0-bfi; #X text 190 37 A brainf*ck interpreter in Pd.; #X text 190 57 (c) 2006 Claude Heiland-Allen; #X text 190 77 Licensed under GNU GPL v2+; #X text 190 117 Pd *is* a programming language!; #X text 190 17 bfi.pd version 0.0.1; #X text 190 97 Yellow means key-press expected.;
#include <stdio.h>
int main(void) { int c; while (EOF != (c = getchar())) { printf("%d\n", c); } return (0); }
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list