aaaa ok...It turns out I can answer my own question!a blog post by Brian
Carper [1] cleared it out for me...I am looking for a *custom literal* -
not a tagged literal and for that one has to patch the reader which I'm
sure is *not* a good idea! anyway it seems I 've misunderstood certain
things...back to reading! :-)
[1] http://briancarper.net/blog/449/
Jim
On 04/01/13 19:20, Jim - FooBar(); wrote:
Greetings and all best wishes for 2013 to everyone!!! :-)
First of all, forgive me for hijacking this thread but I what I
started to do originated from this thread and so I feel it is related.
So, for the fun (and the learning) of it, I thought to create a queue
literal myself as suggested in this thread. As you might expect I
started with function constructor first. That was pretty easy...I
settled for something like this:
(defn queue
([] clojure.lang.PersistentQueue/EMPTY)
([& items] (apply conj (queue) items)))
This gives me behaviour like the rest of the ctor fns (vector, list
etc etc) so that's good. Now I need a literal the reader can
understand so it shows up nicely on the repl. The #[] seems like a
reasonable choice for this exercise but from what I understand from
reading here (
http://clojure.org/reader#The%20Reader--Tagged%20Literals) I can't
have #[] but rather #foo/[] because r eader tags without namespace
qualifiers are reserved for Clojure itself.
So, in the top directory of a dummy project I need a data_readers.clj
file with this in: {foo/[] dummy.foo/queue}.
Can someone please explain how do you then use such literal? Again,
from the website I understand that you would use it like this:
#foo/[] [1 2 3 4] while in fact what I'd want is : #foo/[1 2 3 4]. I
feel I'm missing something big here... How have other people tried to
implement the #[] literal?
thanks a lot in advance!
Jim
On 31/12/12 11:48, Jozef Wagner wrote:
This is great! I will use it for my #[] reader literal.
Thank you,
JW
On Monday, December 31, 2012 1:20:11 AM UTC+1, dgrnbrg wrote:
You can also patch the LispReader in jvm Clojure without dropping
to Java. Here's an example of that to add a #b reader literal:
https://github.com/dgrnbrg/piplin/blob/master/src/piplin/types/bits.clj#L216
<https://github.com/dgrnbrg/piplin/blob/master/src/piplin/types/bits.clj#L216>
On Sunday, December 30, 2012 7:38:44 AM UTC-6, Ambrose
Bonnaire-Sergeant wrote:
Jozef,
How do you achieve that?
Thanks,
Ambrose
On Sun, Dec 30, 2012 at 7:45 PM, Jozef Wagner
<jozef....@gmail.com> wrote:
I use it in Clojurescript for a custom tuple type.
For small number of items, deftypes are way faster to
create and access than PersistentVectors. I use tuple
type e.g. for returning multiple values from a function.
Implementing #[] allowed me to have a compact syntax for
creating and destructuring such tuples.
(defn foo [a b]
#[(+ a b) (- a b) (* a b)])
(defn foo []
(let [#[plus minus times] (foo 1 2)]
(str "bla bla" plus "blaah" minus)))
JW
On Friday, December 28, 2012 11:15:52 PM UTC+1, vemv wrote:
I was just wondering - given that we have the #() and
#{} literals, why not a #[] as well? Queues look like
a good fit.
--
You received this message because you are subscribed to
the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please
be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
<http://groups.google.com/group/clojure?hl=en>
--
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 are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
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 are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en