Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21412
  • 博文数量: 5
  • 博客积分: 106
  • 博客等级: 民兵
  • 技术积分: 65
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-05 21:39
文章分类

全部博文(5)

文章存档

2013年(1)

2012年(1)

2011年(3)

我的朋友

分类: Erlang

2013-01-27 13:28:46


chicken scheme Iup 教程链接:


在C语言里面,这样来显示一个对话框和按钮:

hello1.c
#include 
#include 

int exit_cb (void) {
  return IUP_CLOSE;
}

int main (int argc, char *argv[]) {

  // declare widgets
  Ihandle *btn, *lbl, *vb, *dlg;

  // initialize iup
  IupOpen(&argc, &argv);
  
  // create widgets and set their attributes
  btn=IupButton("&Ok", "");
  IupSetCallback(btn,"ACTION", (Icallback) exit_cb);
  IupSetAttribute(btn, "EXPAND", "Yes");
  IupSetAttribute(btn, "TIP", "Exit button");
  
  lbl=IupLabel("Hello,world!");

  vb=IupVbox(lbl, btn, NULL);
  IupSetAttribute(vb, "GAP", "10");
  IupSetAttribute(vb, "MARGIN", "10x10");
  IupSetAttribute(vb, "ALIGNMENT", "ACENTER");

  dlg=IupDialog(vb);
  IupSetAttribute(dlg, "TITLE", "Hello");

  // Map widgets and show dialog
  IupShow(dlg);

  // Wait for user interaction
  IupMainLoop();

  // Clean up
  IupDestroy(dlg);
  IupClose();
  return EXIT_SUCCESS;
}
可以看到,在C语言里面是标准的命令式语言风格。

Chicken-scheme里面,可以这样写:


(use iup)

(define (cb-exit self) 'close)

(define btn (button))
(set! (callback btn action:) cb-exit)
(set! (attribute btn title:) '&Ok)
(set! (attribute btn expand:) 'Yes)
(set! (attribute btn tip:) "Close button")

(define lbl (label "Hello World!")) 

(define vb (vbox lbl btn))
(attribute-set! vb gap: 10)
(attribute-set! vb margin: '15x15)
(attribute-set! vb alignment: 'ACENTER)

(define dlg (dialog vb))
(attribute-set! dlg title: 'Hello)

(show dlg)
(main-loop)
(destroy! dlg)
(exit 0)

还是命令式风格。

看下面的写法:

(use iup)

(define dlg
  (dialog
    (vbox
      (label "Hello, World!")
      (button title: '&Ok
              expand: 'Yes
              tip: "Close button"
              action: (lambda (self) 'close))
      gap: 10
      alignment: 'ACENTER
      margin: '15x15)
    title: 'IUP))

(show dlg)
(main-loop)
(destroy! dlg)
(exit 0)
里面定义对话框一段,是标准的函数式语言风格了。

看来GUI程序用函数式语言来写显得很精简,也很nature.

另注:

在具体实现的时候,是否会碰到求值顺序的问题?dialog和button会有定义顺序先后的问题吗?


阅读(1545) | 评论(0) | 转发(0) |
0

上一篇:web.py 标准错误重定向

下一篇:没有了

给主人留下些什么吧!~~