Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:01:56+00:00 2026-06-09T14:01:56+00:00

I need to locate a particular value that can be buried into a deeply

  • 0

I need to locate a particular value that can be buried into a deeply nested list, and never at the same place. Or even the same depth ; Here is one form of the list:

(setq my-list '(((partnum . 1) (type (TEXT . plain)) (body (charset UTF-8))
                 (disposition nil) (transfer-encoding QUOTED-PRINTABLE))
                ((partnum . 2) (type (TEXT . html)) (body (charset UTF-8))
                 (disposition nil) (transfer-encoding QUOTED-PRINTABLE)))) 

Now I need to retrieve the value of “charset” ; The first one if any. In this very configuration, it’s easy:

(car (cdr (cadr (third (car my-list)))))
   => UTF-8

But this is when I know exactly where the “body” cell is.

I tried to use mapcar recursively like this :

(defun search-rec (list)
  (mapcar
     (lambda (x)
       (if (listp x)
           (search-rec x)
         (message "OY %s" x)))
     list))

but every time, I get the error (wrong-type-argument listp 1) when the recursion hits the first atom of the first cons cell. I guess my question really is what it is :

How can I search in a list?

EDIT Now the list looks like this, “charset” is still in (body) (told you that was about the only constant thing) and it’s no longer found 🙁

(setq my-list '(((partnum . 1)
                (1.1 (type (TEXT . plain)) (body (charset UTF-8))
                     (disposition nil) (transfer-encoding 7BIT))
                (1.2 (type (TEXT . html)) (body (charset UTF-8))
                     (disposition nil) (transfer-encoding 7BIT))
                (type . alternative) (body (boundary e89a8fb2067eba300404c63c5f7f))
                (disposition nil) (transfer-encoding nil))
               ((partnum . 1.1) (type (TEXT . plain)) (body (charset UTF-8))
                (disposition nil) (transfer-encoding 7BIT))
               ((partnum . 1.2) (type (TEXT . html)) (body (charset UTF-8))
                (disposition nil) (transfer-encoding 7BIT))
               ((partnum . 2) (type (IMAGE . x-xpixmap)) (body (name ladybug.xpm))
                (disposition nil) (transfer-encoding BASE64))))

EDIT here is some more IRL example:

    (setq my-list haystack-list)
    (setq my-needle (tree-assoc 'charset my-list))
    (message "
-------------\n
- my-list: %s\n
- my-needle: %s\n
-------------\n" my-list my-needle)

Produces:


  • my-list: ((TEXT plain (charset UTF-8) nil nil 7BIT 260 18 nil nil nil) (TEXT html (charset UTF-8) nil nil QUOTED-PRINTABLE 738 17 nil nil nil) alternative (boundary e89a8fb1f8061a6be404c70a24a0) nil nil)

  • my-needle: nil


When on the other hand:

(tree-assoc 'charset '((TEXT plain (charset UTF-8) nil nil 7BIT 260 18 nil nil nil)
(TEXT html (charset UTF-8) nil nil QUOTED-PRINTABLE 738 17 nil nil nil) 
alternative (boundary e89a8fb1f8061a6be404c70a24a0) nil nil))
  =>(charset UTF-8)

So really, I don’t know what’s going on here : One could argue “what is this haystack-list and where does it come from?” But is it relevant ? I’m working on a copy (my-list) of this haystack-list so what gives those different results ? The quoting of the list ? Guys, I’m really lost

NB (This behaviour (Works in a direct eval, but not in a defun/let production situation) occurred with all the solution given)

EDIT: I ended up extracting the first list found, and then extracting (not searching) elements from that list. I proved faster ; Of course this is when you can say “my element is always in the fist list found) ; thanks to everybody, I learned a lot through all this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:01:58+00:00Added an answer on June 9, 2026 at 2:01 pm

    It looks like you want the tree analog of Association Lists. By following the conventions of the assoc function, which retrieves the list element that contains the given key as its head, here is a version of assoc that works on tree:

    (defun tree-assoc (key tree)
      (when (consp tree)
        (destructuring-bind (x . y)  tree
          (if (eql x key) tree
            (or (tree-assoc key x) (tree-assoc key y))))))
    

    Example:

    (let ((my-list '(((partnum . 1)
                      (1.1 (type (TEXT . plain)) (body (charset UTF-8))
                       (disposition nil) (transfer-encoding 7BIT))
                      (1.2 (type (TEXT . html)) (body (charset UTF-8))
                       (disposition nil) (transfer-encoding 7BIT))
                      (type . alternative) (body (boundary e89a8fb2067eba300404c63c5f7f))
                      (disposition nil) (transfer-encoding nil))
                     ((partnum . 1.1) (type (TEXT . plain)) (body (charset UTF-8))
                      (disposition nil) (transfer-encoding 7BIT))
                     ((partnum . 1.2) (type (TEXT . html)) (body (charset UTF-8))
                      (disposition nil) (transfer-encoding 7BIT))
                     ((partnum . 2) (type (IMAGE . x-xpixmap)) (body (name ladybug.xpm))
                      (disposition nil) (transfer-encoding BASE64)))))
      (tree-assoc 'charset my-list))
    
    => (charset UTF-8)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to locate a command line tool that would allow me to write
I need to locate rows in a database table that have a field with
I am trying to locate a particular project by a custom field value. So
I need to compare particular content of 2 SQL tables located in different servers:
I need to locate 2 tags in a lump of text and keep whatever
I need some images as input for my tests. Where to locate the files
Update I want to have an expression (XPath, or Regex Expression, similar) that can
I have a time in millis and I need to display that to the
So I've been trying to read this particular .mat file into R. I don't
When adding a new web application on IIS 7.5, I need to locate my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.