分类: Erlang
2013-01-27 13:28:46
chicken scheme Iup 教程链接:
在C语言里面,这样来显示一个对话框和按钮:
hello1.c #include可以看到,在C语言里面是标准的命令式语言风格。#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; }
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会有定义顺序先后的问题吗?