(defun help(a x)
(if (null x) nil
(cons (cons a (car x)) (help a (cdr x)))))
(defun partition(x)
(if (null x) '(nil)
(append (help (car x) (partition(cdr x))) (partition(cdr x)))))
Run Code Online (Sandbox Code Playgroud)
这是这样的:(partition '(a b)) -> ((A B) (A) (B) NIL)
我试图了解它是如何工作的.有人可以说明结果是什么吗?我试着按照代码写下来,但是我失败了.
我需要在OpenGL中制作国际象棋,并想知道这是否是正确的方法.
这是pawn piece的代码:
void pawn(void)
{
glClear (GL_COLOR_BUFFER_BIT);
DrawArc(xc+6, yc-3,1.3,M_PI/2,M_PI/2,25);
DrawArc(xc+6.7, yc-3,1.3,M_PI/2,-M_PI/2,25);
DrawArc(xc+6, yc-0.9,0.8,M_PI/2,M_PI,25);
DrawArc(xc+6.7, yc-0.9,0.8,M_PI/2,-M_PI,25);
DrawArc(xc+6.35, yc+0.25,0.5,(7*M_PI)/4,(3*M_PI)/2,25);
glBegin(GL_LINE_LOOP);
glVertex2d(xc+4.7,yc-3);
glVertex2d(xc+8,yc-3);
glEnd();
glFlush ();
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?