all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to convert a char to a property
@ 2010-07-27  8:29 Cecil Westerhof
  2010-07-27 12:12 ` TheFlyingDutchman
  2010-07-27 13:18 ` Cecil Westerhof
  0 siblings, 2 replies; 6+ messages in thread
From: Cecil Westerhof @ 2010-07-27  8:29 UTC (permalink / raw
  To: help-gnu-emacs

I have the following property list:
    (defvar dcbl-bbdb-user-defined-fields (list :L "mail-alias"
                                                :M "mailer"
                                                :P "playlist"
                                                :s "subjects"
                                                :t "type"
                                                :w "website")
      "User defined fields in the bbdb with parameter to insert into buffer")

With (getf dcbl-bbdb-user-defined-fields :M) I get "mailer".

But I want to work parameter driven. So for example I have:
     (setq parameters "MLst")
     (setq current-char (string-to-char parameters))

The variable current-char now contains 77. How could I use
current-char to retrieve "mailer"?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: How to convert a char to a property
  2010-07-27  8:29 How to convert a char to a property Cecil Westerhof
@ 2010-07-27 12:12 ` TheFlyingDutchman
  2010-07-27 22:06   ` Cecil Westerhof
  2010-07-27 13:18 ` Cecil Westerhof
  1 sibling, 1 reply; 6+ messages in thread
From: TheFlyingDutchman @ 2010-07-27 12:12 UTC (permalink / raw
  To: help-gnu-emacs

On Jul 27, 1:29 am, Cecil Westerhof <Ce...@decebal.nl> wrote:
> I have the following property list:
>     (defvar dcbl-bbdb-user-defined-fields (list :L "mail-alias"
>                                                 :M "mailer"
>                                                 :P "playlist"
>                                                 :s "subjects"
>                                                 :t "type"
>                                                 :w "website")
>       "User defined fields in the bbdb with parameter to insert into buffer")
>
> With (getf dcbl-bbdb-user-defined-fields :M) I get "mailer".
>
> But I want to work parameter driven. So for example I have:
>      (setq parameters "MLst")
>      (setq current-char (string-to-char parameters))
>
> The variable current-char now contains 77. How could I use
> current-char to retrieve "mailer"?
>
> --
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn:http://www.linkedin.com/in/cecilwesterhof


(getf dcbl-bbdb-user-defined-fields
           (intern (concat
              ":"
              (char-to-string current-char)  )  )  )


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

* Re: How to convert a char to a property
  2010-07-27  8:29 How to convert a char to a property Cecil Westerhof
  2010-07-27 12:12 ` TheFlyingDutchman
@ 2010-07-27 13:18 ` Cecil Westerhof
  2010-07-27 17:59   ` Pascal J. Bourguignon
  1 sibling, 1 reply; 6+ messages in thread
From: Cecil Westerhof @ 2010-07-27 13:18 UTC (permalink / raw
  To: help-gnu-emacs

Op dinsdag 27 jul 2010 10:29 CEST schreef Cecil Westerhof:

> I have the following property list:
> (defvar dcbl-bbdb-user-defined-fields (list :L "mail-alias"
> :M "mailer"
> :P "playlist"
> :s "subjects"
> :t "type"
> :w "website")
> "User defined fields in the bbdb with parameter to insert into buffer")
>
> With (getf dcbl-bbdb-user-defined-fields :M) I get "mailer".
>
> But I want to work parameter driven. So for example I have:
> (setq parameters "MLst")
> (setq current-char (string-to-char parameters))
>
> The variable current-char now contains 77. How could I use
> current-char to retrieve "mailer"?

At the moment I use another solution.

I now have:
    (defvar dcbl-bbdb-user-defined-fields '(("L" "mail-alias")
                                            ("M" "mailer")
                                            ("P" "playlist")
                                            ("s" "subjects")
                                            ("t" "type")
                                            ("w" "website"))
      "User defined fields in the bbdb with parameter to insert into buffer")

and use the following code:
    (setq field-name     nil
          parameters     dcbl-bbdb-user-defined-fields
          this-value     nil)
    (while parameters
      (setq this-parameter (car parameters)
            parameters     (cdr parameters))
      (when (string= current-char (car this-parameter))
        (setq field-name (car (cdr this-parameter))
              parameters nil)))

The variable current-char is the parameter (as a string) that I am
searching for.

This does work, but I do not know if it is very efficient. Is this a
good solution, or should I code it differently?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: How to convert a char to a property
  2010-07-27 13:18 ` Cecil Westerhof
@ 2010-07-27 17:59   ` Pascal J. Bourguignon
  2010-07-27 22:11     ` Cecil Westerhof
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal J. Bourguignon @ 2010-07-27 17:59 UTC (permalink / raw
  To: help-gnu-emacs

Cecil Westerhof <Cecil@decebal.nl> writes:

> Op dinsdag 27 jul 2010 10:29 CEST schreef Cecil Westerhof:
>
>> I have the following property list:
>> (defvar dcbl-bbdb-user-defined-fields (list :L "mail-alias"
>> :M "mailer"
>> :P "playlist"
>> :s "subjects"
>> :t "type"
>> :w "website")
>> "User defined fields in the bbdb with parameter to insert into buffer")
>>
>> With (getf dcbl-bbdb-user-defined-fields :M) I get "mailer".
>>
>> But I want to work parameter driven. So for example I have:
>> (setq parameters "MLst")
>> (setq current-char (string-to-char parameters))
>>
>> The variable current-char now contains 77. How could I use
>> current-char to retrieve "mailer"?
>
> At the moment I use another solution.
>
> I now have:
>     (defvar dcbl-bbdb-user-defined-fields '(("L" "mail-alias")
>                                             ("M" "mailer")
>                                             ("P" "playlist")
>                                             ("s" "subjects")
>                                             ("t" "type")
>                                             ("w" "website"))
>       "User defined fields in the bbdb with parameter to insert into buffer")
>
> and use the following code:
>     (setq field-name     nil
>           parameters     dcbl-bbdb-user-defined-fields
>           this-value     nil)
>     (while parameters
>       (setq this-parameter (car parameters)
>             parameters     (cdr parameters))
>       (when (string= current-char (car this-parameter))
>         (setq field-name (car (cdr this-parameter))
>               parameters nil)))
>
> The variable current-char is the parameter (as a string) that I am
> searching for.
>
> This does work, but I do not know if it is very efficient. Is this a
> good solution, or should I code it differently?

If you have characters and want to map them, why do you make a table
mapping keywords or strings?  Make a table mapping characters!


     (defvar dcbl-bbdb-user-defined-fields '((?L . "mail-alias")
                                             (?M . "mailer")
                                             (?P . "playlist")
                                             (?s . "subjects")
                                             (?t . "type")
                                             (?w . "website"))
       "An a-list of User defined fields in the bbdb with parameter to insert into buffer")

    (defun get-field-name-from-character (ch)
       (cdr (assoc ch dcbl-bbdb-user-defined-fields)))



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


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

* Re: How to convert a char to a property
  2010-07-27 12:12 ` TheFlyingDutchman
@ 2010-07-27 22:06   ` Cecil Westerhof
  0 siblings, 0 replies; 6+ messages in thread
From: Cecil Westerhof @ 2010-07-27 22:06 UTC (permalink / raw
  To: help-gnu-emacs

Op dinsdag 27 jul 2010 14:12 CEST schreef TheFlyingDutchman:

> (getf dcbl-bbdb-user-defined-fields
> (intern (concat
> ":"
> (char-to-string current-char)  )  )  )

Thanks, that works.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: How to convert a char to a property
  2010-07-27 17:59   ` Pascal J. Bourguignon
@ 2010-07-27 22:11     ` Cecil Westerhof
  0 siblings, 0 replies; 6+ messages in thread
From: Cecil Westerhof @ 2010-07-27 22:11 UTC (permalink / raw
  To: help-gnu-emacs

Op dinsdag 27 jul 2010 19:59 CEST schreef Pascal J. Bourguignon:

>>> I have the following property list:
>>> (defvar dcbl-bbdb-user-defined-fields (list :L "mail-alias"
>>> :M "mailer"
>>> :P "playlist"
>>> :s "subjects"
>>> :t "type"
>>> :w "website")
>>> "User defined fields in the bbdb with parameter to insert into buffer")
>>>
>>> With (getf dcbl-bbdb-user-defined-fields :M) I get "mailer".
>>>
>>> But I want to work parameter driven. So for example I have:
>>> (setq parameters "MLst")
>>> (setq current-char (string-to-char parameters))
>>>
>>> The variable current-char now contains 77. How could I use
>>> current-char to retrieve "mailer"?
>>
>> At the moment I use another solution.
>>
>> I now have:
>> (defvar dcbl-bbdb-user-defined-fields '(("L" "mail-alias")
>> ("M" "mailer")
>> ("P" "playlist")
>> ("s" "subjects")
>> ("t" "type")
>> ("w" "website"))
>> "User defined fields in the bbdb with parameter to insert into buffer")
>>
>> and use the following code:
>> (setq field-name     nil
>> parameters     dcbl-bbdb-user-defined-fields
>> this-value     nil)
>> (while parameters
>> (setq this-parameter (car parameters)
>> parameters     (cdr parameters))
>> (when (string= current-char (car this-parameter))
>> (setq field-name (car (cdr this-parameter))
>> parameters nil)))
>>
>> The variable current-char is the parameter (as a string) that I am
>> searching for.
>>
>> This does work, but I do not know if it is very efficient. Is this a
>> good solution, or should I code it differently?
>
> If you have characters and want to map them, why do you make a table
> mapping keywords or strings?  Make a table mapping characters!
>
>
> (defvar dcbl-bbdb-user-defined-fields '((?L . "mail-alias")
> (?M . "mailer")
> (?P . "playlist")
> (?s . "subjects")
> (?t . "type")
> (?w . "website"))
> "An a-list of User defined fields in the bbdb with parameter to insert into
> 	buffer")
>
> (defun get-field-name-from-character (ch)
> (cdr (assoc ch dcbl-bbdb-user-defined-fields)))

A very good idea. My temporary solution was quit inefficient. The
solution with getf is almost 15 times as fast as what I did. But your
solution is almost 2 times more efficient. Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

end of thread, other threads:[~2010-07-27 22:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-27  8:29 How to convert a char to a property Cecil Westerhof
2010-07-27 12:12 ` TheFlyingDutchman
2010-07-27 22:06   ` Cecil Westerhof
2010-07-27 13:18 ` Cecil Westerhof
2010-07-27 17:59   ` Pascal J. Bourguignon
2010-07-27 22:11     ` Cecil Westerhof

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.