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?
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
add a comment |
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
add a comment |
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
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
clojure
asked Mar 8 at 4:27
AshwinAshwin
4,5252282147
4,5252282147
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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.
add a comment |
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!" )
add a comment |
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.
add a comment |
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 ofjava.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 ...)
.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
edited Mar 8 at 12:18
l0st3d
2,03212028
2,03212028
answered Mar 8 at 5:26
akondakond
12.5k32849
12.5k32849
add a comment |
add a comment |
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!" )
add a comment |
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!" )
add a comment |
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!" )
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!" )
edited Mar 8 at 20:13
answered Mar 8 at 15:10
Alan ThompsonAlan Thompson
14.2k22534
14.2k22534
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 10 at 17:55
Simon BrookeSimon Brooke
10336
10336
add a comment |
add a comment |
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 ofjava.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 ...)
.
add a comment |
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 ofjava.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 ...)
.
add a comment |
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 ofjava.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 ...)
.
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 ofjava.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 ...)
.
answered Mar 8 at 8:11
Ivan GrishaevIvan Grishaev
1,041611
1,041611
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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