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

  • Home
  • SEARCH
  • 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 103411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:07:11+00:00 2026-05-11T01:07:11+00:00

I have a list that looks like (A (B (C D)) (E (F))) which

  • 0

I have a list that looks like (A (B (C D)) (E (F))) which represents this tree:

      A     /  \   B      E  / \    / C   D  F 

How do I print it as (A B E C D F) ?

This is as far as I managed:

((lambda(tree) (loop for ele in tree do (print ele))) my-list) 

But it prints:

A (B (C D)) (E (F)) NIL 

I’m pretty new to Common LISP so there may be functions that I should’ve used. If that’s the case then enlight me.

Thanks.

  • 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. 2026-05-11T01:07:12+00:00Added an answer on May 11, 2026 at 1:07 am

    Taking your question at face value, you want to print out the nodes in ‘breadth-first’ order, rather than using one of the standard, depth-first orderings: ‘in-order’ or ‘pre-order’ or ‘post-order’.

    • in-order: C B D A E F
    • pre-order: A B C D E F
    • post-order: C D B F E A

    • requested order: A B E C D F

    In your tree structure, each element can be either an atom, or a list with one element, or a list with two elements. The first element of a list is always an atom.

    What I think the pseudo-code needs to look like is approximately:

    Given a list 'remains-of-tree':     Create empty 'next-level' list     Foreach item in `remains-of-tree`         Print the CAR of `remains-of-tree`         If the CDR of `remains-of-tree` is not empty              CONS the first item onto 'next-level'              If there is a second item, CONS that onto `next-level`     Recurse, passing `next-level` as argument. 

    I’m 100% sure that can be cleaned up (that looks like trivial tail recursion, all else apart). However, I think it works.

    Start: (A (B (C D)) (E (F))) Level 1: Print CAR: A Add (B (C D)) to next-level: ((B (C D))) Add (E (F)) to next-level: ((B (C D)) (E (F))) Pass ((B (C D) (E (F))) to level 2: Level 2: Item 1 is (B (C D)) Print CAR: B Push C to next-level: (C) Push D to next-level: (C D) Item 2 is (E (F)) Print CAR: E Push F to next-level: (C D F) Pass (C D F) to level 3: Level 3: Item 1 is C Print CAR: C Item 2 is D Print CAR: D Item 3 is F Print CAR: F 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 106k
  • Answers 106k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the lxml.etree.Comment() factory function. It will return… May 11, 2026 at 8:56 pm
  • Editorial Team
    Editorial Team added an answer Call field.GetValue(Nothing) and it'll be fine. You don't need an… May 11, 2026 at 8:56 pm
  • Editorial Team
    Editorial Team added an answer Replace showOn: 'focus' with showOn: 'button' This will make the… May 11, 2026 at 8:56 pm

Related Questions

I'm new to Django and so far I like it a lot but I've
I have the following entity structure: Business --> Campaign --> Promotion, where ONE Business
I would like to write a plug-in that will allow a custom written CRM
I used this CSS to make my ULs look fancy ul, li { padding:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.