Re: [ANN] Primitive Operator

2017-07-03 Thread Phillip Lord

Yes, but it doesn't supoort ints for all the operators, as far as I can
tell.

You are right, though, perhaps I should look at this also.

Phil

Max Penet  writes:

> This seems quite similar to https://github.com/ztellman/primitive-math. Did 
> you know about it?
>
> On Monday, July 3, 2017 at 11:44:40 AM UTC+2, Phillip Lord wrote:
>>
>>
>>
>> This is the first alpha release of my new library! Comments welcome. 
>>
>> Clojure has an extensive system for dealing with numbers, including 
>> error on overflow, or auto-promotion, defaulting to long and double data 
>> types. 
>>
>> This is all well and good, but irritating if you need to implement an 
>> algorithm which depends on ints overflowing for instance. While, clojure 
>> provides functions for operating over ints, the names tend to be long 
>> and wieldy, such as clojure.core/unchecked-int-add. Clojure is also 
>> rather inconsistent; for example, the bit-shifting operators in Java are 
>> not accessible in Clojure over ints. 
>>
>> This library provides accessible, easily named float and int functions 
>> for Clojure. Where possible, functions with the same name as the 
>> operators are provided as well as names (<< and left-shift). Three Java 
>> operators are not valid symbols in clojure (~, % and ^), so just have 
>> names. Short reader literals are also provided to simplify the creation 
>> of ints and float. 
>>
>> (require '[primititve.operator.integer :as i]) 
>>
>> (i/+ 10 10) 
>> => 20 
>>
>> (type (i/+ 10 10)) 
>> => java.lang.Integer 
>>
>> (i/add 10 10) 
>> => 20 
>>
>> (i/not 10) 
>> => -11 
>>
>> (i/+ #p/i 10 #p/i 10) 
>> => 20 
>>
>>
>> https://github.com/phillord/primitive-operator 

-- 
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: [ANN] Primitive Operator

2017-07-03 Thread Phillip Lord
Nicola Mometto  writes:

> Hi Phillip,
>
> I've had a very quick look at the code and I've spotted a few issues,
> here's my feedback:
>
> 1- all your functions will cause input args and return value to be
> boxed. There's a few ways to avoid it, none of which are particularly
> pretty. If your library is not worried about performance but just
> about behaviour then this is not a problem, if it is, I can guide you
> through ways to avoid boxing (primitive type hinting of ints and
> floats is unfortunately not an option).

I'd be happy to get that information. Performance is not really my
concern here, rather it is ensuring that I can replicate int/float based
algorithms in Clojure.

Having said that, all things being equal, performance is better than not.


> 2- defining a var called &, while technically valid, is not a good
> idea. syntax-quote will not resolve vars named & to avoid collision
> with the & rest syntax in destructuring, so I'd consider using a
> different name

Ah, yes. Clojure really sucks up all those handy punctuation characters.


> 3- clojure/core encourages libraries to provide "sufficiently uniquely
> named data literals", p/i and p/f to me while convenient don't seem
> unique enough to be safely included in a library. This one could be
> detabatable

Yeah, I was worried about that. If they are longer, though, it defeats
the point.

#primitive/int 10
(int 10)

Phil

-- 
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: [ANN] Primitive Operator

2017-07-03 Thread Phillip Lord
Nicola Mometto  writes:

> Hi Phillip,
>
> I've had a very quick look at the code and I've spotted a few issues,
> here's my feedback:
>
> 1- all your functions will cause input args and return value to be
> boxed. There's a few ways to avoid it, none of which are particularly
> pretty. If your library is not worried about performance but just
> about behaviour then this is not a problem, if it is, I can guide you
> through ways to avoid boxing (primitive type hinting of ints and
> floats is unfortunately not an option).

I'd be happy to get that information. Performance is not really my
concern here, rather it is ensuring that I can replicate int/float based
algorithms in Clojure.

Having said that, all things being equal, performance is better than not.


> 2- defining a var called &, while technically valid, is not a good
> idea. syntax-quote will not resolve vars named & to avoid collision
> with the & rest syntax in destructuring, so I'd consider using a
> different name

Ah, yes. Clojure really sucks up all those handy punctuation characters.


> 3- clojure/core encourages libraries to provide "sufficiently uniquely
> named data literals", p/i and p/f to me while convenient don't seem
> unique enough to be safely included in a library. This one could be
> detabatable

Yeah, I was worried about that. If they are longer, though, it defeats
the point.

#primitive/int 10
(int 10)

Phil

-- 
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: [ANN] Primitive Operator

2017-07-03 Thread Tomasz Sulej
this article may be helpful:
http://insideclojure.org/2014/12/15/warn-on-boxed/

On 3 July 2017 at 13:36, Tomasz Sulej  wrote:

> When you decide to work with longs and doubles you can achieve the same in
> pure clojure
> Just add primitive type hints and (set! *unchecked-math* true).
> (to see if you have boxed operations add (set! *unchecked-math*
> :warn-on-boxed))
>
> (set! *unchecked-math* :warn-on-boxed) ;; set math to be unchecked and
> warn if boxed operations are used
>
> (defn add ^long [^long a ^long b] (+ a b))
> (defn not ^long [^long a] (bit-not a))
>
> (add 10 10)
> ;; => 20
>
> (not 10)
> ;; => -11
>
> (type (add 10 10))
> ;; => java.lang.Long
>
> On 3 July 2017 at 11:44, Phillip Lord 
> wrote:
>
>>
>>
>> This is the first alpha release of my new library! Comments welcome.
>>
>> Clojure has an extensive system for dealing with numbers, including
>> error on overflow, or auto-promotion, defaulting to long and double data
>> types.
>>
>> This is all well and good, but irritating if you need to implement an
>> algorithm which depends on ints overflowing for instance. While, clojure
>> provides functions for operating over ints, the names tend to be long
>> and wieldy, such as clojure.core/unchecked-int-add. Clojure is also
>> rather inconsistent; for example, the bit-shifting operators in Java are
>> not accessible in Clojure over ints.
>>
>> This library provides accessible, easily named float and int functions
>> for Clojure. Where possible, functions with the same name as the
>> operators are provided as well as names (<< and left-shift). Three Java
>> operators are not valid symbols in clojure (~, % and ^), so just have
>> names. Short reader literals are also provided to simplify the creation
>> of ints and float.
>>
>> (require '[primititve.operator.integer :as i])
>>
>> (i/+ 10 10)
>> => 20
>>
>> (type (i/+ 10 10))
>> => java.lang.Integer
>>
>> (i/add 10 10)
>> => 20
>>
>> (i/not 10)
>> => -11
>>
>> (i/+ #p/i 10 #p/i 10)
>> => 20
>>
>>
>> https://github.com/phillord/primitive-operator
>>
>> --
>> 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: [ANN] Primitive Operator

2017-07-03 Thread Max Penet
This seems quite similar to https://github.com/ztellman/primitive-math. Did 
you know about it?

On Monday, July 3, 2017 at 11:44:40 AM UTC+2, Phillip Lord wrote:
>
>
>
> This is the first alpha release of my new library! Comments welcome. 
>
> Clojure has an extensive system for dealing with numbers, including 
> error on overflow, or auto-promotion, defaulting to long and double data 
> types. 
>
> This is all well and good, but irritating if you need to implement an 
> algorithm which depends on ints overflowing for instance. While, clojure 
> provides functions for operating over ints, the names tend to be long 
> and wieldy, such as clojure.core/unchecked-int-add. Clojure is also 
> rather inconsistent; for example, the bit-shifting operators in Java are 
> not accessible in Clojure over ints. 
>
> This library provides accessible, easily named float and int functions 
> for Clojure. Where possible, functions with the same name as the 
> operators are provided as well as names (<< and left-shift). Three Java 
> operators are not valid symbols in clojure (~, % and ^), so just have 
> names. Short reader literals are also provided to simplify the creation 
> of ints and float. 
>
> (require '[primititve.operator.integer :as i]) 
>
> (i/+ 10 10) 
> => 20 
>
> (type (i/+ 10 10)) 
> => java.lang.Integer 
>
> (i/add 10 10) 
> => 20 
>
> (i/not 10) 
> => -11 
>
> (i/+ #p/i 10 #p/i 10) 
> => 20 
>
>
> https://github.com/phillord/primitive-operator 
>
>

-- 
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: [ANN] Primitive Operator

2017-07-03 Thread Nicola Mometto
Hi Phillip,

I've had a very quick look at the code and I've spotted a few issues, here's my 
feedback:

1- all your functions will cause input args and return value to be boxed. 
There's a few ways to avoid it, none of which are particularly pretty. If your 
library is not worried about performance but just about behaviour then this is 
not a problem, if it is, I can guide you through ways to avoid boxing 
(primitive type hinting of ints and floats is unfortunately not an option).

2- defining a var called &, while technically valid, is not a good idea. 
syntax-quote will not resolve vars named & to avoid collision with the & rest 
syntax in destructuring, so I'd consider using a different name

3- clojure/core encourages libraries to provide "sufficiently uniquely named 
data literals", p/i and p/f to me while convenient don't seem unique enough to 
be safely included in a library. This one could be detabatable

Nicola

> On 3 Jul 2017, at 10:44, Phillip Lord  wrote:
> 
> 
> 
> This is the first alpha release of my new library! Comments welcome.
> 
> Clojure has an extensive system for dealing with numbers, including
> error on overflow, or auto-promotion, defaulting to long and double data
> types.
> 
> This is all well and good, but irritating if you need to implement an
> algorithm which depends on ints overflowing for instance. While, clojure
> provides functions for operating over ints, the names tend to be long
> and wieldy, such as clojure.core/unchecked-int-add. Clojure is also
> rather inconsistent; for example, the bit-shifting operators in Java are
> not accessible in Clojure over ints.
> 
> This library provides accessible, easily named float and int functions
> for Clojure. Where possible, functions with the same name as the
> operators are provided as well as names (<< and left-shift). Three Java
> operators are not valid symbols in clojure (~, % and ^), so just have
> names. Short reader literals are also provided to simplify the creation
> of ints and float.
> 
> (require '[primititve.operator.integer :as i])
> 
> (i/+ 10 10)
> => 20
> 
> (type (i/+ 10 10))
> => java.lang.Integer
> 
> (i/add 10 10)
> => 20
> 
> (i/not 10)
> => -11
> 
> (i/+ #p/i 10 #p/i 10)
> => 20
> 
> 
> https://github.com/phillord/primitive-operator
> 
> --
> 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.


signature.asc
Description: Message signed with OpenPGP