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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:51:52+00:00 2026-05-30T07:51:52+00:00

What is convention for local vars that has same meaning as function argument? If

  • 0

What is convention for local vars that has same meaning as function argument?

If I need local variable that has as its initial state value of function argument (and thus has the same meaning), how should I call it?

As artificial example (that, however, demonstrates quite popular construction in Clojure):

(defn sum [coll]
  (loop [local-coll coll, result 0]
    (if (empty? local-coll)
       result
       (recur (rest local-coll) (+ (first local-coll) result)))))

Here local-coll is initialized to the value of coll initially, and it also holds this meaning during looping. local-coll is definitely not a good name for it, but what is?

In Haskell it is a good style to put quote (') to the end of variable/function name, e.g. var'. In Common Lisp sometimes I saw names ending with asterisk (*). Clojure has same notation for function that duplicate another function meaning but have a bit different semantics (e.g. list*). But this notation is also frequently used in docstrings to indicate that there may be several items of this type (e.g. (methodname [args*] body)* or (try expr* catch-clause* finally-clause?)) and thus can confuse when used for local var names.
Java interop also provides things like defn-, that is names ending with hyphen (-) to indicate private methods in generated classes. So it makes some sense to use hyphen for local (private for a function) variables too (though it seems a bit weird for me).

So, what the way should I go when naming my local variables with the same meaning as function argument?

  • 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-30T07:51:53+00:00Added an answer on May 30, 2026 at 7:51 am

    I think it’s fine to shadow the argument name when you don’t need the original argument any more:

    (defn sum [coll]
      (loop [coll coll, result 0]
        (if (empty? coll)
           result
           (recur (rest coll) (+ (first coll) result)))))
    

    Other variations that I’ve seen are:

    (loop [c colls] ...)
    (loop [coll initial-coll] ...)
    (loop [foo foo-coll] ...)
    (loop [s specs] ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On occasion, my local Rails app loses its connection to MySQL. I get some
Python's convention is that variables are created by first assignment, and trying to read
I have a simple grammar consisting of mixed variables ( $(name) ) and variable-value
Which naming convention do you use for local constants in C# and why? const
I have a variable that indicates the length of time the UI can be
As my app gets bigger I am finding that the same type of entity
What is the universally accepted naming convention for c#? (functions, classes, parameters, local variables,
Regarding, Local variables ... function foo(){var x = 1; ...} ...and Global variables ,
I made a website that uses the Twitter Ruby gem. On local host, I
I have a variable in a package ( rec in this case) that needs

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.