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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:59:31+00:00 2026-06-12T12:59:31+00:00

I am working on some Lisp exercises using Clojure. I am trying to work

  • 0

I am working on some Lisp exercises using Clojure. I am trying to work these exercises without taking advantage of vectors and some Clojure functions.

This function

(defn rev-seq
    [s1]
    (concat (pop s1) (list (peek s1))))

puts the first element of a list at the end. I want to call this function as many times as it takes to reverse the list (without calling Clojure’s reverse function).

I am not sure what to use in its place. I have experimented with map, apply, and repeat with no success. I would rather have a way to think differently about this than a straight answer, but I am not asking for a discussion.

  • 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-12T12:59:33+00:00Added an answer on June 12, 2026 at 12:59 pm

    Firstly, I think you’ll need to convert rev-seq to use first/rest rather than peek/pop if you want to work on general sequences – at leas in Clojure 1.4 peek/pop seems to require a PersistentStack:

    (defn rev-seq
      [s1]
      (concat (rest s1) (list (first s1))))
    

    Then you should probably note that applying this function repeatedly will “cycle” a list rather than reversing it. You can see that if you look at the result of a small number of applications using iterate:

    (def s '(1 2 3 4 5 6 7 8 9))
    
    (nth (iterate rev-seq s) 3)
    => (4 5 6 7 8 9 1 2 3)
    

    An option that would work is to reverse with a recursive function:

    (defn reverse-seq [s]
      (concat (reverse (next s)) (list (first s))))
    
    (reverse-seq s)
    => (9 8 7 6 5 4 3 2 1)
    

    Or alternatively you can do a reverse using the technique in clojure.core:

    (defn reverse-seq [s]
      (reduce conj () s))
    
    (reverse-seq s)
    => (9 8 7 6 5 4 3 2 1)
    

    Hope this gives you some ideas!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to hash some strings in a Common Lisp app I'm working on.
I'm working some code that inserts csv rows into an SQLite database using Python.
Whilst working on some generally horrible Javascript code this morning, I came across the
I working with some regular expression matching and I'm trying to figure out how
I was working with a Lisp dialect but also learning some Haskell as well.
Working through some OpenGL-ES tutorials, using the Android emulator. I've gotten up to texture
To set some context, I'm in the process of learning Clojure, and Lisp development
I have some working url with unicode and trying to apply IDNA encoding test
is it possible to get this stuff working(some way to force Objectfactory create instances
I'm trying to pick up Lisp as my new language, and I'm having some

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.