Talk:Man or boy test

message: Amazing how most wikipedia articles regarding algorithms quickly evolve into pissing contest between programming language implementations.  Is the algorithm really so hard or are programmers so stupid that they can't possibly read it unless it's written in their favorite language?  I'm sure there's also a lot of propaganda going on -- I mean, is it really necessary implementations for 2 versions of C#?! -- 201.47.188.2 (talk) 18:30, 8 September 2008 (UTC)

message: http://www.rosettacode.org/rosettacode/w/index.php?title=Talk:Man_or_boy_test  —Preceding unsigned comment added by NevilleDNZ (talk • contribs) 00:32, 19 December 2007 (UTC)
thread_title:  Pending code snippet transplant/removal? 

message: I turned the Common Lisp example into Scheme. Would it be useful to add that, given that there's already CL? Golwengaud (talk) 16:35, 24 December 2007 (UTC)
replies: text: Yes, I believe it would.  70.111.126.237 (talk) 16:16, 3 January 2008 (UTC)
replies: text: Done. Golwengaud (talk) 14:57, 6 January 2008 (UTC)
thread_title:  Scheme 

message: There is a bug in the Common Lisp implementation:
even with LET*, the scope of a local variable does not
include its own initialization form, so the proposed
solution does not in fact work (B is unbound).
I intend to replace it shortly.
70.111.126.237 (talk) 16:16, 3 January 2008 (UTC)
thread_title: Common Lisp

message: Added a Scala implementation. This is without the object wrapper because you can run Scala programs directly as scripts. 128.214.11.51 (talk) 08:26, 17 March 2008 (UTC)
thread_title: Scala

message: The C program in the article is rather confusing. In particular, ARG is both a type and a macro:
 /* man-or-boy.c */
 #include <stdio.h>
 #include <stdlib.h>
 
 // --- thunks
 typedef struct arg {
   int       (*fn)(struct arg*);
   int        *k;
   struct arg *x1, *x2, *x3, *x4, *x5;
 } ARG;
 
 // --- lambdas
 int f_1 (ARG* _) { return -1; }
 int f0  (ARG* _) { return  0; }
 int f1  (ARG* _) { return  1; }
 
 // --- helper
 int eval(ARG* a) { return a->fn(a); }
 #define ARG(...) (&(ARG){ __VA_ARGS__ })
 #define FUN(...) ARG(B,&k,__VA_ARGS__)
 
 // --- functions
 int B(ARG* a) {
   int A(ARG*);
   int k = *a->k -= 1;
   return A( FUN(a,a->x1,a->x2,a->x3,a->x4) );
 }
 
 int A(ARG* a) {
   return *a->k <= 0 ? eval(a->x4)+eval(a->x5) : B(a);
 }
 
 int main(int argc, char **argv) {
   int k = argc == 2 ? strtol(argv[1],0,0) : 10;
   printf("%d\n", A( FUN(ARG(f1),ARG(f_1),ARG(f_1),ARG(f1),ARG(f0)) ));
 }
The C program from the talk page (at top, by Random832) looks much clearer, and avoids advanced features such as __VA_ARGS__:
#include <stdio.h>
typedef struct s {
    int k;
    struct s *x1, *x2, *x3, *x4;
    int(*f)(struct s* ref);
} *ps;
int B(ps ref) {
    (ref->k)--;
    return A(ref->k,ref,ref->x1,ref->x2,ref->x3,ref->x4);
}
int A(int k, ps x1,ps x2,ps x3,ps x4,ps x5) {
    struct s x;
    x.x1=x1; x.x2=x2; x.x3=x3; x.x4=x4;
    x.k=k; x.f=B;
    if(x.k <= 0)
        return x4->f(x4) + x5->f(x5);
    else
        return B(&x);
}
int x(ps ref) {
    return ref->k;
}
int main() {
    struct s p; p.k= +1; p.f=x;
    struct s m; m.k= -1; m.f=x;
    struct s z; z.k=  0; z.f=x;
    int val = A(10,&p,&m,&m,&p,&z);
    printf("value is %d\n",val);
    return 0;
}
So, why not use the latter instead? 81.231.33.217 (talk) 08:56, 24 June 2008 (UTC)
thread_title:  Change C implementation