[ClojureScript] Re: Inconsistency in creating keywords

2018-03-03 Thread outrovurt
Thank you for the background, it explains everything.

So, if you want to be really safe and "to the spec" right now, then I would 
> say, don't use leading digits in keywords. Realistically though, we're 
> never going to disallow those and eventually I expect them to be 
> "officially" ok. 
>

This is what I specifically wanted to hear, whether things are going to 
change in the future and if so how. But as it doesn't sound like they are, 
I know where I stand.
 

> For leading digits in namespaces, that may actually violate Java package 
> rules, in which cases we would not be able to allow that.
>

This isn't such a concern for me as I'm mostly using them in CLJS, but I do 
realise that macros are currently executed in Clojure-land so I'll keep all 
of this in mind as I go along.

Cheers!

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Inconsistency in creating keywords

2018-03-02 Thread AndyR
You should be extra careful in CLJS when creating keywords with multiple 
slashes. They currently behave different from CLJ. Logged here: 
https://dev.clojure.org/jira/browse/CLJS-2120

On Thursday, March 1, 2018 at 1:14:34 PM UTC+1, outr...@gmail.com wrote:
>
> I've encountered a problem when creating namespaced keywords using the 
> literal syntax, specifically using keywords which start with numbers. 
>
> If I try using the literal syntax, entering the following at the REPL, I 
> get the exception which follows it:
>
> :a/0
> ;= clojure.lang.ExceptionInfo: NO_SOURCE_FILE [line 1, col 5] Invalid 
> keyword: :a/0. {:type :reader-exception, :ex-kind :reader-error, :file 
> "NO_SOURCE_FILE", :line 1, :col 5} ...
>
> If instead I use the the keyword function, it produces the desired result:
>
> (keyword "a" "0")
> ;= :a/0
>
>
> It seems I can get away with almost anything using the keyword function. 
> For example:
>
> (keyword "a" "0/1")
> ;= :a/0/1
>
> I'm wondering then, what is the "correct" behaviour if there is such a 
> thing in this case? I know that in Clojure the behaviour appears once again 
> to be slightly different, and the main docs seem to cater more to Clojure 
> than to CLJS.
>
> Thank you,
> Ali
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Inconsistency in creating keywords

2018-03-02 Thread Alex Miller
There's actually a lot of history and several open tickets about this 
specific question of whether keywords can start with a digit. The original 
intent (and the reader reference page) is that it would match symbols in 
that leading digits are not allowed. However, there is a bug in the regex 
that lead to them being accepted.

We tried to fix this bug several years ago and it broke a lot of existing 
code that was relying on the ability to do this. We decided at that point 
that there was no reason to take this away. The lingering tickets are to 

a) fix the regex to do this on purpose rather than on accident (and this is 
also the reason why some of your examples work and some do not)
b) update the reference pages to explicitly include this
c) sync up edn rules with clojure rules

So, if you want to be really safe and "to the spec" right now, then I would 
say, don't use leading digits in keywords. Realistically though, we're 
never going to disallow those and eventually I expect them to be 
"officially" ok. 

For leading digits in namespaces, that may actually violate Java package 
rules, in which cases we would not be able to allow that.

On Friday, March 2, 2018 at 12:35:26 AM UTC-6, outr...@gmail.com wrote:
>
> Thank you both for the links, especially the FAQ page. As an aside I was 
> looking for something like the namespace function and am glad I found it.
>
> Something is still confusing me however. If we follow the reader docs 
> which Alex posted, "Symbols begin with a non-numeric character", and 
> "Keywords are *like* symbols" (emphasis mine, this may be open to 
> interpretation) hence also shouldn't begin with a non-numeric character. 
> But if you try the following in either Clojure or (Script)'s REPLs, they 
> work just fine:
>
> :0
> ;= :0
>
> Further, using the respective reader-string functions also yields:
> (read-string ":0")
> ;= :0
>
> So this would indicate that whatever is written in the docs is not 
> necessarily being enforced in the reader, is that correct?  
>

> It seems that as far as the reader is concerned, keywords can begin with a 
> numeric but the name portion (after the /) of a namespaced keyword can't. 
> In other words :0 is legal, :a/0 isn't. 
>
> Interestingly enough, 
> :0/a
> ;= :0/a
>
> is also legal within each language's reader.
>
> In which case, why are :0 and :0/a legal but not :a/0?
>
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Inconsistency in creating keywords

2018-03-01 Thread outrovurt
Thank you both for the links, especially the FAQ page. As an aside I was 
looking for something like the namespace function and am glad I found it.

Something is still confusing me however. If we follow the reader docs which 
Alex posted, "Symbols begin with a non-numeric character", and "Keywords 
are *like* symbols" (emphasis mine, this may be open to interpretation) 
hence also shouldn't begin with a non-numeric character. But if you try the 
following in either Clojure or (Script)'s REPLs, they work just fine:

:0
;= :0

Further, using the respective reader-string functions also yields:
(read-string ":0")
;= :0

So this would indicate that whatever is written in the docs is not 
necessarily being enforced in the reader, is that correct? 

It seems that as far as the reader is concerned, keywords can begin with a 
numeric but the name portion (after the /) of a namespaced keyword can't. 
In other words :0 is legal, :a/0 isn't. 

Interestingly enough, 
:0/a
;= :0/a

is also legal within each language's reader.

In which case, why are :0 and :0/a legal but not :a/0?

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Inconsistency in creating keywords

2018-03-01 Thread Alex Miller


On Thursday, March 1, 2018 at 9:34:29 AM UTC-6, Thomas Heller wrote:
>
> Clojure follows the principle of "Garbage in, Garbage out" for a lot of 
> internal functions. 
>

I would say "unspecified input / unspecified output", however this is not 
one of those cases in my opinion. The keyword function creates keywords and 
they can be programatically used just fine. You can put them in a map, use 
them as accessors, etc. 
 

> Meaning you are responsible for ensuring that you only use valid data when 
> calling those functions as the validation itself carries overhead which the 
> core fns should not have.
>
> :a/0 fails because the reader does those checks and fails. The keyword fn 
> does no checks and lets you have your invalid keywords. They are still 
> invalid keywords though. Keywords are not allowed to start with numbers.
>

Really, that applies specifically to *literal* keywords (and actually even 
that is a matter of some lengthy debate and differences between clj and 
cljs). They are still valid keyword instances, just not ones that can be 
printed and read back by the reader.
 

> https://github.com/edn-format/edn might be a helpful reference about that 
> is allowed and what isn't.
>

Clojure(Script) code is not edn so the reader page is a better reference 
- https://clojure.org/reference/reader

These pages will not agree exactly - edn tends to be more restrictive in 
what it officially supports.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Inconsistency in creating keywords

2018-03-01 Thread Alex Miller
Regarding the keyword function, see the faq 
at https://clojure.org/guides/faq#unreadable_keywords

On Thursday, March 1, 2018 at 6:14:34 AM UTC-6, outr...@gmail.com wrote:
>
> I've encountered a problem when creating namespaced keywords using the 
> literal syntax, specifically using keywords which start with numbers. 
>
> If I try using the literal syntax, entering the following at the REPL, I 
> get the exception which follows it:
>
> :a/0
> ;= clojure.lang.ExceptionInfo: NO_SOURCE_FILE [line 1, col 5] Invalid 
> keyword: :a/0. {:type :reader-exception, :ex-kind :reader-error, :file 
> "NO_SOURCE_FILE", :line 1, :col 5} ...
>
> If instead I use the the keyword function, it produces the desired result:
>
> (keyword "a" "0")
> ;= :a/0
>
>
> It seems I can get away with almost anything using the keyword function. 
> For example:
>
> (keyword "a" "0/1")
> ;= :a/0/1
>
> I'm wondering then, what is the "correct" behaviour if there is such a 
> thing in this case? I know that in Clojure the behaviour appears once again 
> to be slightly different, and the main docs seem to cater more to Clojure 
> than to CLJS.
>
> Thank you,
> Ali
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Inconsistency in creating keywords

2018-03-01 Thread Thomas Heller
Clojure follows the principle of "Garbage in, Garbage out" for a lot of 
internal functions. Meaning you are responsible for ensuring that you only 
use valid data when calling those functions as the validation itself 
carries overhead which the core fns should not have.

:a/0 fails because the reader does those checks and fails. The keyword fn 
does no checks and lets you have your invalid keywords. They are still 
invalid keywords though. Keywords are not allowed to start with numbers.

https://github.com/edn-format/edn might be a helpful reference about that 
is allowed and what isn't.

HTH

On Thursday, March 1, 2018 at 1:14:34 PM UTC+1, outr...@gmail.com wrote:
>
> I've encountered a problem when creating namespaced keywords using the 
> literal syntax, specifically using keywords which start with numbers. 
>
> If I try using the literal syntax, entering the following at the REPL, I 
> get the exception which follows it:
>
> :a/0
> ;= clojure.lang.ExceptionInfo: NO_SOURCE_FILE [line 1, col 5] Invalid 
> keyword: :a/0. {:type :reader-exception, :ex-kind :reader-error, :file 
> "NO_SOURCE_FILE", :line 1, :col 5} ...
>
> If instead I use the the keyword function, it produces the desired result:
>
> (keyword "a" "0")
> ;= :a/0
>
>
> It seems I can get away with almost anything using the keyword function. 
> For example:
>
> (keyword "a" "0/1")
> ;= :a/0/1
>
> I'm wondering then, what is the "correct" behaviour if there is such a 
> thing in this case? I know that in Clojure the behaviour appears once again 
> to be slightly different, and the main docs seem to cater more to Clojure 
> than to CLJS.
>
> Thank you,
> Ali
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.