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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:23:19+00:00 2026-06-14T11:23:19+00:00

I am a total newbie to clojure and trying to follow some tutorials basically.

  • 0

I am a total newbie to clojure and trying to follow some tutorials basically. I have a question about defrecords.

Here is the thing that I am trying to do :

(defrecord somemap [key1 key2 key3 key4])

(defn give-me-map [m1 m2]
  (somemap. m1 m2))

On the code above, i would like to have key3 and key4 as optional, so that i wont need to give values to them each time a create a somemap object.

there is a similar question here, but it does the reverse of what i am trying to do here.

So the is it possible to define defrecord with optional fields?

  • 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-14T11:23:21+00:00Added an answer on June 14, 2026 at 11:23 am

    When you use (defrecord T [...]), two factory functions are created: ->T and map->T.

    The first uses the positional parameters as keys. The second applies an arbitrary map to the record.

    You can keep key3 and key4 in the constructor and use map->somemap.

    (defrecord somemap [key1 key2 key3 key4])
    
    (defn give-me-map
      [key1 key2]
      (map->somemap {:key1 key1 :key2 key2}))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Total newbie question here; I apologize in advance. Suppose I have a daemon written
Total newbie question here...Today while trying to calculate sum of a list of integers(actually
I am a total newbie in servers/hosting etc, although I have some experience in
first of all, sorry if that question is dumb but I´m a total newbie
Total newbie question now... Suffice to say, I have searched for a completely noddy
Total newbie to R here (so far very pleased!). I have a large array(vector?)
A total newbie question, so please bear with me here ;) When a key
total newbie here. i was trying to replace a character in char * but
again a total newbie question from me about Haskell, and Leskah. (First, a subjective
Total newbie question about XNA (probably 3D in general). When I render a simple

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.