Re: Accessing Record fields with keywords in ClojureScript not working as in Clojure

2020-08-12 Thread Alan Thompson
I verified the problem in the StackOverflow post. For some reason keyword lookup of record fields in CLJS doesn't work. Alan On Tue, Aug 4, 2020 at 12:05 PM Justin Smith wrote: > I don't think this is true, or if true is incidental to the real problem > > % cljs > ClojureScript 1.10.758 >

Re: Accessing Record fields with keywords in ClojureScript not working as in Clojure

2020-08-04 Thread Justin Smith
I don't think this is true, or if true is incidental to the real problem % cljs ClojureScript 1.10.758 cljs.user=> (defrecord Attr [has-default default]) cljs.user/Attr cljs.user=> (get (->Attr true 1) :default) 1 cljs.user=> (:default (->Attr true 1)) nil cljs.user=> On Tue, Aug 4, 2020 at

Re: Accessing Record fields with keywords in ClojureScript not working as in Clojure

2020-08-04 Thread Mark Engelberg
You misspelled default in your defrecord. On Tue, Aug 4, 2020 at 7:42 AM 'clartaq' via Clojure < clojure@googlegroups.com> wrote: > I originally posted > <https://stackoverflow.com/questions/63231270/accessing-record-fields-with-keywords-in-clojurescript-not-workin

Accessing Record fields with keywords in ClojureScript not working as in Clojure

2020-08-04 Thread 'clartaq' via Clojure
I originally posted <https://stackoverflow.com/questions/63231270/accessing-record-fields-with-keywords-in-clojurescript-not-working-as-in-clojure> this on StackOverflow. When I try this: ```clojure (defrecord Attr [has-default default]) (def attr (->Attr true 1)) (get attr :defaul

Re: Keys in EDN maps: keywords or symbols

2019-10-25 Thread James Reeves
As you point out, symbols in edn have no inherent meaning; it's entirely up to how you interpret them. However, if you saw the symbol "clojure.core/conj" in an edn file, then the chances are that it's intended to refer to a Clojure function. Similarly, the symbol "PI" likely refers to the

Re: Keys in EDN maps: keywords or symbols

2019-10-25 Thread Anton Vodonosov
Thank you for responses. The last two arguments do not resolve the doubt, however: 1. symbols also implement IFn: (require 'clojure.edn) ('a (clojure.edn/read-string "{a 1 b 2}")) => 1 2. EDN does not specify any evaluation model, so how can a symbol designate something "in

Re: Keys in EDN maps: keywords or symbols

2019-10-24 Thread James Reeves
On Thu, 24 Oct 2019 at 16:48, Anton Vodonosov wrote: > Regarding the idea that a keyword is an identifier that designates itself, > while a symbol is a keyword that designates something else. > > Keys in config file map do not designate themselves, they designate the > corresponding map values.

Re: Keys in EDN maps: keywords or symbols

2019-10-24 Thread David Chelimsky
I think James talking about resolution of values when he said "designates", not "the value bound to a key in the map." In other words, the keyword :email resolves to the keyword :email, whereas the symbol clojure.core/vec resolves to a function. Keywords-as-keys give yo

Re: Keys in EDN maps: keywords or symbols

2019-10-24 Thread Anton Vodonosov
d{3}" 2digits "\\d{2}"} in another config section user can refer the regex by the symbols he defined that way. So the map keys in user's definitions allow hig to give names to values; here the names do not designate themselves, they are names for the regular expressions. Thinking tha

Re: Keys in EDN maps: keywords or symbols

2019-10-24 Thread James Reeves
In edn, a keyword is an identifier that designates itself, while a symbol is a keyword that designates something else. This means keys in a map should generally be keywords, unless they identify something beyond themselves. For example: {:profiling/function-count {clojure.core/vec 10

Re: Keys in EDN maps: keywords or symbols

2019-10-24 Thread Jason Felice
My personal opinion is to prefer keywords, and prefer less preprocessing of the configuration before the program uses it. If it gets to a place where the configuration changes a lot, and a "natural" (read: clojure-like) expression of the configuration in EDN has either a lot of

Keys in EDN maps: keywords or symbols

2019-10-23 Thread Anton Vodonosov
I'm working on a config file format in EDN, and in doubt: should I use keywords or symbols as map keys. After all, the colon is an extra keyboard press - an extra effort for users. As EDN parser doesn't evaluate expressions, there is no need to quote symbols when using them as EDN map keys

Re: Invalid-token when dereferencing namespaced keywords.

2019-09-19 Thread Dieter Komendera
We have the common use-case that we want to use double-colon keywords for well known namespaces, without actually requiring the namespaces. (defmacro ns-alias "Set up a custom alias for use with namespace keywords." [ns as] `(do (create-ns '~ns) (alias '~as '~ns))) T

Issue with using keywords as function in a spec conformer

2019-01-31 Thread Daniel Dinnyes
Hi everyone, I have ran into an issue with spec, and suspect it is a bug. The following code throws an error: (clojure.spec.alpha/conformer :foo) The error is a java.lang.Exception and says: Unable to resalve spec; :foo This is unexpected because I intend to use the keyword as a conformer

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-30 Thread Philip Markgraf
Thank you Justin, Andy, Alex and Thomas. I now understand both the root of my issue (leading digits in keyword names is not allowed) and have a greater understanding of how keywords work, especially the reader's role in expanding double-colon keywords. On Wednesday, January 30, 2019 at 2:53

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-30 Thread Thomas Heller
To expand on what Alex already mentioned. There is no such thing as double-colon keywords. Double-colon is a reader alias mechanism that let the reader resolve them so you can type less. (ns foo.bar.xyz) ::hello this is resolved at read-time and identical to actually writing :foo.bar.xyz

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Philip Markgraf
and namespaced keywords is. When should we use single-colon keywords and when should we use the double-colon variety? On Tuesday, January 29, 2019 at 8:48:00 PM UTC-8, Alex Miller wrote: > > > > On Tuesday, January 29, 2019 at 10:07:29 PM UTC-6, Philip Markgraf wrote: >>

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Alex Miller
On Tuesday, January 29, 2019 at 10:07:29 PM UTC-6, Philip Markgraf wrote: > > Thank you, Alex and Andy. This answers my question regarding leading digit > in keywords. > > > Alex, > You describe an error with autoresolved keywords in my example. Is this > also true

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Philip Markgraf
Thank you, Alex and Andy. This answers my question regarding leading digit in keywords. Alex, You describe an error with autoresolved keywords in my example. Is this also true of the second example I posted (in response to Justin), which does not use the user namespace? Am I correct to use

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Alex Miller
There are two interrelated issues here. First, when you are using autoresolved keywords, the qualifier part must be an alias. Here it is a fully-qualified namespace (user). Instead, you should be using :user/015-00. Note that before Clojure 1.10, this would not produce an error

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Andy Fingerhut
I believe the original intent was that keywords with a digit immediately after the colon would not be supported, but due to a bug in the Clojure reader they were permitted. There was a brief time in 2013 where this bug was fixed, but there were enough extant Clojure code bases that used

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Philip Markgraf
gt; nil > (ins)foo=> ::user/a > RuntimeException Invalid token: ::user/a > clojure.lang.Util.runtimeException (Util.java:221) > (ins)foo=> :user/a > :user/a > > On Tue, Jan 29, 2019 at 2:52 PM Philip Markgraf > wrote: > > > > I am moving some code

Re: Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Justin Smith
PM Philip Markgraf wrote: > > I am moving some code to use spec and namespaced keywords under Clojure > 1.10.0 (release). One group of keywords starts with a numeric character after > the colon, which has worked fine in the non-namespaced context. Creating and > using the namespaced

Invalid-token when dereferencing namespaced keywords.

2019-01-29 Thread Philip Markgraf
I am moving some code to use spec and namespaced keywords under Clojure 1.10.0 (release). One group of keywords starts with a numeric character after the colon, which has worked fine in the non-namespaced context. Creating and using the namespaced keyword works correctly in the local namespace

Re: How to Programmatically Create Unqualified Keywords?

2018-03-22 Thread Francis Avila
absolutely sure* namespace is nil, use (keyword nil "something-empty") in your example. Note that the keyword function will happily create keywords whose printed form is either not readable (e.g. include a space, a digit in the wrong place, a bad character, etc) or would be read a di

Re: How to Programmatically Create Unqualified Keywords?

2018-03-22 Thread Gary Verhaegen
I think there's some confusion here between the keyword and its textual representation. The root issue is that the keyword function is, in a way, too lenient in its error checking: it will allow you to create keywords that are not valid according to the language definition. The Clojure reader

Re: How to Programmatically Create Unqualified Keywords?

2018-03-21 Thread Mauricio Aldazosa
On Wed, Mar 21, 2018 at 7:48 AM, Nick Mudge <mud...@gmail.com> wrote: > I see what you mean. All keywords are namespaced, so there really is no > such thing as a no-namespaced keyword. Thank you. > You can have keywords without a namespace: user> (clojure-version) 1.9.0 u

Re: How to Programmatically Create Unqualified Keywords?

2018-03-21 Thread Matteo Moci
Don't know about older clojure versions, but running your code in the 1.9 repl I got this: $ clj Clojure 1.9.0 user=> (keyword (str "something" "-empty")) :something-empty On Wed, Mar 21, 2018 at 2:15 PM, Nick Mudge <mud...@gmail.com> wrote: > I want to progr

Re: How to Programmatically Create Unqualified Keywords?

2018-03-21 Thread Nick Mudge
I see what you mean. All keywords are namespaced, so there really is no such thing as a no-namespaced keyword. Thank you. On Wednesday, March 21, 2018 at 6:32:53 AM UTC-7, Alex Miller wrote: > > I believe you are mistaken as the keyword function will create > :something-empty in

Re: How to Programmatically Create Unqualified Keywords?

2018-03-21 Thread Nick Mudge
ax for :user/something-empty btw > (where user is your current namespace), so it's not even possible to > "create" a keyword like ::something-empty. > > On Wednesday, March 21, 2018 at 8:15:43 AM UTC-5, Nick Mudge wrote: >> >> I want to programmatically create so

Re: How to Programmatically Create Unqualified Keywords?

2018-03-21 Thread Alex Miller
Wednesday, March 21, 2018 at 8:15:43 AM UTC-5, Nick Mudge wrote: > > I want to programmatically create some keywords without namespaces? Or > are we not supposed to do that? > > I can't use the "keyword" function because that only creates keywords with >

How to Programmatically Create Unqualified Keywords?

2018-03-21 Thread Nick Mudge
I want to programmatically create some keywords without namespaces? Or are we not supposed to do that? I can't use the "keyword" function because that only creates keywords with a namespace. For example doing this: (keyword (str "something" "-empty")) Creates

Re: Sets/Vectors vs Maps/Keywords default value when used as functions

2017-12-13 Thread Khalid Jebbari
:56:58 AM UTC-6, Khalid Jebbari wrote: >> >> Any reason we can't provide default value for sets and vectors when using >> them as functions, whereas it works just fine for maps and keywords ? >> >> Examples : >> >> boot.user=> (["first" "second

Re: Sets/Vectors vs Maps/Keywords default value when used as functions

2017-12-13 Thread Alex Miller
it works just fine for maps and keywords ? > > Examples : > > boot.user=> (["first" "second"] 2 :nope) > clojure.lang.ArityException: Wrong number of args (2) passed to: > PersistentVector > > boot.user=> (#{1 2} 3 :nope) >

Sets/Vectors vs Maps/Keywords default value when used as functions

2017-12-13 Thread Khalid Jebbari
Any reason we can't provide default value for sets and vectors when using them as functions, whereas it works just fine for maps and keywords ? Examples : boot.user=> (["first" "second"] 2 :nope) clojure.lang.ArityException: Wrong number of args (2) passed to: Pers

Re: Map Keywords are functions, why not vector elements?

2017-11-19 Thread Stephen Feyrer
conj >> >> [] >> >> l)) >> >> >> >> Hopefully that’ll give you some options to think about… >> >> >> >> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN >> An Architect's View -- http://corfield.org/ >>

Re: Map Keywords are functions, why not vector elements?

2017-11-14 Thread Gary Verhaegen
- http://corfield.org/ > > "If you're not annoying somebody, you're not really alive." > -- Margaret Atwood > > > -- > *From:* clojure@googlegroups.com <clojure@googlegroups.com> on behalf of > Stephen Feyrer <stephen.fey...@gmail.c

RE: Map Keywords are functions, why not vector elements?

2017-11-13 Thread Sean Corfield
Stephen Feyrer <stephen.fey...@gmail.com> Sent: Monday, November 13, 2017 5:19:32 PM To: clojure@googlegroups.com Subject: Re: Map Keywords are functions, why not vector elements? Hi Alex, Didier, Thanks for your patience. That covers everything which I can think of and a fair bit more :) I

Re: Map Keywords are functions, why not vector elements?

2017-11-13 Thread Stephen Feyrer
Hi Alex, Didier, Thanks for your patience. That covers everything which I can think of and a fair bit more :) I have a bit of reading and thinking to do now. Again, thank you. -- Rule of thumb simple question, complicated answer Stephen. On 13 November 2017 at 22:09, Didier

Re: Map Keywords are functions, why not vector elements?

2017-11-13 Thread Didier
Yo are looking for indexOf (.indexOf vector value). (.indexOf ["a" "b"] "b") => 1 (.indexOf ["a" "b" "b"] "b") => 1 Note how indexOf searches for the index of the first value which matches value. To do what you ask, is a query over a vector, which requires a search on each element. This will

Re: Map Keywords are functions, why not vector elements?

2017-11-13 Thread Alex Miller
On Monday, November 13, 2017 at 11:40:10 AM UTC-6, Stephen Feyrer wrote: > > Updating subject to make it make more sense, hopefully. > > On 13 November 2017 at 14:15, Alex Miller <a...@puredanger.com> wrote: > >> Regarding the title, this is incorrect. Map keys are

Re: Map Keywords are functions, why not vector elements?

2017-11-13 Thread Stephen Feyrer
Updating subject to make it make more sense, hopefully. On 13 November 2017 at 14:15, Alex Miller <a...@puredanger.com> wrote: > Regarding the title, this is incorrect. Map keys are not functions; > keywords are functions that take an associative data structure and will > loo

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-07 Thread Erik Assum
Bruce Hauman has done some work in this area both in figwheel and in a branch of leiningen. Basically, if I understand correctly, he looks for misspelled keywords in configuration maps by taking the levenstein distance between expected, valid, keywords and non-matching keywords

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-04 Thread Dave Tenny
I have found eastwood to be useful for a number of things, however on keyword checking it failed terribly on our code base, though perhaps there have been updates since I last tried it. Thanks for the suggestion though. On Friday, February 3, 2017 at 7:26:01 PM UTC-5, Ben Brinckerhoff wrote: >

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-04 Thread Colin Fleming
at 1:49:20 AM UTC+1, tbc++ wrote: >> >> A good editor should auto-complete your keywords for you. Since using >> this feature in Cursive (same sort of thing is available in other editors) >> the cases where I've mis-spelled a keyword have dropped dramatically. It's >> a

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-03 Thread Linus Ericsson
). /Linus On Friday, February 3, 2017 at 1:49:20 AM UTC+1, tbc++ wrote: > > A good editor should auto-complete your keywords for you. Since using this > feature in Cursive (same sort of thing is available in other editors) the > cases where I've mis-spelled a keyword have dropped dramat

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-03 Thread Ben Brinckerhoff
The eastwood linter can also be configured to look for possibly misspelled keyword typos https://github.com/jonase/eastwood#keyword-typos On Friday, February 3, 2017 at 3:47:21 AM UTC-7, John Schmidt wrote: > > I suggest something like (defn fetch-encrypted [] (fetch-important-data > {:encrypt

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-03 Thread John Schmidt
I suggest something like (defn fetch-encrypted [] (fetch-important-data {:encrypt true})) + unit tests On Friday, February 3, 2017 at 2:56:34 AM UTC+1, Michael Gardner wrote: > > What would be the Right Way to deal with typos like (fetch-important-data > {:encypt true}), where the :encrypt key

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Michael Gardner
What would be the Right Way to deal with typos like (fetch-important-data {:encypt true}), where the :encrypt key is optional? Timothy mentions auto-complete, which is better than nothing but doesn't feel like a real solution (especially to those who don't use auto-complete). > On Feb 2, 2017,

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Timothy Baldridge
A good editor should auto-complete your keywords for you. Since using this feature in Cursive (same sort of thing is available in other editors) the cases where I've mis-spelled a keyword have dropped dramatically. It's a lot harder to mis-spell a keyword when you can just do: :egg/th and the rest

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Alex Miller
Ugh, don't do that. Introducing layers that add no value is a bad idea. Just use the keyword directly. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Matching Socks
Keyword literals are inherently misspellable and trying to solve that problem with Spec does not really hit the nail on the head. But there is a solution: You do not have to use keyword literals very much! Instead of using, say, :egg/thunder throughout your program, def a var as :egg/thunder

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Mikhail Gusarov
Hello Alex, The idea is (as I understand it) that every function should accept any map and pick keys which it understands. If some keys are critical, then they should be marked as such in the spec. Function might iterate over keys and raise an error if there are keys which belong to the

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Dave Tenny
On Thursday, February 2, 2017 at 10:07:31 AM UTC-5, Alex Miller wrote: > > We don't encourage you to do this, but I don't have an easier solution > than this. > Yes, and from the general standpoint of map handling I understand that. >From the standpoint of functions that take options and don't

Re: Documentation for namespace aliased keywords (particularly relevant for clojure.spec use)

2017-02-02 Thread Alex Miller
On Wednesday, February 1, 2017 at 6:12:35 PM UTC-6, Dave Tenny wrote: > > Looking at the documentation for keywords under > https://clojure.org/reference/reader#_literals > there is no mention for the syntax for namespace aliased keywords, and > this is very important it you

Re: Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Alex Miller
We don't encourage you to do this, but I don't have an easier solution than this. On Thursday, February 2, 2017 at 7:05:37 AM UTC-6, Dave Tenny wrote: > > I want to specify in clojure spec that only declared keywords are > permitted in function calls. > This is to catch what are

Clojure.spec, maps, restrict valid keywords, easier way?

2017-02-02 Thread Dave Tenny
I want to specify in clojure spec that only declared keywords are permitted in function calls. This is to catch what are usually mis-spelled or mis-cased keywors passed via option maps in function calls. In the fdefs below, the second fdef will catch an invalid call, e.g. (f 1 {:a 2 :B 3

Re: Documentation for namespace aliased keywords (particularly relevant for clojure.spec use)

2017-02-02 Thread Dave Tenny
I also have to wonder why keyword namespaces aren't processed like other symbol namespaces, that is, to interpret the namespace portion before a '/' with alias consideration. No doubt there's a good answer, but it seems anachronistic that keywords need special syntax contortions to recognize

Documentation for namespace aliased keywords (particularly relevant for clojure.spec use)

2017-02-01 Thread Dave Tenny
Looking at the documentation for keywords under https://clojure.org/reference/reader#_literals there is no mention for the syntax for namespace aliased keywords, and this is very important it you want to manage your keywords for clojure.spec. I only know about it because google turned up some

Re: Guidelines/Recommendations for namespaces and qualified keywords

2016-10-18 Thread Alex Miller
On Saturday, October 15, 2016 at 10:17:15 PM UTC-5, Josh Tilles wrote: > > I’ve got a couple questions for Alex Miller and/or the other Cognitect > folks. > >1. *Are single-segment namespaces still “bad” when it comes to >registering specs under qualified keywords?* &

Re: Guidelines/Recommendations for namespaces and qualified keywords

2016-10-17 Thread Mauricio Aldazosa
> That isn't me. I'm just chiming in from the peanut gallery. Must of my > "experience" so far stems from converting > my toy projects from prismatic schema to spec. > >> >>1. *Are single-segment namespaces still “bad” when it comes to >>registering specs

Re: Guidelines/Recommendations for namespaces and qualified keywords

2016-10-17 Thread James Gatannah
g my toy projects from prismatic schema to spec. > >1. *Are single-segment namespaces still “bad” when it comes to >registering specs under qualified keywords?* >In the past, single-segment namespaces have been discouraged in the >Clojure community—both because

Guidelines/Recommendations for namespaces and qualified keywords

2016-10-15 Thread Josh Tilles
I’ve got a couple questions for Alex Miller and/or the other Cognitect folks. 1. *Are single-segment namespaces still “bad” when it comes to registering specs under qualified keywords?* In the past, single-segment namespaces have been discouraged in the Clojure community—both

Re: Keywords with colon on the backside?

2016-10-13 Thread larry google groups
r 23, 2016 at 7:13:30 PM UTC-4, John Mastro wrote: > > Timothy Baldridge <tbald...@gmail.com > wrote: > > The syntax (I think) comes from Ruby although they call keywords > "symbols". > > The reader syntax for Common Lisp's keywords has the leading colon t

Best style for clojure.spec and namespaced keywords?

2016-10-10 Thread David Goldfarb
I'm starting to dive into clojure.spec, which is a strong motivation for me to finally appreciate and use namespaced keywords -- an aspect of Clojure that I've ignored until now. I don't have a good sense of style re how to namespace keywords, especially in standalone projects. I'm inclined

Re: Keywords with colon on the backside?

2016-09-23 Thread John Mastro
Timothy Baldridge <tbaldri...@gmail.com> wrote: > The syntax (I think) comes from Ruby although they call keywords "symbols". The reader syntax for Common Lisp's keywords has the leading colon too. John -- You received this message because you are subscribed t

Re: Keywords with colon on the backside?

2016-09-23 Thread Gregg Reynolds
come ( https://en.wikibooks.org/wiki/Learning_Clojure/Reader_Macros). And that's just one of many reasons (without even mentioning backwards compatibility), postfix colons on keywords will never happen. >> > > Just to clear, I'm not suggesting that the current notation go away. Breaking

Re: Keywords with colon on the backside?

2016-09-23 Thread tabcomputing
t's > just one of many reasons (without even mentioning backwards compatibility), > postfix colons on keywords will never happen. > > Just to clear, I'm not suggesting that the current notation go away. Breaking backwards compatibility would be nuts, of course. Just wonder if the alter

Re: Keywords with colon on the backside?

2016-09-23 Thread Timothy Baldridge
efixed. So it's very natural to keep keywords the same way. The syntax (I think) comes from Ruby although they call keywords "symbols". So that would be my rationale for it..it's easy to see by the first character of a term what data structure the term will become ( https://en.wikib

Keywords with colon on the backside?

2016-09-23 Thread tabcomputing
eyeing it for some time. Reading over numerous examples, there is one thing about reading Clojure code that I find a bit hard to take -- keywords. Take the example of metadata for a Cryogen post: {:title "First Post!" :layout :post :date "2016-01-01" :

Re: Unexpected behavior for symbols or keywords used in the operator position

2015-09-15 Thread Michael O'Keefe
Aha, got it. Just surprised me that it still worked without a map. Thanks for clearing it up! Cheers On Tuesday, September 15, 2015 at 10:29:08 PM UTC-6, Carlo wrote: > > Symbols and keywords act as functions which look themselves up in their > argument. Essentially: > > ('s

Unexpected behavior for symbols or keywords used in the operator position

2015-09-15 Thread Michael O'Keefe
Hello All: Noticed the following works in Clojure 1.6 and 1.7 (didn't test prior to that): user=> ('+ 'a 'b) b Also "works" for any set of symbols: user=> ('abra 'ka 'dabra) dabra My expectation was that using symbols or keywords in the function/operator position would th

Re: Unexpected behavior for symbols or keywords used in the operator position

2015-09-15 Thread Carlo Zancanaro
Symbols and keywords act as functions which look themselves up in their argument. Essentially: ('sym map) => (get map 'sym) ('sym map not-found) => (get map 'sym not-found) (:key map) => (get map :key) (:key map not-found) => (get map :key not-found) It's often pretty u

keywords

2014-09-15 Thread Paweł Sabat
Hi. How many :keywords can I create in Clojure? Is there any limited number of them? I know of such limitation of Erlang's atoms, which are just like Clojure's keywords. noniwoo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group

Re: keywords

2014-09-15 Thread adrian . medina
There is no hard limit beyond available memory and JVM class size limitations (which is really only relevant if your creating a ton of keywords statically I think). On Monday, September 15, 2014 3:32:40 PM UTC-4, Paweł Sabat wrote: Hi. How many :keywords can I create in Clojure

Re: keywords

2014-09-15 Thread adrian . medina
*you're On Monday, September 15, 2014 4:23:46 PM UTC-4, adrian...@mail.yu.edu wrote: There is no hard limit beyond available memory and JVM class size limitations (which is really only relevant if your creating a ton of keywords statically I think). On Monday, September 15, 2014 3:32:40

Re: keywords

2014-09-15 Thread dennis zhuang
Clojure's keyword is using a soft reference cache, they would be garbage collected when used memory reaches threshold. 2014-09-15 18:36 GMT+08:00 Paweł Sabat noni...@gmail.com: Hi. How many :keywords can I create in Clojure? Is there any limited number of them? I know of such limitation

When to prefer keywords as functions?

2014-07-03 Thread gvim
I'm reading Cloujure in Action as an introduction to Clojure and, although, I understand a keyword can be used as a function I don't understand the difference between: (ns org.currylogic.damages.http.expenses (:require [clojure.data.json :as json-lib]

Re: When to prefer keywords as functions?

2014-07-03 Thread James Reeves
The ns form is a macro that takes a special syntax and always uses the keyword form, as you have in your first example. Your second example is incorrect; I'd be surprised if it even ran. The reason for this is to make it clear that you're not executing the require function directly, but instead

Re: When to prefer keywords as functions?

2014-07-03 Thread gvim
On 03/07/2014 18:36, James Reeves wrote: The reason for this is to make it clear that you're not executing the require function directly, but instead passing options to the ns form. I don't understand not executing the require function directly. I've also seen the when function called as

Re: When to prefer keywords as functions?

2014-07-03 Thread adrian . medina
I believe you might have seen :when in the binding vector of either a for or deseq form. Their special usage is documented here: http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/for In any event, James explained the distinction quite well. Macros are often used to create

Re: When to prefer keywords as functions?

2014-07-03 Thread Mauricio Aldazosa
Keywords can be used as a function with a map, so the keyword will search for itself in the map. Take a look at http://clojure.org/data_structures#Data%20Structures-Keywords In the case of the ns form, as James pointed out, what is happening is not a function call. ns is a macro

Re: When to prefer keywords as functions?

2014-07-03 Thread Jony Hudson
One thing to note is that while it's true keywords can be used as functions they can only really do one thing, which is get values from maps. That is to say, the keyword-function :foo is equivalent to the function #(get % foo). The function :foo has no relationship with the function foo

Using macro to generate boilerplate keywords

2014-01-17 Thread Kashyap CK
Hi, I am exploring javax.sound.midi using clojure and while creating keywords for notes I wonder if I could use macros to generate the keywords - (defn note-2-num [n] (let [ m { :C1 0 :C#1 1 :D1 2 :D#1 3 :E1 4 :F1 5

Re: Using macro to generate boilerplate keywords

2014-01-17 Thread Timothy Baldridge
clojure and while creating keywords for notes I wonder if I could use macros to generate the keywords - (defn note-2-num [n] (let [ m { :C1 0 :C#1 1 :D1 2 :D#1 3 :E1 4 :F1 5 :F#1 6 :G1 7

Re: Using macro to generate boilerplate keywords

2014-01-17 Thread Alex Walker
Is a macro necessary? https://gist.github.com/alexpw/8476780 On Friday, January 17, 2014 10:21:52 AM UTC-6, Kashyap CK wrote: Hi, I am exploring javax.sound.midi using clojure and while creating keywords for notes I wonder if I could use macros to generate the keywords - (defn note-2-num

Re: Using macro to generate boilerplate keywords

2014-01-17 Thread Kashyap CK
/8476780 On Friday, January 17, 2014 10:21:52 AM UTC-6, Kashyap CK wrote: Hi, I am exploring javax.sound.midi using clojure and while creating keywords for notes I wonder if I could use macros to generate the keywords - (defn note-2-num [n] (let [ m { :C1 0

Re: Using macro to generate boilerplate keywords

2014-01-17 Thread Kashyap CK
octave Timothy On Fri, Jan 17, 2014 at 9:21 AM, Kashyap CK ckka...@gmail.comjavascript: wrote: Hi, I am exploring javax.sound.midi using clojure and while creating keywords for notes I wonder if I could use macros to generate the keywords - (defn note-2-num [n] (let [ m

Why are vectors and sets inconsistent with maps, keywords, and symbols when used as operators?

2013-12-05 Thread Dave Tenny
Maps, keywords, and symbols when used as operators allow optional second arguments for 'default-not-found' values is if to 'get'. E.g. ({:a 1} :b 'b) = b However sets don't support this behavior (though they do with 'get') and vectors don't allow the optional default-not-found in their pseudo

Re: Why are vectors and sets inconsistent with maps, keywords, and symbols when used as operators?

2013-12-05 Thread Alex Miller
tickets though. http://dev.clojure.org/jira/browse/CLJ Alex On Thursday, December 5, 2013 2:13:37 PM UTC-6, Dave Tenny wrote: Maps, keywords, and symbols when used as operators allow optional second arguments for 'default-not-found' values is if to 'get'. E.g. ({:a 1} :b 'b) = b

Re: Reading namespaced keywords

2013-09-17 Thread Dave Ray
regarding namespaced keywords (is that the right term?) such as ::l/test. = (read-string ::l/test) RuntimeException Invalid token: ::l/test clojure.lang.Util.runtimeException (Util.java:219) It seems that the reader requires the namespace alias 'l' to exist. This is a shame because in most (all

Reading namespaced keywords

2013-09-17 Thread Casper Clausen
I am reading a bunch of clojure files using the build-in reader (or tools.reader, it has the same problem) and I am running into a problem regarding namespaced keywords (is that the right term?) such as ::l/test. = (read-string ::l/test) RuntimeException Invalid token: ::l/test

Re: Reading namespaced keywords

2013-09-17 Thread Casper Clausen
Dave On Tue, Sep 17, 2013 at 4:03 PM, Casper Clausen cas...@gmail.comjavascript: wrote: I am reading a bunch of clojure files using the build-in reader (or tools.reader, it has the same problem) and I am running into a problem regarding namespaced keywords (is that the right term

Re: Reading namespaced keywords

2013-09-17 Thread Dave Ray
17, 2013 at 4:03 PM, Casper Clausen cas...@gmail.com wrote: I am reading a bunch of clojure files using the build-in reader (or tools.reader, it has the same problem) and I am running into a problem regarding namespaced keywords (is that the right term?) such as ::l/test. = (read-string ::l

Re: Reading namespaced keywords

2013-09-17 Thread Andy Fingerhut
at 4:03 PM, Casper Clausen cas...@gmail.comwrote: I am reading a bunch of clojure files using the build-in reader (or tools.reader, it has the same problem) and I am running into a problem regarding namespaced keywords (is that the right term?) such as ::l/test. = (read-string ::l/test

Re: Reading namespaced keywords

2013-09-17 Thread Andy Fingerhut
Dave On Tue, Sep 17, 2013 at 4:03 PM, Casper Clausen cas...@gmail.comwrote: I am reading a bunch of clojure files using the build-in reader (or tools.reader, it has the same problem) and I am running into a problem regarding namespaced keywords (is that the right term?) such as ::l/test

Re: Reading namespaced keywords

2013-09-17 Thread Brandon Bloom
The double-colon is only shorthand for the current namespace: Or other namespaces via an alias: (alias 'clj 'clojure.core) ::clj/foo = :clojure.core/foo Inside ns forms, the :as keyword creates aliases. -- -- You received this message because you are subscribed to the Google Groups Clojure

Re: Reading namespaced keywords

2013-09-17 Thread Dave Ray
Cool. You learn something new every day :) On Tuesday, September 17, 2013, Brandon Bloom wrote: The double-colon is only shorthand for the current namespace: Or other namespaces via an alias: (alias 'clj 'clojure.core) ::clj/foo = :clojure.core/foo Inside ns forms, the :as keyword

core.match question: how can I escape keywords?

2013-07-22 Thread Yong
I have a sequence of keywords which I want to use match on. However, :when has a special meaning, which means I cannot do something like: (let [x [:ok :when :where]] (match [x] [[_ :when _]] :a0)) which gives a clojure.lang.Compiler$CompilerException: java.lang.AssertionError: Assert

Re: core.match question: how can I escape keywords?

2013-07-22 Thread David Nolen
This is just a bug :when should only have special meaning if it occurs in a list not a vector. Please file a ticket in JIRA: http://dev.clojure.org/jira/browse/MATCH David On Sun, Jul 21, 2013 at 8:54 PM, Yong yong...@10gic.net wrote: I have a sequence of keywords which I want to use match

  1   2   3   >