Re: (type ...) vs (class ...)

2018-10-25 Thread Rick Moynihan
I think the main intention of type is to be used as a more generic version
of class, that lets clojure data participate alongside java objects etc
with multi-methods etc.

i.e.

(defmulti foo type)

(defmethod foo java.lang.String [x]
  :string-dispatched)

(defmethod foo :my-clojure-type [x]
  :my-clojure-type-dispatched)

(foo ^{:type :my-clojure-type} {:blah :blah}) ;; =>
:my-clojure-type-dispatched

derive et al also let you use keywords to augment java class hierarchies
with new types, provide multiple inheritance and priorities with
prefer-method etc.

R.

On Fri, 12 Feb 2016 at 21:37, Alan Thompson  wrote:

> Hey - Just saw something on the clojure.core/type function:
>
>
>
> (defn type
> "Returns the :type metadata of x, or its Class if none"
> {:added "1.0"
> :static true}
> [x]
> (or (get (meta x) :type) (class x)))
>
>
> I have never seen this before, and it appears the :type metadata is not
> used in the clojure.core source code itself.  Is this ever used for
> anything or is it just a vestigial remnant from long ago?
>
> Alan
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (type ...) vs (class ...)

2018-10-24 Thread Armando Blancas
Found this:

https://groups.google.com/forum/#!searchin/clojure/%22type$20metadata%22%7Csort:date/clojure/LBGsPs2__pQ/oLgx_kgmQxgJ

:tag is applied to source forms to communicate type hints to the 
compiler. :type can be used, by convention, to add 'type names' to 
runtime data structures that support metadata. The type function will 
return the :type metadata if present, else the class, making it a 
handy dispatch function. Neither :tag nor :type are used directly by 
isa? 

Rich



On Wednesday, October 24, 2018 at 12:30:14 AM UTC-7, Didier wrote:
>
> Reviving this thread, as I'd like to kmow if someone can explain the 
> purpose of the type metadata and what is responsible for adding it?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (type ...) vs (class ...)

2018-10-24 Thread Justin Smith
the type function in clojure.core lets you override the nominal class of an
object with the :type metadata

user=> (type {})

clojure.lang.PersistentArrayMap

user=> (type ^{:type :foo} {})

:foo

On Wed, Oct 24, 2018 at 9:41 AM alex  wrote:

> Looks like pre defrecord stuff used in early days to add "type" to map.
> Can still be used if you need "type" on a map without using defrecord.
>
> среда, 24 октября 2018 г., 10:30:14 UTC+3 пользователь Didier написал:
>
>> Reviving this thread, as I'd like to kmow if someone can explain the
>> purpose of the type metadata and what is responsible for adding it?
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (type ...) vs (class ...)

2018-10-24 Thread alex
Looks like pre defrecord stuff used in early days to add "type" to map. Can 
still be used if you need "type" on a map without using defrecord.

среда, 24 октября 2018 г., 10:30:14 UTC+3 пользователь Didier написал:
>
> Reviving this thread, as I'd like to kmow if someone can explain the 
> purpose of the type metadata and what is responsible for adding it?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (type ...) vs (class ...)

2018-10-24 Thread Didier
Reviving this thread, as I'd like to kmow if someone can explain the purpose of 
the type metadata and what is responsible for adding it?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (type ...) vs (class ...)

2016-02-12 Thread Kevin Downey
On 02/12/2016 01:37 PM, Alan Thompson wrote:
> Hey - Just saw something on the clojure.core/type function:
> 
> 
> 
> (defn type
>   "Returns the :type metadata of x, or its Class if none"
>   {:added "1.0"
>   :static true}
>   [x]
>   (or (get (meta x) :type) (class x)))
> 
> 
> 
> I have never seen this before, and it appears the :type metadata is not
> used in the clojure.core source code itself.  Is this ever used for
> anything or is it just a vestigial remnant from long ago?
> 
> Alan

It is used by the printing system (see core_print.clj). If I write a
multimethod that is dispatching on type/class whatever, `type` is the
first function I reach for.

> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (type ...) vs (class ...)

2016-02-12 Thread Kevin Downey
On 02/12/2016 01:47 PM, Kevin Downey wrote:
> On 02/12/2016 01:37 PM, Alan Thompson wrote:
>> Hey - Just saw something on the clojure.core/type function:
>>
>>
>>
>> (defn type
>>  "Returns the :type metadata of x, or its Class if none"
>>  {:added "1.0"
>>  :static true}
>>  [x]
>>  (or (get (meta x) :type) (class x)))
>>
>>
>>
>> I have never seen this before, and it appears the :type metadata is not
>> used in the clojure.core source code itself.  Is this ever used for
>> anything or is it just a vestigial remnant from long ago?
>>
>> Alan
> 
> It is used by the printing system (see core_print.clj). If I write a
> multimethod that is dispatching on type/class whatever, `type` is the
> first function I reach for.

Oh, my mistake, print-method actually re-implements `type`, with the
added restriction that is has to be a keyword.

> 
>>
>> -- 
>> 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 unsubscribe from this group and stop receiving emails from it, send
>> an email to clojure+unsubscr...@googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
> 
> 


-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.