unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* widget-create 'menu-choice
@ 2009-09-18 18:54 Mortimer Cladwell
  2009-09-22  2:28 ` Kevin Rodgers
  2009-09-24 17:31 ` Andreas Politz
  0 siblings, 2 replies; 5+ messages in thread
From: Mortimer Cladwell @ 2009-09-18 18:54 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 728 bytes --]

Hi,

I would like to dynamically populate a dropdown widget from a database.  the 'menu-choice widget looks like

(widget-create 'menu-choice
        :tag "Select Host Species"
        :value "unknown"
                 :notify (lambda (widget &rest ignore)
                           (setq host-species (widget-value widget)))
    '(item "human") 
    '(item "rat") 
    '(item "mouse")) 

Suppose I can generate a list '( "human "rat" "mouse") from the database.  How to create

   '(item "human") 
    '(item "rat") 
    '(item "mouse")

on the fly?  The closest I can come is 

(progn
  (setq var '( "human" "rat" "mouse"))
(mapcar '(lambda  (a)  `'(item ,a))  var)
)

Thanks

Mortimer


      

[-- Attachment #2: Type: text/html, Size: 1589 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: widget-create 'menu-choice
  2009-09-18 18:54 widget-create 'menu-choice Mortimer Cladwell
@ 2009-09-22  2:28 ` Kevin Rodgers
  2009-09-24 17:31 ` Andreas Politz
  1 sibling, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2009-09-22  2:28 UTC (permalink / raw)
  To: help-gnu-emacs

Mortimer Cladwell wrote:
> Hi,
>  
> I would like to dynamically populate a dropdown widget from a database.  
> the 'menu-choice widget looks like
>  
> (widget-create 'menu-choice
>         :tag "Select Host Species"
>         :value "unknown"
>                  :notify (lambda (widget &rest ignore)
>                            (setq host-species (widget-value widget)))
>     '(item "human")
>     '(item "rat")
>     '(item "mouse"))
> Suppose I can generate a list '( "human "rat" "mouse") from the 
> database.  How to create
>  
>    '(item "human")
>     '(item "rat")
>     '(item "mouse")
>  
> on the fly?  The closest I can come is
>  
> (progn
>   (setq var '( "human" "rat" "mouse"))
> (mapcar '(lambda  (a)  `'(item ,a))  var)
> )

i.e.

(let ((var '("human" "rat" "mouse")))
   (mapcar (lambda (label) (list 'item label))
	  var))

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: widget-create 'menu-choice
  2009-09-18 18:54 widget-create 'menu-choice Mortimer Cladwell
  2009-09-22  2:28 ` Kevin Rodgers
@ 2009-09-24 17:31 ` Andreas Politz
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Politz @ 2009-09-24 17:31 UTC (permalink / raw)
  To: help-gnu-emacs

Mortimer Cladwell <mbcladwell@yahoo.com> writes:

> Hi,
>  
> I would like to dynamically populate a dropdown widget from a
> database.  the 'menu-choice widget looks like
>  
> (widget-create 'menu-choice
>         :tag "Select Host Species"
>         :value "unknown"
>                  :notify (lambda (widget &rest ignore)
>                            (setq host-species (widget-value
> widget)))
>     '(item "human")
>     '(item "rat")
>     '(item "mouse"))
> Suppose I can generate a list '( "human "rat" "mouse") from the
> database.  How to create
>  
>    '(item "human")
>     '(item "rat")
>     '(item "mouse")
>  
> on the fly?  The closest I can come is
>  
> (progn
>   (setq var '( "human" "rat" "mouse"))
> (mapcar '(lambda  (a)  `'(item ,a))  var)
> )
> Thanks
>  
> Mortimer

`apply' solves this problem.

(apply #'* 1 2 3 '(4 5))

-ap





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: widget-create 'menu-choice
  2009-09-24 16:13 Mortimer Cladwell
@ 2009-09-25  2:59 ` Kevin Rodgers
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2009-09-25  2:59 UTC (permalink / raw)
  To: help-gnu-emacs

Mortimer Cladwell wrote:
> Your suggestion evaluates to:
>  
> ((item "human") (item "rat") (item "mouse"))
>  
> which when inserted into a form results in the error:
>  
> widget-create: Invalid function: (item "human")

Ah, I misread the widget-create arguments.  That function's doc string is
practically useless.

> Evaluations that would work are:
>  
> '(item "human") '(item "rat") '(item "mouse")
> OR
> 
> (quote (item "human"))  (quote (item "rat")) (quote (item "mouse"))
 >
> Note that there are no enclosing parenthesis around the list.

As Andreas points out, you need apply:

(defvar species '("human" "rat" "mouse"))

(apply 'widget-create
        'menu-choice
        :tag "Select Host Species"
        :value "unknown"
        :notify (lambda (widget &rest ignore)
		 (setq host-species (widget-value widget)))
        (mapcar (lambda (label) (list 'item label))
	       species))

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: widget-create 'menu-choice
@ 2009-09-26 21:52 Mortimer Cladwell
  0 siblings, 0 replies; 5+ messages in thread
From: Mortimer Cladwell @ 2009-09-26 21:52 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1705 bytes --]

(apply 'widget-create 'menu-choice....
Will create multiple dropdown lists.  I want a single dropdown that has 
multiple elements.  I am thinking a macro is the way to go.  Consider:

(defmacro item-element (var)
           (list 'quote `'(item ,var)))

Then (item-element "human") would evaluate to (quote (item "human"))

What I haven't been able to do is mapcar item-element over my list

("rat" "human" "mouse")

The desired output is:

(quote (item "rat")) (quote (item "human")) (quote (item "mouse"))

Note the absence of circumscribed parenthesis, i.e. this is not a list.
Suggestions?
Thanks

Mortimer

----------------------------------------------------------

Mortimer Cladwell wrote:

Your suggestion evaluates to:
>> 
>((item "human") (item "rat") (item "mouse"))
>> 
>which when inserted into a form results in the error:
>> 
>widget-create: Invalid function: (item "human")
>
Ah, I misread the widget-create arguments.  That function's doc string is
practically useless.

Evaluations that would work are:
>> 
>'(item "human") '(item "rat") '(item "mouse")
>>OR
>
>(quote (item "human"))  (quote (item "rat")) (quote (item "mouse"))
>> 
Note that there are no enclosing parenthesis around the list.
>
As Andreas points out, you need apply:
(defvar species '("human" "rat" "mouse"))
(apply 'widget-create 'menu-choice :tag "Select Host Species" :value "unknown" :notify (lambda (widget &rest ignore) (setq host-species (widget-value widget))) (mapcar (lambda (label) (list 'item label)) species))
--
Kevin Rodgers
Denver, Colorado, USA


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

[-- Attachment #2: Type: text/html, Size: 2543 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-09-26 21:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-18 18:54 widget-create 'menu-choice Mortimer Cladwell
2009-09-22  2:28 ` Kevin Rodgers
2009-09-24 17:31 ` Andreas Politz
  -- strict thread matches above, loose matches on Subject: below --
2009-09-24 16:13 Mortimer Cladwell
2009-09-25  2:59 ` Kevin Rodgers
2009-09-26 21:52 Mortimer Cladwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).