Re: format and printf can't be used with BigInt

2011-07-28 Thread Andrea Tortorella
Thanks for your replies,

+1 for enhancing format

Maybe it could handle also rationals, converting them to doubles, but
it could be to much.

On Jul 28, 9:47 am, Sean Corfield seancorfi...@gmail.com wrote:
 On Wed, Jul 27, 2011 at 11:48 PM, Tom Faulhaber tomfaulha...@gmail.com 
 wrote:
  FWIW, clojure.pprint.cl-format handles this fine in 1.3:

  (cl-format nil ~d 2N)
  = 2

 Wow, I just spent the last 30 minutes reading Common Lisp the
 Language, 2nd Ed, chapter 22 which describes how powerful and
 mind-bending that is...
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View --http://corfield.org/
 World Singles, LLC. --http://worldsingles.com/
 Railo Technologies, Inc. --http://www.getrailo.com/

 Perfection is the enemy of the good.
 -- Gustave Flaubert, French realist novelist (1821-1880)

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


Re: format and printf can't be used with BigInt

2011-07-28 Thread Andrea Tortorella
As I said tweaking `format` to work on rationals could be too much,
and i can restate that as it is too much.

Nevertheless, extending it to work on bigint doesn't seem to me really
an edge case, given that i could get a bigint out of any function that
uses autopromotion, so:

(printf %d (autopromoting-factorial N))

would work only for small enough inputs. That's a bit surprising, so i
keep my +1 while I learn cl-format.

Then, if cl-format, is the true formatting function for clojure, why
isn't it in core?

On Jul 28, 2:48 pm, Chas Emerick cemer...@snowtide.com wrote:
 Tweaking `format` so that it accounts for all sorts of edge cases almost 
 certainly isn't going to happen, and would be a horrible kludge in any case.

 To extend Tom's point, if you really want a format that knows about all of 
 Clojure's scalars and data structures, cl-format is what you want, and it 
 comes with the language.  If you don't want to learn about cl-format, then a 
 local wrapper around `format` that does whatever you like re: coercions to 
 standard Java numeric types would be ~3 lines.

 - Chas

 On Jul 28, 2011, at 7:52 AM, Andrea Tortorella wrote:







  Thanks for your replies,

  +1 for enhancing format

  Maybe it could handle also rationals, converting them to doubles, but
  it could be to much.

  On Jul 28, 9:47 am, Sean Corfield seancorfi...@gmail.com wrote:
  On Wed, Jul 27, 2011 at 11:48 PM, Tom Faulhaber tomfaulha...@gmail.com 
  wrote:
  FWIW, clojure.pprint.cl-format handles this fine in 1.3:

  (cl-format nil ~d 2N)
  = 2

  Wow, I just spent the last 30 minutes reading Common Lisp the
  Language, 2nd Ed, chapter 22 which describes how powerful and
  mind-bending that is...

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


format and printf can't be used with BigInt

2011-07-27 Thread Andrea Tortorella
Hi everyone,
I don't know where to post about bugs (if this is a bug).
Anyway in clojure 1.3 with the new numerics:

(format %d 2N)

throws IllegalFormatConversionException, is it a bug? are there any
workarounds?

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


Expanding symbols and expression in macros.

2011-07-13 Thread Andrea Tortorella
I'm not an expert in macros, and maybe this is a stupid question but i
think there should be a general pattern for this.

I' ve a function:

(defn choose* [f  choices]
  Applies f to one of the choices
. .)

And this macro:

(defmacro choose [[c choices]  body]
 `(choose* (fn [~c] ~@body) ~@choices))

Now if i call it with a literal sequence:

(choose [x [:a :b :c]]
   (println x))

it correctly expands to:

(choose* (fn [x] (println x)) :a :b :c)

but if i have:

(def y [:a :b :c])
(choose [x y]
  (println x))

it gives me an error: don't know how to create ISeq from symbol.

with an expression:

(choose [x (vec 2 3 4)]
   (println x))

it expands to:

(choose* (fn [x] (println x)) vec 2 3 4)

I knew it could not be that simple, and i also understand why i get
theese expansions, but i don't get how to solve it.
So what's the pattern for something like this, where you want to
evaluate a symbol or an expression before expansion?

Andrea

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


protocols metadata

2010-04-30 Thread Andrea Tortorella
Hi everyone,

Reading the documentation I found that except for the docstring there
is no way to tell that InternalReduce is a protocol, it's tagged
simply as a var.
Why don't add a :protocol true to the metadata for protocols
like :macro true for macros?

Andrea.

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


Protocols and Types

2010-03-03 Thread Andrea Tortorella
Hi everyone,

if I run this code:

(defprotocol P
 (foo [x]))

(deftype T []
  P
  (foo [] dummy))

(extends? P T)
;== nil
(satisfies? P T)
;== nil
(extenders P)
;==nil

are they not yet implemented?

anyway when I run

(type P)
 ;== clojure.lang.PersistentArrayMap

So the protocol is simply a map.

I thought that P had some kind of protocol type, that extends
something like:

(defprotocol ProtocolProtocol
 (extends? [p t])
 (extenders [p])
 (satisfies? [p t]))


(deftype Protocol [methods implementers]
 ProtocolProtocol
 (extends? [t] ...)
 (extenders [] ...)
 (satisfies? [t] ...))

Does it make any sense?

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


Re: Protocols and Types

2010-03-03 Thread Andrea Tortorella
I'm not on my machine so i'cant experiment, i tried on  #clojure with
clojurebot but it's not 1.2, so i ask here,
 given that a protocol is represented as a simple map, which is the
way to know if something is infact a protocol.
Or suppose i want to add a function that works on protocols how can i
do that?

  I thought that P had some kind of protocol type, that extends
  something like:

 As you found out, it doesn't. But then, you shouldn't care about how 
 protocols are represented in memory, as long as the documented API functions 
 work.

 Konrad.

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


Re: leiningen with latest clojure

2009-12-19 Thread Andrea Tortorella
Thanks for your answers.
Yes, I'd like to use the new branch not the master one, anyway having
this dependency in project.clj:

[org.clojure/clojure 1.1.0-new-SNAPSHOT]

and using lein repl, I still have 1.1.0-alpha-SNAPSHOT at the repl.

I added the spec to the dev-dependencies too, but still having no
success.

Andrea.

On Dec 19, 3:56 am, Alex Osborne a...@meshy.org wrote:
 defn dev...@gmail.com writes:
  On Dec 18, 7:00 am, Andrea Tortorella elian...@gmail.com wrote:
  I'd like to ask how to use leiningen with the latest clojure
  development new branch, is this possible?
  This will pull down 1.1.0-master-SNAPSHOT per the settings in
  project.clj which is as new as Dec. 18th, 16:00 at the time of writing
  this.

 I think Andrea meant the new branch rather than the master branch.
 Just use 1.1.0-new-SNAPSHOT as the version number for both clojure and
 clojure-contrib and you should be okay.  Just be aware that if you pull
 in other Clojure libraries they may be compiled against master and
 won't work against new.  This compatibility will hopefully be sorted
 out in future as slim jars (not AOT-compiled) are probably going to
 become the default in most tools.

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


leiningen with latest clojure

2009-12-18 Thread Andrea Tortorella
I'm new to the group, I've been following clojure development for a
while, and I want to thank rich and you all for the fantastic work.

I'd like to ask how to use leiningen with the latest clojure
development new branch, is this possible?

thanks,
Andrea Tortorella

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