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 8282907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:32:52+00:00 2026-06-08T10:32:52+00:00

Today I’ve seen some references to tying the knot and circular data structures. I’ve

  • 0

Today I’ve seen some references to tying the knot and circular data structures. I’ve been out reading some answers, and the solutions seem to involve using a ref to point back to the head of the list. One particular SO question showed a Haskell example, but I don’t know Haskell well enough to know if the example was using a the Haskell equivalent of a ref.

Is there a way to make a Clojure data structure circular without using a ref or similar construct?

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. Editorial Team
    Editorial Team
    2026-06-08T10:32:54+00:00Added an answer on June 8, 2026 at 10:32 am

    I straightforwardly translated the Haskell example into Clojure:

    user> (def alternates
              (letfn [(x [] (lazy-seq (cons 0 (y))))
                      (y [] (lazy-seq (cons 1 (x))))]
                (x)))
    #'user/alternates
    user> (take 7 alternates)
    (0 1 0 1 0 1 0)
    

    It works as expected. However I prefer the cycle function to mutually recursive functions using letfn:

    user> (take 7 (cycle [0 1]))
    (0 1 0 1 0 1 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, I was reading about structures in Let Us C (on Goodreads ). I
Today I was reading code from some very popular numerical libraries written in FORTRAN
Today I was reading Floyd's algorithm of detecting loop in a linked list. I
Today i have a little problem containing a File Upload. First some Infos: Rubyversion:
Today we have received some strange exceptions on our production website. They all have
Today, while I was randomly reading the JavaScript patterns O'Reilly book, I found one
Today I made some tests and I am curious of the results. I made
Today, reading Servlet 3.0 specification, I've come across a sentence: We emphasize that this
Today I am trying to remove some bytes from an EXE file. Inside the
Today I wanted to write a simple php script, but I got some annoying

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.