Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Submit Tips
Search
HOME
REVIEWS
HOW-TOS
CODING
INTERVIEWS
FEATURES
OVERVIEW
BLOGS
SERIES
IT ADMIN
Search for:
Search
Lisp has been hailed as the worlds most powerful programming language. But only the top percentile of programmers use it because of its cryptic syntax and academic reputation. This is rather unfortunate, since Lisp isnt that hard to grasp. If you want to be among the crme de la crme, this series is for you. This is the eighth article in the series that began in June 2011.
A popular myth about Common Lisp is that it does not support a GUI. This is not true. Lisp systems have supported the GUI since the late 1970s much before low-cost consumer computers adopted it. The Xerox Alto, developed at Xerox PARC in 1973, was the first computer to use the desktop metaphor and a mouse-driven GUI. It was not a commercial product. Later, Xerox Star was introduced by Xerox Corporation in 1981. This was the first commercial system to incorporate the GUI, and it came with Lisp and SmallTalk for the research and software development market (the Apple Macintosh, released in 1984, was the first commercially successful product to use a multi-panel window GUI). Windows and Macintosh users occasionally find the Lisp GUI coarse and a bit unfamiliar. Several commercial Lisp environments offer graphical interface builders that let you build widgets with point/click and drag/drop techniques, but the look and feel is often plain. These Lisp environments typically provide wrappers around the collection of graphic routines supported by the OS, such that these wrappers can be used from within your Lisp program.
Follow
+2,503
Menus
You can create menus for an application using the menu class. Let us start by creating a testcallback and a hello function, which well need to create and test our GUIs.
( d e f u nt e s t c a l l b a c k( d a t ai n t e r f a c e ) ( d i s p l a y m e s s a g e" D a t a~ Si ni n t e r f a c e~ S " d a t ai n t e r f a c e ) )
( d e f u nh e l l o( d a t ai n t e r f a c e ) ( d e c l a r e( i g n o r ed a t ai n t e r f a c e ) ) ( d i s p l a y m e s s a g e" H e l l oW o r l d " ) )
Find us on Facebook
The following code then creates a CAPI interface with a menu, Foo, which contains four items. Choosing any of these items displays its arguments. Each item has the callback specified by the
: c a l l b a c kkeyword.
( m a k e i n s t a n c e' m e n u : t i t l e" F o o " : i t e m s' ( " O n e "" T w o "" T h r e e "" F o u r " ) : c a l l b a c k' t e s t c a l l b a c k ) ( m a k e i n s t a n c e' i n t e r f a c e : m e n u b a r i t e m s( l i s t* ) ) ( d i s p l a y* )
A submenu can be created simply by specifying a menu as one of the items of the top-level menu.
( m a k e i n s t a n c e' m e n u : t i t l e" B a r " : i t e m s' ( " O n e "" T w o "" T h r e e "" F o u r " ) : c a l l b a c k' t e s t c a l l b a c k ) ( m a k e i n s t a n c e' m e n u : t i t l e" B a z " : i t e m s( l i s t12*45 ) : c a l l b a c k' t e s t c a l l b a c k ) ( c o n t a i n* ) Popular Comments Tag cloud
This creates an interface that has a menu called Baz, which itself contains five items. The third item is another menu, Bar, which contains four items. Once again, selecting any item returns its arguments. Menus can be nested as deeply as required, using this method. The m e n u c o m p o n e n tclass lets you group related items together in a menu. This allows similar menu items to share properties such as callbacks, and to be visually separated from other items in the menus. Menu components are actually choices. Here is a simple example of a menu component. This creates a menu called Items, which has four items. Menu 1 and Menu 2 are ordinary menu items, but Item 1 and Item 2 are created from a menu component, and are therefore grouped together in the menu, as shown in Figure 1:
( s e t qc o m p o n e n t( m a k e i n s t a n c e' m e n u c o m p o n e n t : i t e m s' ( " i t e m1 "" i t e m 2 " ) : p r i n t f u n c t i o n' s t r i n g c a p i t a l i z e : c a l l b a c k' t e s t c a l l b a c k ) ) ( c o n t a i n( m a k e i n s t a n c e' m e n u : t i t l e" I t e m s " : i t e m s ( l i s t" m e n u1 "c o m p o n e n t" m e n u2 " ) : p r i n t f u n c t i o n' s t r i n g c a p i t a l i z e : c a l l b a c k' h e l l o ) : w i d t h1 5 0 : h e i g h t0 )
Radio buttons
Menu components allow you to specify, via the : i n t e r a c t i o nkeyword, selectable menu items either as multiple-selection or single-selection items. This is like having radio buttons or check boxes as items in a menu, and is a popular technique among many GUI-based applications. The following example shows you how to include a panel of radio buttons in a menu (see Figure 2):
( s e t qr a d i o( m a k e i n s t a n c e' m e n u c o m p o n e n t : i n t e r a c t i o n: s i n g l e s e l e c t i o n : i t e m s' ( " T h i s "" T h a t " ) : c a l l b a c k' h e l l o ) ) ( s e t qc o m m a n d s( m a k e i n s t a n c e' m e n u : t i t l e" C o m m a n d s " : i t e m s ( l i s t" C o m m a n d1 "r a d i o" C o m m a n d2 " ) : c a l l b a c k' t e s t c a l l b a c k ) ) ( c o n t a i nc o m m a n d s )
The menu items This and That are radio buttons, only one of which may be selected at a time. The other items are just ordinary commands, as in the previous example. Note that CAPI automatically groups items that are parts of a menu component, so that they are separated from other items in the menu.
Checked menu
The above example also illustrates the use of more than one callback in a menu, which of course is the usual case when you are developing real applications. Choosing either of the radio buttons displays one message on the screen, and choosing either Command1 or Command2 returns the arguments of the callback. Checked menu items can be created by specifying : m u l t i p l e s e l e c t i o nto the : i n t e r a c t i o nkeyword, as illustrated below (view Figure 3):
( s e t ql e t t e r s( m a k e i n s t a n c e' m e n u c o m p o n e n t : i n t e r a c t i o n: m u l t i p l e s e l e c t i o n : i t e m s( l i s t" A l p h a "" B e t a " ) ) ) ( c o n t a i n( m a k e i n s t a n c e' m e n u : t i t l e" G r e e k " : i t e m s( l i s tl e t t e r s ) : c a l l b a c k' t e s t c a l l b a c k ) )
Note how the items in the menu component inherit the callback given to the parent, eliminating the need to specify a separate callback for each item or component in the menu. Within a menu or component, you can specify alternatives that are invoked by modifier keys for a main menu item. The menu-item class lets you create individual menu items, which can be passed to menucomponents or menus via the : i t e m skeyword. Using this class, you can assign different callbacks to different menu items. Remember that each instance of a menu item must not be used in more than one place at a time.
( s e t qt e s t( m a k e i n s t a n c e' m e n u i t e m : t i t l e" T e s t " : c a l l b a c k' t e s t c a l l b a c k ) ) ( s e t qh e l l o( m a k e i n s t a n c e' m e n u i t e m : t i t l e" H e l l o " : c a l l b a c k' h e l l o ) ) ( s e t qg r o u p( m a k e i n s t a n c e' m e n u c o m p o n e n t : i t e m s( l i s tt e s th e l l o ) ) ) ( c o n t a i ng r o u p )
The combination of menu items, menu components and menus can create a hierarchical structure. The menu in the below code has five elements, one of which is itself a menu (with three menu items) and the remainder are menu components and menu items. Items in a menu inherit values from their parent, allowing similar elements to share relevant properties whenever possible.
( d e f u nm e n u i t e m n a m e( d a t a ) ( f o r m a tn i l" M e n uI t e m~ D "d a t a ) )
( d e f u ns u b m e n u i t e m n a m e( d a t a ) ( f o r m a tn i l" S u b m e n uI t e m~ D "d a t a ) ) ( c o n t a i n ( m a k e i n s t a n c e ' m e n u : i t e m s ( l i s t ( m a k e i n s t a n c e' m e n u c o m p o n e n t : i t e m s' ( 12 ) : p r i n t f u n c t i o n' m e n u i t e m n a m e ) ( m a k e i n s t a n c e' m e n u c o m p o n e n t : i t e m s ( l i s t3 ( m a k e i n s t a n c e ' m e n u : t i t l e" S u b m e n u " : i t e m s' ( 123 ) : p r i n t f u n c t i o n ' s u b m e n u i t e m n a m e ) ) : p r i n t f u n c t i o n' m e n u i t e m n a m e ) ( m a k e i n s t a n c e' m e n u i t e m : d a t a4 2 ) ) : p r i n t f u n c t i o n' m e n u i t e m n a m e ) )
Rather than create GUI elements programmatically, LispWorks also contains an Interface Builder, which is a tool to construct graphical user interfaces for Lisp applications. You can design and test each window or dialogue in your application, and the interface builder generates the necessary source code to create the windows you have all you need to do is add callbacks to the generated code, so that your own source code is utilised.
Related Posts:
A Quick-Start Practical Guide to Drupal Module Development Developing Apps on Qt, Part 4 Developing Apps on Qt, Part 2 Play with GUIs using Python Function Pointers and Callbacks in C An Odyssey
Tags: application interfaces, CAPI, Common Lisp, graphical interface, GTK+, GUI, LFY February 2012, Lisp, lisp code, lisp program, lisp programs, Lisp: Tears of Joy series, LispWorks, Macintosh, Smalltalk, X Window System, Xerox Corporation, Xerox Star
Previous Post
Next Post
What's this?
Billionaires Dump Stocks, Prepare for Collapse Moneynews How To Trade Your Fat Belly for a Fit Belly The People's Chemist Don't Let Your Kids Read This: Paying Teens for Citi Women & Co. Don't Get Alzheimer's: Here's What May Cause It Newsmax Health
India has immense under-utilised talent in the cloud 39 comments Getting Your First Job Code Sport
1 comment 1 comment
Share
Sir, I am an engineer student. Is it good to learn Lisp especially in India? Answer plz
Reply Share
V ivek S hangari
a year ago
Lisp enlightens you as a hacker. Lisper Paul Graham explains this so proficiently and methodically that it will be inappropriate to answer this questions in any other words than his. Here is an excerpt from one of his essays: The five languages (Python, Java, C/C++, Perl, and Lisp) that Eric Raymond recommends to hackers fall at various points on the power continuum. Where they fall relative to one another is a sensitive topic. But I think Lisp is at the top. And to support this claim Ill tell you about one of the things I find missing when I look at the other four languages. How can you get anything done in them, I think, without macros? Many languages have something called a macro. But Lisp macros are unique. Lisp code is made out of Lisp data objects. And not in the trivial sense that the source files contain characters, and strings are one of the data types supported by the language. Lisp code, after its read by the parser, is made of data structures that you can traverse.
r
C o m m e n t fe e d
see more
Reply
Share
Su b s cri b e vi a e m a i l
Reviews
How-Tos
Coding
Interviews
Features
Overview
Blogs
Search
Popular tags
Linux , ubuntu, Java, MySQL, Google, python, Fedora, Android, PHP, C, html, w eb applications , India, Microsoft, unix , Window s , Red Hat, Oracle, Security , Apache, xml, LFY April 2012, FOSS, GNOME, http, JavaScript, LFY June 2011, open source, RAM, operating systems
All published articles are released under Creative Commons Attribution-NonCommercial 3.0 Unported License, unless otherw ise noted. LINUX For You is pow ered by WordPress, w hich gladly sits on top of a CentOS-based LEMP stack.