Right way to change a value on a map on clojure2019 Community Moderator ElectionScala vs. Groovy vs. ClojureMapping a function on the values of a map in ClojureClojure - Map through all levelsTransforming a map with a map of functions in clojureIn clojure, why does assoc require arguments in addition to a map, but dissoc not?Clojure: treat multiple arguments to < and +Clojure deep-merge to ignore nil valuesClojure: iterate over map of setsIncrementing Values in Clojure MapException using map and anonymous functions in Clojure

What is the significance behind "40 days" that often appears in the Bible?

Knife as defense against stray dogs

Fewest number of steps to reach 200 using special calculator

How is the partial sum of a geometric sequence calculated?

Turning a hard to access nut?

Right piano pedal is bright

Relation between independence and correlation of uniform random variables

I seem to dance, I am not a dancer. Who am I?

Print a physical multiplication table

Can a medieval gyroplane be built?

Bash - pair each line of file

Light propagating through a sound wave

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Should I be concerned about student access to a test bank?

What does "mu" mean as an interjection?

Should I use acronyms in dialogues before telling the readers what it stands for in fiction?

두음법칙 - When did North and South diverge in pronunciation of initial ㄹ?

Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?

Probably overheated black color SMD pads

What does Jesus mean regarding "Raca," and "you fool?" - is he contrasting them?

Describing a chess game in a novel

HP P840 HDD RAID 5 many strange drive failures

What are substitutions for coconut in curry?

When did antialiasing start being available?



Right way to change a value on a map on clojure



2019 Community Moderator ElectionScala vs. Groovy vs. ClojureMapping a function on the values of a map in ClojureClojure - Map through all levelsTransforming a map with a map of functions in clojureIn clojure, why does assoc require arguments in addition to a map, but dissoc not?Clojure: treat multiple arguments to < and +Clojure deep-merge to ignore nil valuesClojure: iterate over map of setsIncrementing Values in Clojure MapException using map and anonymous functions in Clojure










0















Alright, I'm new to clojure, this should be easy but for the life of me I can't find the answer



Let's say I have this map



(def mymap :a 10 :b 15)


Now I want to change the value of :a to 5. I don't know how to do this properly



I know update and assoc can make changes but they both receive a function as last argument, which applies to the value. I don't want that, I don't want any function to run, I just want to simply set :a to 5.



I think I can pass an anonymous function that simply returns 5 and ignores the arg, but is this the right way? Doesn't look good to me



(update mymap :a (fn [arg] 5))










share|improve this question

















  • 1





    assoc is what you're looking for; no last-arg function. clojuredocs.org/clojure.core/assoc

    – Micah Elliott
    Mar 6 at 22:19






  • 1





    assoc does not take a function - (assoc mymap :a 5).

    – Lee
    Mar 6 at 22:46















0















Alright, I'm new to clojure, this should be easy but for the life of me I can't find the answer



Let's say I have this map



(def mymap :a 10 :b 15)


Now I want to change the value of :a to 5. I don't know how to do this properly



I know update and assoc can make changes but they both receive a function as last argument, which applies to the value. I don't want that, I don't want any function to run, I just want to simply set :a to 5.



I think I can pass an anonymous function that simply returns 5 and ignores the arg, but is this the right way? Doesn't look good to me



(update mymap :a (fn [arg] 5))










share|improve this question

















  • 1





    assoc is what you're looking for; no last-arg function. clojuredocs.org/clojure.core/assoc

    – Micah Elliott
    Mar 6 at 22:19






  • 1





    assoc does not take a function - (assoc mymap :a 5).

    – Lee
    Mar 6 at 22:46













0












0








0








Alright, I'm new to clojure, this should be easy but for the life of me I can't find the answer



Let's say I have this map



(def mymap :a 10 :b 15)


Now I want to change the value of :a to 5. I don't know how to do this properly



I know update and assoc can make changes but they both receive a function as last argument, which applies to the value. I don't want that, I don't want any function to run, I just want to simply set :a to 5.



I think I can pass an anonymous function that simply returns 5 and ignores the arg, but is this the right way? Doesn't look good to me



(update mymap :a (fn [arg] 5))










share|improve this question














Alright, I'm new to clojure, this should be easy but for the life of me I can't find the answer



Let's say I have this map



(def mymap :a 10 :b 15)


Now I want to change the value of :a to 5. I don't know how to do this properly



I know update and assoc can make changes but they both receive a function as last argument, which applies to the value. I don't want that, I don't want any function to run, I just want to simply set :a to 5.



I think I can pass an anonymous function that simply returns 5 and ignores the arg, but is this the right way? Doesn't look good to me



(update mymap :a (fn [arg] 5))







clojure






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 6 at 22:04









GBarrosoGBarroso

147112




147112







  • 1





    assoc is what you're looking for; no last-arg function. clojuredocs.org/clojure.core/assoc

    – Micah Elliott
    Mar 6 at 22:19






  • 1





    assoc does not take a function - (assoc mymap :a 5).

    – Lee
    Mar 6 at 22:46












  • 1





    assoc is what you're looking for; no last-arg function. clojuredocs.org/clojure.core/assoc

    – Micah Elliott
    Mar 6 at 22:19






  • 1





    assoc does not take a function - (assoc mymap :a 5).

    – Lee
    Mar 6 at 22:46







1




1





assoc is what you're looking for; no last-arg function. clojuredocs.org/clojure.core/assoc

– Micah Elliott
Mar 6 at 22:19





assoc is what you're looking for; no last-arg function. clojuredocs.org/clojure.core/assoc

– Micah Elliott
Mar 6 at 22:19




1




1





assoc does not take a function - (assoc mymap :a 5).

– Lee
Mar 6 at 22:46





assoc does not take a function - (assoc mymap :a 5).

– Lee
Mar 6 at 22:46












1 Answer
1






active

oldest

votes


















4














assoc does not take a function as its last argument; unless you were wanting to associate a function with a key in the map. (assoc mymap :a 5) does what you want.



I'll add though, update, which does take a function, could be used here as well when combined with constantly or just another function (although there's no reason to use it over assoc):



; constantly returns a function that throws away any arguments given to it,
; and "constantly" returns the given value
(update mymap :a (constantly 5))

; Basically the same as above
(update mymap :a (fn [_] 5))





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032898%2fright-way-to-change-a-value-on-a-map-on-clojure%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    assoc does not take a function as its last argument; unless you were wanting to associate a function with a key in the map. (assoc mymap :a 5) does what you want.



    I'll add though, update, which does take a function, could be used here as well when combined with constantly or just another function (although there's no reason to use it over assoc):



    ; constantly returns a function that throws away any arguments given to it,
    ; and "constantly" returns the given value
    (update mymap :a (constantly 5))

    ; Basically the same as above
    (update mymap :a (fn [_] 5))





    share|improve this answer





























      4














      assoc does not take a function as its last argument; unless you were wanting to associate a function with a key in the map. (assoc mymap :a 5) does what you want.



      I'll add though, update, which does take a function, could be used here as well when combined with constantly or just another function (although there's no reason to use it over assoc):



      ; constantly returns a function that throws away any arguments given to it,
      ; and "constantly" returns the given value
      (update mymap :a (constantly 5))

      ; Basically the same as above
      (update mymap :a (fn [_] 5))





      share|improve this answer



























        4












        4








        4







        assoc does not take a function as its last argument; unless you were wanting to associate a function with a key in the map. (assoc mymap :a 5) does what you want.



        I'll add though, update, which does take a function, could be used here as well when combined with constantly or just another function (although there's no reason to use it over assoc):



        ; constantly returns a function that throws away any arguments given to it,
        ; and "constantly" returns the given value
        (update mymap :a (constantly 5))

        ; Basically the same as above
        (update mymap :a (fn [_] 5))





        share|improve this answer















        assoc does not take a function as its last argument; unless you were wanting to associate a function with a key in the map. (assoc mymap :a 5) does what you want.



        I'll add though, update, which does take a function, could be used here as well when combined with constantly or just another function (although there's no reason to use it over assoc):



        ; constantly returns a function that throws away any arguments given to it,
        ; and "constantly" returns the given value
        (update mymap :a (constantly 5))

        ; Basically the same as above
        (update mymap :a (fn [_] 5))






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 7 at 4:33

























        answered Mar 6 at 22:54









        CarcigenicateCarcigenicate

        18.2k43262




        18.2k43262





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032898%2fright-way-to-change-a-value-on-a-map-on-clojure%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved