Meaning of # in clojureScala vs. Groovy vs. ClojureClojure - named argumentsNon tail-recursive anonymous functions in ClojureHow to make a Clojure function take a variable number of parameters?Clojure vector as function parameterClojure join fails to create a string from the result of filter functionclojure assoc-if and assoc-if-newhow to split a string in clojure not in regular expression modeHow to split string at fixed numbers of character in clojure?How to split string with defining multiple regular expression in clojure?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

Why electric field inside a cavity of a non-conducting sphere not zero?

Yosemite Fire Rings - What to Expect?

Drawing ramified coverings with tikz

On a tidally locked planet, would time be quantized?

How do I find all files that end with a dot

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Biological Blimps: Propulsion

How could a planet have erratic days?

What should you do if you miss a job interview (deliberately)?

WiFi Thermostat, No C Terminal on Furnace

What was this official D&D 3.5e Lovecraft-flavored rulebook?

copy and scale one figure (wheel)

Freedom of speech and where it applies

Why did the Mercure fail?

How much character growth crosses the line into breaking the character

Energy measurement from position eigenstate

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

Is it safe to use olive oil to clean the ear wax?

Loading commands from file

Not using 's' for he/she/it

The screen of my macbook suddenly broken down how can I do to recover

What if a revenant (monster) gains fire resistance?

"Spoil" vs "Ruin"



Meaning of # in clojure


Scala vs. Groovy vs. ClojureClojure - named argumentsNon tail-recursive anonymous functions in ClojureHow to make a Clojure function take a variable number of parameters?Clojure vector as function parameterClojure join fails to create a string from the result of filter functionclojure assoc-if and assoc-if-newhow to split a string in clojure not in regular expression modeHow to split string at fixed numbers of character in clojure?How to split string with defining multiple regular expression in clojure?













2















In clojure you can create anonymous functions using #



eg



#(+ % 1) 


is a function that takes in a parameter and adds 1 to it.



But we also have to use # for regex
eg



(clojure.string/split "hi, buddy" #",")


Are these two # related?










share|improve this question


























    2















    In clojure you can create anonymous functions using #



    eg



    #(+ % 1) 


    is a function that takes in a parameter and adds 1 to it.



    But we also have to use # for regex
    eg



    (clojure.string/split "hi, buddy" #",")


    Are these two # related?










    share|improve this question
























      2












      2








      2


      1






      In clojure you can create anonymous functions using #



      eg



      #(+ % 1) 


      is a function that takes in a parameter and adds 1 to it.



      But we also have to use # for regex
      eg



      (clojure.string/split "hi, buddy" #",")


      Are these two # related?










      share|improve this question














      In clojure you can create anonymous functions using #



      eg



      #(+ % 1) 


      is a function that takes in a parameter and adds 1 to it.



      But we also have to use # for regex
      eg



      (clojure.string/split "hi, buddy" #",")


      Are these two # related?







      clojure






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 4:27









      AshwinAshwin

      4,5252282147




      4,5252282147






















          4 Answers
          4






          active

          oldest

          votes


















          7














          There are also sets #, fully qualified class name constructors #my.klass_or_type_or_record[:a :b :c], instants #inst "yyyy-mm-ddThh:mm:ss.fff+hh:mm" and some others.



          They are related in a sence that in these cases # starts a sequence recognisible by clojure reader, which dispatches every such instance to an appropriate reader.There's a guide that expands on this.



          I think this convention exists to reduce the number of different syntaxes to just one and thus simplify the reader.






          share|improve this answer
































            3














            The two uses have no (direct) relationship.



            In Clojure, when you see the # symbol, it is a giant clue that you are "talking" to the Clojure Reader, not to the Clojure Compiler. See the full docs on the Reader here: https://clojure.org/reference/reader.



            The Reader is responsible for converting plain text from a source file into a collection of data structures. For example, comparing Clojure to Java we have



            ; Clojure ; Java
            "Hello" => new String( "Hello" )


            and



            [ "Goodbye" "cruel" "world!" ] ; Clojure vector of 3 strings

            ; Java ArrayList of 3 strings
            var msg = new ArrayList<String>();
            msg.add( "Goodbye" );
            msg.add( "cruel" );
            msg.add( "world!" );


            Similarly, there are shortcuts that the Reader recognizes even within Clojure source code (before the compiler converts it to Java bytecode), just to save you some typing. These "Reader Macros" get converted from your "short form" source code into "standard Clojure" even before the Clojure compiler gets started. For example:



            @my-atom => (deref my-atom) ; not using `#`
            #'map => (var map)
            # 1 2 3 => (hash-set 1 2 3)
            #_(launch-missiles 12.3 45.6) => `` ; i.e. "nothing"
            #(+ 1 %) => (fn [x] (+ 1 x))


            and so on. As the @ or deref operator shows, not all Reader Macros use the # (hash/pound/octothorpe) symbol. Note that, even in the case of a vector literal:



            [ "Goodbye" "cruel" "world!" ]


            the Reader creates a result as if you had typed:



            (vector "Goodbye" "cruel" "world!" )





            share|improve this answer
































              0














              Other Lisps have proper programmable readers, and consequently read macros. Clojure doesn't really have a programmable reader - users cannot easily add new read macros - but the Clojure system does internally use read macros. The # read macro is the dispatch macro, the character following the # being a key into a further read macro table.



              So yes, the # does mean something; but it's so deep and geeky that you do not really need to know this.






              share|improve this answer






























                -1















                Are these two # related?




                No, they aren't. The # literal is used in different ways. Some of them you've already mentioned: these are an anonymous function and a regex pattern. Here are some more cases:



                • Prepending an expression with #_ just wipes it from the compiler as it has never been written. For example: #_(/ 0 0) will be ignored on reader level so none of the exception will appear.


                • Tagging primitives to coerce them to complex types, for example #inst "2019-03-09" will produce an instance of java.util.Date class. There are also #uuid and other built-in tags. You may register your own ones.


                • Tagging ordinary maps to coerce them to types maps, e.g. #project.models/User :name "John" :age 42 will produce a map declared as (defrecord User ...).






                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%2f55056725%2fmeaning-of-in-clojure%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  7














                  There are also sets #, fully qualified class name constructors #my.klass_or_type_or_record[:a :b :c], instants #inst "yyyy-mm-ddThh:mm:ss.fff+hh:mm" and some others.



                  They are related in a sence that in these cases # starts a sequence recognisible by clojure reader, which dispatches every such instance to an appropriate reader.There's a guide that expands on this.



                  I think this convention exists to reduce the number of different syntaxes to just one and thus simplify the reader.






                  share|improve this answer





























                    7














                    There are also sets #, fully qualified class name constructors #my.klass_or_type_or_record[:a :b :c], instants #inst "yyyy-mm-ddThh:mm:ss.fff+hh:mm" and some others.



                    They are related in a sence that in these cases # starts a sequence recognisible by clojure reader, which dispatches every such instance to an appropriate reader.There's a guide that expands on this.



                    I think this convention exists to reduce the number of different syntaxes to just one and thus simplify the reader.






                    share|improve this answer



























                      7












                      7








                      7







                      There are also sets #, fully qualified class name constructors #my.klass_or_type_or_record[:a :b :c], instants #inst "yyyy-mm-ddThh:mm:ss.fff+hh:mm" and some others.



                      They are related in a sence that in these cases # starts a sequence recognisible by clojure reader, which dispatches every such instance to an appropriate reader.There's a guide that expands on this.



                      I think this convention exists to reduce the number of different syntaxes to just one and thus simplify the reader.






                      share|improve this answer















                      There are also sets #, fully qualified class name constructors #my.klass_or_type_or_record[:a :b :c], instants #inst "yyyy-mm-ddThh:mm:ss.fff+hh:mm" and some others.



                      They are related in a sence that in these cases # starts a sequence recognisible by clojure reader, which dispatches every such instance to an appropriate reader.There's a guide that expands on this.



                      I think this convention exists to reduce the number of different syntaxes to just one and thus simplify the reader.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 8 at 12:18









                      l0st3d

                      2,03212028




                      2,03212028










                      answered Mar 8 at 5:26









                      akondakond

                      12.5k32849




                      12.5k32849























                          3














                          The two uses have no (direct) relationship.



                          In Clojure, when you see the # symbol, it is a giant clue that you are "talking" to the Clojure Reader, not to the Clojure Compiler. See the full docs on the Reader here: https://clojure.org/reference/reader.



                          The Reader is responsible for converting plain text from a source file into a collection of data structures. For example, comparing Clojure to Java we have



                          ; Clojure ; Java
                          "Hello" => new String( "Hello" )


                          and



                          [ "Goodbye" "cruel" "world!" ] ; Clojure vector of 3 strings

                          ; Java ArrayList of 3 strings
                          var msg = new ArrayList<String>();
                          msg.add( "Goodbye" );
                          msg.add( "cruel" );
                          msg.add( "world!" );


                          Similarly, there are shortcuts that the Reader recognizes even within Clojure source code (before the compiler converts it to Java bytecode), just to save you some typing. These "Reader Macros" get converted from your "short form" source code into "standard Clojure" even before the Clojure compiler gets started. For example:



                          @my-atom => (deref my-atom) ; not using `#`
                          #'map => (var map)
                          # 1 2 3 => (hash-set 1 2 3)
                          #_(launch-missiles 12.3 45.6) => `` ; i.e. "nothing"
                          #(+ 1 %) => (fn [x] (+ 1 x))


                          and so on. As the @ or deref operator shows, not all Reader Macros use the # (hash/pound/octothorpe) symbol. Note that, even in the case of a vector literal:



                          [ "Goodbye" "cruel" "world!" ]


                          the Reader creates a result as if you had typed:



                          (vector "Goodbye" "cruel" "world!" )





                          share|improve this answer





























                            3














                            The two uses have no (direct) relationship.



                            In Clojure, when you see the # symbol, it is a giant clue that you are "talking" to the Clojure Reader, not to the Clojure Compiler. See the full docs on the Reader here: https://clojure.org/reference/reader.



                            The Reader is responsible for converting plain text from a source file into a collection of data structures. For example, comparing Clojure to Java we have



                            ; Clojure ; Java
                            "Hello" => new String( "Hello" )


                            and



                            [ "Goodbye" "cruel" "world!" ] ; Clojure vector of 3 strings

                            ; Java ArrayList of 3 strings
                            var msg = new ArrayList<String>();
                            msg.add( "Goodbye" );
                            msg.add( "cruel" );
                            msg.add( "world!" );


                            Similarly, there are shortcuts that the Reader recognizes even within Clojure source code (before the compiler converts it to Java bytecode), just to save you some typing. These "Reader Macros" get converted from your "short form" source code into "standard Clojure" even before the Clojure compiler gets started. For example:



                            @my-atom => (deref my-atom) ; not using `#`
                            #'map => (var map)
                            # 1 2 3 => (hash-set 1 2 3)
                            #_(launch-missiles 12.3 45.6) => `` ; i.e. "nothing"
                            #(+ 1 %) => (fn [x] (+ 1 x))


                            and so on. As the @ or deref operator shows, not all Reader Macros use the # (hash/pound/octothorpe) symbol. Note that, even in the case of a vector literal:



                            [ "Goodbye" "cruel" "world!" ]


                            the Reader creates a result as if you had typed:



                            (vector "Goodbye" "cruel" "world!" )





                            share|improve this answer



























                              3












                              3








                              3







                              The two uses have no (direct) relationship.



                              In Clojure, when you see the # symbol, it is a giant clue that you are "talking" to the Clojure Reader, not to the Clojure Compiler. See the full docs on the Reader here: https://clojure.org/reference/reader.



                              The Reader is responsible for converting plain text from a source file into a collection of data structures. For example, comparing Clojure to Java we have



                              ; Clojure ; Java
                              "Hello" => new String( "Hello" )


                              and



                              [ "Goodbye" "cruel" "world!" ] ; Clojure vector of 3 strings

                              ; Java ArrayList of 3 strings
                              var msg = new ArrayList<String>();
                              msg.add( "Goodbye" );
                              msg.add( "cruel" );
                              msg.add( "world!" );


                              Similarly, there are shortcuts that the Reader recognizes even within Clojure source code (before the compiler converts it to Java bytecode), just to save you some typing. These "Reader Macros" get converted from your "short form" source code into "standard Clojure" even before the Clojure compiler gets started. For example:



                              @my-atom => (deref my-atom) ; not using `#`
                              #'map => (var map)
                              # 1 2 3 => (hash-set 1 2 3)
                              #_(launch-missiles 12.3 45.6) => `` ; i.e. "nothing"
                              #(+ 1 %) => (fn [x] (+ 1 x))


                              and so on. As the @ or deref operator shows, not all Reader Macros use the # (hash/pound/octothorpe) symbol. Note that, even in the case of a vector literal:



                              [ "Goodbye" "cruel" "world!" ]


                              the Reader creates a result as if you had typed:



                              (vector "Goodbye" "cruel" "world!" )





                              share|improve this answer















                              The two uses have no (direct) relationship.



                              In Clojure, when you see the # symbol, it is a giant clue that you are "talking" to the Clojure Reader, not to the Clojure Compiler. See the full docs on the Reader here: https://clojure.org/reference/reader.



                              The Reader is responsible for converting plain text from a source file into a collection of data structures. For example, comparing Clojure to Java we have



                              ; Clojure ; Java
                              "Hello" => new String( "Hello" )


                              and



                              [ "Goodbye" "cruel" "world!" ] ; Clojure vector of 3 strings

                              ; Java ArrayList of 3 strings
                              var msg = new ArrayList<String>();
                              msg.add( "Goodbye" );
                              msg.add( "cruel" );
                              msg.add( "world!" );


                              Similarly, there are shortcuts that the Reader recognizes even within Clojure source code (before the compiler converts it to Java bytecode), just to save you some typing. These "Reader Macros" get converted from your "short form" source code into "standard Clojure" even before the Clojure compiler gets started. For example:



                              @my-atom => (deref my-atom) ; not using `#`
                              #'map => (var map)
                              # 1 2 3 => (hash-set 1 2 3)
                              #_(launch-missiles 12.3 45.6) => `` ; i.e. "nothing"
                              #(+ 1 %) => (fn [x] (+ 1 x))


                              and so on. As the @ or deref operator shows, not all Reader Macros use the # (hash/pound/octothorpe) symbol. Note that, even in the case of a vector literal:



                              [ "Goodbye" "cruel" "world!" ]


                              the Reader creates a result as if you had typed:



                              (vector "Goodbye" "cruel" "world!" )






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Mar 8 at 20:13

























                              answered Mar 8 at 15:10









                              Alan ThompsonAlan Thompson

                              14.2k22534




                              14.2k22534





















                                  0














                                  Other Lisps have proper programmable readers, and consequently read macros. Clojure doesn't really have a programmable reader - users cannot easily add new read macros - but the Clojure system does internally use read macros. The # read macro is the dispatch macro, the character following the # being a key into a further read macro table.



                                  So yes, the # does mean something; but it's so deep and geeky that you do not really need to know this.






                                  share|improve this answer



























                                    0














                                    Other Lisps have proper programmable readers, and consequently read macros. Clojure doesn't really have a programmable reader - users cannot easily add new read macros - but the Clojure system does internally use read macros. The # read macro is the dispatch macro, the character following the # being a key into a further read macro table.



                                    So yes, the # does mean something; but it's so deep and geeky that you do not really need to know this.






                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      Other Lisps have proper programmable readers, and consequently read macros. Clojure doesn't really have a programmable reader - users cannot easily add new read macros - but the Clojure system does internally use read macros. The # read macro is the dispatch macro, the character following the # being a key into a further read macro table.



                                      So yes, the # does mean something; but it's so deep and geeky that you do not really need to know this.






                                      share|improve this answer













                                      Other Lisps have proper programmable readers, and consequently read macros. Clojure doesn't really have a programmable reader - users cannot easily add new read macros - but the Clojure system does internally use read macros. The # read macro is the dispatch macro, the character following the # being a key into a further read macro table.



                                      So yes, the # does mean something; but it's so deep and geeky that you do not really need to know this.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 10 at 17:55









                                      Simon BrookeSimon Brooke

                                      10336




                                      10336





















                                          -1















                                          Are these two # related?




                                          No, they aren't. The # literal is used in different ways. Some of them you've already mentioned: these are an anonymous function and a regex pattern. Here are some more cases:



                                          • Prepending an expression with #_ just wipes it from the compiler as it has never been written. For example: #_(/ 0 0) will be ignored on reader level so none of the exception will appear.


                                          • Tagging primitives to coerce them to complex types, for example #inst "2019-03-09" will produce an instance of java.util.Date class. There are also #uuid and other built-in tags. You may register your own ones.


                                          • Tagging ordinary maps to coerce them to types maps, e.g. #project.models/User :name "John" :age 42 will produce a map declared as (defrecord User ...).






                                          share|improve this answer



























                                            -1















                                            Are these two # related?




                                            No, they aren't. The # literal is used in different ways. Some of them you've already mentioned: these are an anonymous function and a regex pattern. Here are some more cases:



                                            • Prepending an expression with #_ just wipes it from the compiler as it has never been written. For example: #_(/ 0 0) will be ignored on reader level so none of the exception will appear.


                                            • Tagging primitives to coerce them to complex types, for example #inst "2019-03-09" will produce an instance of java.util.Date class. There are also #uuid and other built-in tags. You may register your own ones.


                                            • Tagging ordinary maps to coerce them to types maps, e.g. #project.models/User :name "John" :age 42 will produce a map declared as (defrecord User ...).






                                            share|improve this answer

























                                              -1












                                              -1








                                              -1








                                              Are these two # related?




                                              No, they aren't. The # literal is used in different ways. Some of them you've already mentioned: these are an anonymous function and a regex pattern. Here are some more cases:



                                              • Prepending an expression with #_ just wipes it from the compiler as it has never been written. For example: #_(/ 0 0) will be ignored on reader level so none of the exception will appear.


                                              • Tagging primitives to coerce them to complex types, for example #inst "2019-03-09" will produce an instance of java.util.Date class. There are also #uuid and other built-in tags. You may register your own ones.


                                              • Tagging ordinary maps to coerce them to types maps, e.g. #project.models/User :name "John" :age 42 will produce a map declared as (defrecord User ...).






                                              share|improve this answer














                                              Are these two # related?




                                              No, they aren't. The # literal is used in different ways. Some of them you've already mentioned: these are an anonymous function and a regex pattern. Here are some more cases:



                                              • Prepending an expression with #_ just wipes it from the compiler as it has never been written. For example: #_(/ 0 0) will be ignored on reader level so none of the exception will appear.


                                              • Tagging primitives to coerce them to complex types, for example #inst "2019-03-09" will produce an instance of java.util.Date class. There are also #uuid and other built-in tags. You may register your own ones.


                                              • Tagging ordinary maps to coerce them to types maps, e.g. #project.models/User :name "John" :age 42 will produce a map declared as (defrecord User ...).







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 8 at 8:11









                                              Ivan GrishaevIvan Grishaev

                                              1,041611




                                              1,041611



























                                                  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%2f55056725%2fmeaning-of-in-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

                                                  Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                                  2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                                                  Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme