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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:34:00+00:00 2026-05-26T05:34:00+00:00

I define a function, which takes two parameters – map and a key. The

  • 0

I define a function, which takes two parameters – map and a key. The key is referenced from the map parameter decomposition

(defn myfunc [{v k} k]
   v)

when I call:

  (myfunc {:a 10} :a)

It surprisingly produces expected result: 10

Similar thing in the let:

(let [{v k} {:a 10} k :a] v)

fails, because k is not defined at the moment, when first part is evaluated.

My question is: why decomposition inside function parameters behaves differently compared to decomposition in let expressions?

  • 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-26T05:34:01+00:00Added an answer on May 26, 2026 at 5:34 am

    Macroexpanding the defn form I get the equivalent of this (removed .withMeta stuff and reformatted):

    (def myfunc
      (fn* myfunc
           ([p__11393 k]
              (let* [map__11394 p__11393
                     map__11394 (if (seq? map__11394)
                                  (apply hash-map map__11394)
                                  map__11394)
                     v          (get map__11394 k)]
                    v))))
    

    So here we can see that the {v k} map is in fact first assigned to a local variable p__11393. Then the if statement tests if that variable is in fact a sequence and turns it into a hash-map if so, otherwise leaves it as it is. Importantly, the value assigned to k is looked up in the map after all of this happens, thus this works without error (and also would if :a wasn’t in the map, get returns nil in that case).

    On the other hand macroexpanding the let form I get

    (let*
        [map__11431
      {:a 10}
      map__11431
      (if (seq? map__11431) (apply hash-map map__11431) map__11431)
      v
      (get map__11431 k)
      k
      :a]
      v)
    

    and here we can see that v gets the result of (get map__11431 k), but k isn’t defined at this point yet, hence the error.

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

Sidebar

Related Questions

In Haskell I can easily define a recursive function which takes a value and
I am trying to modify an existing Hill-climb function, which takes two node names
I'm trying to dynamically define functions that call through to another function that takes
Suppose I have a function which takes some form of predicate: void Foo( boost::function<bool(int,int,int)>
I need a function which takes an arbitrary number of arguments (All of the
I have a function which takes in a list of characters and generates the
Is it possible to define a sparse matrix in scipy from a function rather
how would i define a function ptr which points to a function which gives
I am trying to figure out how to define a function that works on
With a class in Python, how do I define a function to print every

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.