小编Mat*_*och的帖子

我如何从SICP调用Scheme号函数

在SICP中,(前2.6)将以下函数描述为"没有数字"的方法.我正在试图理解这一点.作为起点,如何调用这些函数?我可以用输出为1的某种方式实际应用它们吗?(或任何其他数字?)

(define zero (lambda (f) (lambda (x) x)))

(define (add-1 n)
  (lambda (f) (lambda (x) (f ((n f) x)))))
Run Code Online (Sandbox Code Playgroud)

我最初的尝试没有成功:

Welcome to DrScheme, version 4.1.5 [3m].
Language: Simply Scheme; memory limit: 128 megabytes.
> (add-1 (zero))
. . procedure zero: expects 1 argument, given 0
> (add-1 zero)
#<procedure>
> (add-1 1)
#<procedure>
> ((add-1 1))
. . #<procedure>: expects 1 argument, given 0
> 
Run Code Online (Sandbox Code Playgroud)

scheme sicp

1
推荐指数
1
解决办法
638
查看次数

如何删除这些C宏之间的重复?

我有以下几个用于创建测试功能的C预处理器宏:

// Defines a test function in the active suite
#define test(name)\
    void test_##name();\
    SuiteAppender test_##name##_appender(TestSuite::active(), test_##name);\
    void test_##name()
Run Code Online (Sandbox Code Playgroud)

这是这样使用的:

test(TestName) {
    // Test code here
}
Run Code Online (Sandbox Code Playgroud)

// Defines a test function in the specified suite
#define testInSuite(name, suite)\
    void test_##name();\
    SuiteAppender test_##name##_appender(suite, test_##name);\
    void test_##name()
Run Code Online (Sandbox Code Playgroud)

这是这样使用的:

test(TestName, TestSuiteName) {
    // Test code here
}
Run Code Online (Sandbox Code Playgroud)

如何删除两个宏之间的重复?

c macros code-duplication c-preprocessor

1
推荐指数
1
解决办法
162
查看次数

在GUI中使用不同的布局

这是我的程序应该是什么样子,我有点困惑我应该在哪里使用不同的布局.

我有一个Window类调用Panel类,Panel类调用InputPanel和DisplayPanel类.我的InputPanel类调用我的DetailsPanel,CrimePanel和ButtonPanel类,以便它们构成在Input选项卡下看到的内容.我被告知要在整个窗口中使用BorderLayout,并且DetailsPanel(左侧面板)和CrimePanel应该是GridLayout.

这是否意味着我应该:

  1. 将BorderLayout代码放在Panel中,将GridLayout代码放在CrimePanel和DetailsPanel中
  2. 将BorderLayout代码放在Window中,将GridLayout代码放在Panel中?

alt text http://img137.imageshack.us/img137/6422/93381955.jpg

java layout user-interface grid-layout

1
推荐指数
1
解决办法
1044
查看次数

当我尝试访问同步列表时,为什么我的线程会停止?

由于某种原因,这个输出:

 public void msgNeedParts() {
    // Blabla...
    System.out.println(name + ": Try to print 'tasks'...");
    synchronized(tasks) {
        System.out.println(name + ": Tasks--" + tasks);
        System.out.println(name + ": Did I manage to print it?");
        tasks.add(new BinToDump(feeder, binNum));
    }
    stateChanged();
 }
Run Code Online (Sandbox Code Playgroud)

只需打印出"GantryAgent:尝试打印'任务'......",但不能打印出以下任何消息.我猜测线程在尝试访问同步列表'任务'时会以某种方式"卡住",但我不知道为什么会发生这种情况.

'tasks'被声明并初始化为:

private List<BinToDump> tasks = 
    Collections.synchronizedList(new ArrayList<BinToDump>());
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出我错过了什么吗?

啊! 我怀疑我可能有罪魁祸首:

    /* If nothing left to do, return to original position. */

    synchronized (tasks) {

        if (tasks.isEmpty()) {

            doReturnToOriginalPos();

        }

    }
Run Code Online (Sandbox Code Playgroud)

在我的调度程序(这是代理设计)中,我检查'tasks'是否为空,然后调用doReturnToOriginalPos().也许这只是一次又一次地发生,以至于其他方法没有机会修改它?

这确实是问题所在!在我的调度程序中,它一直被调用得如此之快,以至于没有别的东西可以访问"任务" 谢谢大家的帮助!

java synchronized

1
推荐指数
1
解决办法
255
查看次数

在Java中初始化复杂静态成员的最佳方法是什么?

我的目标是Properties在我的类中有一个私有静态对象,在创建Properties我的应用程序所需的其他对象时充当默认对象.当前的实现如下所示:

public class MyClass {
    private static Properties DEFAULT_PROPERTIES = new Properties();

    static {
        try {
           DEFAULT_PROPERTIES.load(
               MyClass.class.getResourceAsStream("myclass.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 }
Run Code Online (Sandbox Code Playgroud)

看着它,它有效,但感觉不对.

你会怎么做?

java static-members

1
推荐指数
2
解决办法
734
查看次数

有关JSP计算的问题

这段代码的问题是,我发现了一个作家的普及为0%(我的意思是百分之零如果借图书的数量是14和借来的所选作者的书籍总数为3 - 它应该是21.42% ).为什么会这样?

除最后一个外,所有结果都是正确的:

作者0%受欢迎(对于上面给出的数据)

<%
String requestedoprations = request.getParameter("popularity");
if("check".equalsIgnoreCase(requestedoprations)){
    int num=LimsHandler.getInstance().popularitycheck(
        request.getParameter("selectedauthor"));
    if(num!=0){
        Limsdetails[] list = LimsHandler.getInstance().libsdetails();
        String totbks=list[0].getTot_books();
        String totbrwdbk=list[0].getTot_borrowed_bks();
        int totbksint=Integer.parseInt(totbks);
        int totbrwdbksint=Integer.parseInt(totbrwdbk);
        float per=(num/totbrwdbksint)*100;          
%>
<font color="brown">
    <b>Total No of Books Available in Library is : <%=totbksint %><br></br>
    Out of which <%=totbrwdbksint %> are borrowed.<br></br>
    <b>No of readers reading Author 
        <%=request.getParameter("selectedauthor") %>'s book. : 
        <%=num %></b><br></br>
    <b> Author <%=request.getParameter("selectedauthor") %> is <%=per %> % 
        popular!</b><br></br>
</font>

<%}else{ %>
    <h4 align="center">
        <font color="red">
            <img border="0" …
Run Code Online (Sandbox Code Playgroud)

java jsp

1
推荐指数
1
解决办法
706
查看次数

如何在Arduino Uno上检查已存储的变量?

我有一个我想要制作的程序,它会询问变量是否已经存在.如果是,则显示它,如果没有,则显示它并使用PROGMEM命令将其存储在Arduino中.有人可以解释更多关于PROGMEM以及如何制作我正在谈论的程序吗?

arduino

1
推荐指数
1
解决办法
1万
查看次数

C(.LST)中的列表文件

编译完一些代码后,编译器会生成一堆文件.我有统计,符号,调用树,错误,列表,调试和exe.除了列表文件之外,我已经弄明白了每个意思.列表文件的功能是什么.是针对用户还是计算机/嵌入式系统本身?

c list

0
推荐指数
1
解决办法
6584
查看次数

为什么这个Python代码什么都不打印?

class a(str):
    def b(self,*x,**y):
        print str.decode(self,*x,**y)

b=a()
b.b('utf-8','aaa') # This prints nothing, why?
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
1126
查看次数

如何在删除行时更改自动增量主键值?

我有一个问题,每当我删除一行时,与该行对应的行ID都会被删除,但我不想这样做.我想要的是如果删除任何行,那么该行之后的其他行应该移位一个(删除的行数)位置.

例:

假设有一个用户表(id和名称)

id(auto incremented primary key)          name
1                                         xyz
2                                         aaa
3                                         ray
4                                         mark
5                                         allen
Run Code Online (Sandbox Code Playgroud)

现在删除行id=3和表应该是这样的

id(auto incremented primary key)          name
1                                         xyz
2                                         aaa
3                                         mark
4                                         allen
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个目标?

mysql

0
推荐指数
1
解决办法
1329
查看次数

如何在Turbo C++中创建基于字符的数组?

我正在尝试一些C++,但我太新了,你可以说这是我在C++的第一天.所以我试图创建一个函数,但我被阵列困住了!当我创建一个像这样的基于字符的数组:

char x[7][7] = {"sec","min","hr","day","week","month","year"};
Run Code Online (Sandbox Code Playgroud)

当我尝试从中获取数据时:

for (i=0;i<=7;i++){
  cout << x[i] << "\n";    
} 
Run Code Online (Sandbox Code Playgroud)

我得到一些奇怪的结果!像这样 :
在此输入图像描述

任何人都可以告诉我,我完全错了!请我是C++的新手,所以你能给我一个很好的解释.

c c++ arrays multidimensional-array

0
推荐指数
1
解决办法
1396
查看次数

绑定功能出错(C只是服务器)

这是我服务器的代码:

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>

int main (int argc, char **argv)
//------------------------MAIN--------------------------//
{
int sock;       // sock descriptor
int new_sock;
int c;
int sin_size;
int koniec = 0;
char *ip_address;
char *port_number;
while (1)
        {
        static struct option OpcjeProgramu[] =
        {
        { "port", required_argument, 0, 'p'},
        { "interface", required_argument, 0, 'i'},
        { 0, 0,0,0 }
        };

int option_index = 0; …
Run Code Online (Sandbox Code Playgroud)

c bind

-1
推荐指数
1
解决办法
1591
查看次数