Re: delays are forced by deref too early?

2009-09-21 Thread Christophe Grand
On Mon, Sep 21, 2009 at 6:48 PM, patrickdlogan wrote:

>
> > (force del) ; note that @del would be equivalent here
>
> This is at the core of my question. I did not understand that a delay
> is something that can be deref'd until I read the source.
>

Well, it's documented but not on #'delay:

=> (doc deref)
-
clojure.core/deref
([ref])
  Also reader macro: @ref/@agent/@var/@atom/@delay/@future. Within a
transaction,
  returns the in-transaction-value of ref, else returns the
  most-recently-committed value of ref. When applied to a var, agent
  or atom, returns its current state. When applied to a delay, forces
  it if not already forced. When applied to a future, will block if
  computation not complete


I'll open a ticket for changing the docstring of delay to mention deref/@.

Christophe




-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
-~--~~~~--~~--~--~---



Re: delays are forced by deref too early?

2009-09-21 Thread patrickdlogan

> (force del) ; note that @del would be equivalent here

This is at the core of my question. I did not understand that a delay
is something that can be deref'd until I read the source.

Knowing now that a delay does behave this way, I can work with it as
such. Given the doc string for delay, I wasn't sure whether this was
accidental behavior due to the implementation, or by design.

Thanks

--~--~-~--~~~---~--~~
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: delays are forced by deref too early?

2009-09-21 Thread Christophe Grand
Hi Patrick,

If that really annoys you, you can tell the repl to display Delay instances
as dumb objects:
(defmethod print-method clojure.lang.Delay [x w] ((get-method print-method
Object) x w))

user=> (defmethod print-method clojure.lang.Delay [x w] ((get-method
print-method Object) x w))
#
user=> (def del (delay (println "printed") (+ 2 3)))
#'net.cgrand.parsley/del
user=> del
#
user=> (force del) ; note that @del would be equivalent here
printed
5

Christophe

On Mon, Sep 21, 2009 at 5:53 PM, patrickdlogan wrote:

>
> I expected a delay only to be forced by an explicit call to force.
> instead it looks like, being a kind of IDeref, a delay will be forced
> by the REPL.
>
> e.g.
>
> user=> (def del (delay (println "printed") (+ 2 3)))
> #'user/del
> user=> del
> printed
> #
> user=> (force del)
> 5
>
> The documentation seems to imply the only way to force a delay is
> through the force procedure...
>
> " Takes a body of expressions and yields a Delay object that will
>  invoke the body only the first time it is forced (with force), and
>  will cache the result and return it on all subsequent force
>  calls."
>
> >
>


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
-~--~~~~--~~--~--~---



Re: delays are forced by deref too early?

2009-09-21 Thread Jarkko Oranen

On Sep 21, 6:53 pm, patrickdlogan  wrote:
> I expected a delay only to be forced by an explicit call to force.
> instead it looks like, being a kind of IDeref, a delay will be forced
> by the REPL.
>
> e.g.
>
> user=> (def del (delay (println "printed") (+ 2 3)))
> #'user/del
> user=> del
> printed
> #
> user=> (force del)
> 5
>
> The documentation seems to imply the only way to force a delay is
> through the force procedure...

I'm pretty sure force is still causing the evaluation... Just
indirectly :)

The delay here is forced by its print method, which, as you can see,
also prints the value. Delays could be changed to print something like
#, but I wonder if that's really useful.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



delays are forced by deref too early?

2009-09-21 Thread patrickdlogan

I expected a delay only to be forced by an explicit call to force.
instead it looks like, being a kind of IDeref, a delay will be forced
by the REPL.

e.g.

user=> (def del (delay (println "printed") (+ 2 3)))
#'user/del
user=> del
printed
#
user=> (force del)
5

The documentation seems to imply the only way to force a delay is
through the force procedure...

" Takes a body of expressions and yields a Delay object that will
  invoke the body only the first time it is forced (with force), and
  will cache the result and return it on all subsequent force
  calls."

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