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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:59:53+00:00 2026-05-13T05:59:53+00:00

Thanks a lot for all the beautiful answers! Cannot mark just one as correct

  • 0

Thanks a lot for all the beautiful answers! Cannot mark just one as correct

Note: Already a wiki

I am new to functional programming and while I can read simple functions in Functional programming, for e.g. computing the factorial of a number, I am finding it hard to read big functions.
Part of the reason is I think because of my inability to figure out the smaller blocks of code within a function definition and also partly because it is becoming difficult for me to match ( ) in code.

It would be great if someone could walk me through reading some code and give me some tips on how to quickly decipher some code.

Note: I can understand this code if I stare at it for 10 minutes, but I doubt if this same code had been written in Java, it would take me 10 minutes. So, I think to feel comfortable in Lisp style code, I must do it faster

Note: I know this is a subjective question. And I am not seeking any provably correct answer here. Just comments on how you go about reading this code, would be welcome and highly helpful

(defn concat
  ([] (lazy-seq nil))
  ([x] (lazy-seq x))
  ([x y]
    (lazy-seq
      (let [s (seq x)]
        (if s
          (if (chunked-seq? s)
            (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
            (cons (first s) (concat (rest s) y)))
          y))))
  ([x y & zs]
     (let [cat (fn cat [xys zs]
                 (lazy-seq
                   (let [xys (seq xys)]
                     (if xys
                       (if (chunked-seq? xys)
                         (chunk-cons (chunk-first xys)
                                     (cat (chunk-rest xys) zs))
                         (cons (first xys) (cat (rest xys) zs)))
                       (when zs
                         (cat (first zs) (next zs)))))))]
       (cat (concat x y) zs))))
  • 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-05-13T05:59:53+00:00Added an answer on May 13, 2026 at 5:59 am

    Lisp code, in particular, is even harder to read than other functional languages because of the regular syntax. Wojciech gives a good answer for improving your semantic understanding. Here is some help on syntax.

    First, when reading code, don’t worry about parentheses. Worry about indentation. The general rule is that things at the same indent level are related. So:

          (if (chunked-seq? s)
            (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
            (cons (first s) (concat (rest s) y)))
    

    Second, if you can’t fit everything on one line, indent the next line a small amount. This is almost always two spaces:

    (defn concat
      ([] (lazy-seq nil))  ; these two fit
      ([x] (lazy-seq x))   ; so no wrapping
      ([x y]               ; but here
        (lazy-seq          ; (lazy-seq indents two spaces
          (let [s (seq x)] ; as does (let [s (seq x)]
    

    Third, if multiple arguments to a function can’t fit on a single line, line up the second, third, etc arguments underneath the first’s starting parenthesis. Many macros have a similar rule with variations to allow the important parts to appear first.

    ; fits on one line
    (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
    
    ; has to wrap: line up (cat ...) underneath first ( of (chunk-first xys)
                         (chunk-cons (chunk-first xys)
                                     (cat (chunk-rest xys) zs))
    
    ; if you write a C-for macro, put the first three arguments on one line
    ; then the rest indented two spaces
    (c-for (i 0) (< i 100) (add1 i)
      (side-effects!)
      (side-effects!)
      (get-your (side-effects!) here))
    

    These rules help you find blocks within the code: if you see

    (chunk-cons (chunk-first s)
    

    Don’t count parentheses! Check the next line:

    (chunk-cons (chunk-first s)
                (concat (chunk-rest s) y))
    

    You know that the first line is not a complete expression because the next line is indented beneath it.

    If you see the defn concat from above, you know you have three blocks, because there are three things on the same level. But everything below the third line is indented beneath it, so the rest belongs to that third block.

    Here is a style guide for Scheme. I don’t know Clojure, but most of the rules should be the same since none of the other Lisps vary much.

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

Sidebar

Related Questions

EDIT: thanks a lot for all the answers an points raised. As a novice
How to delete all cache in JavaScript? Thanks a lot.
This problem has been solved! Thanks a lot to Brad, Denis and junkie! You're
How to explicitly set django_language in Django session? Thanks a lot...
I am done with my first iphone app (SO helps a lot..thanks). Now i
Problem fixed! Thanks a lot for the constructive suggestions! I am unable to figure
Ok guys, we all know there are all lot of typedef/struct questions out there,
I wrote a script (.js) which should copy all text from one file to
Thanks for the help on here with my query on here the other day
Thanks for stopping by. this static analyser warning is annoying me here is 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.