[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.


[ClojureScript] Inconsistency in creating keywords

2018-03-01 Thread outrovurt
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.