Strange eval behavior making Java types more generic

2015-08-28 Thread psfblair
I'm pretty new to Clojure, so please bear with me if this is obvious for 
some reason. Maybe the answer is out there and I've been looking in the 
wrong place.

I'm seeing some strange behavior losing type information when using eval in 
certain circumstances. Here is an example:

Eval-ing a Timestamp is still a Timestamp:

(def my-timestamp (clj-time.coerce/to-timestamp (java.util.Date.)))
=> #'user/my-timestamp
(type my-timestamp)
=> java.sql.Timestamp
(eval my-timestamp)
=> #inst "2015-08-28T15:03:10.55700-00:00"
(type (eval my-timestamp))
=> java.sql.Timestamp

Using the Timestamp as a hash value also works as expected:

(def timestamp-holder {:a my-timestamp})
=> #'user/timestamp-holder
(type (:a timestamp-holder))
=> java.sql.Timestamp
(eval (:a timestamp-holder))
=> #inst "2015-08-28T15:03:10.55700-00:00"
(type (eval (:a timestamp-holder)))
=> java.sql.Timestamp


But now instead eval the hash map and its type gets more generic:

(eval timestamp-holder)
=> {:a #inst "2015-08-28T15:03:10.557-00:00"}
(type (:a (eval timestamp-holder)))
=> java.util.Date

Is this expected behavior?

-- 
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: Fighting with Emacs ;-)

2010-10-05 Thread psfblair
I would have sworn that when I was doing C-c C-r originally I was
seeing the region be copied in at the REPL prompt and evaluated. That
isn't what's happening now--can anyone else confirm that I shouldn't
be expecting to see this?

Thx.

On Sep 28, 1:37 pm, Mike Meyer  wrote:
> On Tue, 28 Sep 2010 03:58:56 -0700 (PDT)
>
>
>
>
>
> psfblair  wrote:
> > I could do this, but right now I'm just playing with C-c C-r to
> > evaluate regions, instead of compiling the entire file. And I'd swear
> > this used to put the evaluation in the REPL.
>
> > On Sep 27, 10:59 pm, Alan  wrote:
> > > C-c C-k in the .clj buffer is easier and equivalent (or at least very
> > > similar)
>
> > > On Sep 27, 12:27 pm, Linus Ericsson 
> > > wrote:
>
> > > > I recognize that one. The repl haven't loaded the file your editing.
>
> > > > My (temporary) solution is to do a (load-file "")
> > > > after each edit that I want to debug, but that's a bit boring. I guess 
> > > > there
> > > > is some kind of reload feature somewhere...
>
> > > > /Linus
>
> > > > 2010/9/27 psfblair 
>
> > > > > I found the old thread below, but unfortunately the solution isn't
> > > > > working for me. If I have a foo.clj file in a buffer and evaluate
> > > > > region on
>
> > > > > (defn foo [] (+ 1 2))
>
> > > > > I get
>
> > > > > #'user/foo in the minibuffer. If I then evaluate region on
>
> > > > > (foo)
>
> > > > > I get 3 in the minibuffer. The slime REPL is giving me a prompt user>
> > > > > so I'm assuming it's in the user namespace, but I can't seem to get
> > > > > expressions from the text buffer to evaluate in there.
>
> > > > > On Mar 28, 5:01 am, Michał Marczyk  wrote:
>
> > > > > > On 27 March 2010 22:25, alux  wrote:
>
> > > > > > > But now I see people use the result of this evaluation in their 
> > > > > > > REPL
> > > > > > > (I see this in videos, so I cant ask 'em :). This doesnt work at 
> > > > > > > all
> > > > > > > for me. I get the result in the minibuffer (this thing at the very
> > > > > > > bottom) and thats it.
>
> > > > > > If the form you evaluate is of the def* variety, it's going to 
> > > > > > affect
> > > > > > the namespace it resides in and not the namespace of the REPL. Thus,
> > > > > > if you have e.g. (ns foo) at the top of the file, yet you're working
> > > > > > in the user namespace at the REPL, then after using C-x C-e to
> > > > > > evaluate a function definition in your file, you'll have to say
> > > > > > something like foo/bar to reach it from the REPL. (Or (use 
> > > > > > :reload-all
> > > > > > 'foo), if you prefer.)
>
> > > > > > If there is no namespace declaration in the file, then the 
> > > > > > expression
> > > > > > will be evaluated in the user namespace, which means that you'll be
> > > > > > able to use it straight away if that's your REPL's namespace. (If 
> > > > > > you
> > > > > > say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say
> > > > > > something like user/bar to reach your function.)
>
> > > > > > Sincerely,
> > > > > > Michał
>
> > > > > --
> > > > > 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
>
> Actually, this sounds like standard behavior for an integrated
> EMACS/REPL to me: "sending" code from the edited file to the REPL
> evaluates them in the REPL, but doesn't print them: you either get a
> message in the minibuffer or a short note in the buffer. Normal usage
> is to edit a function, send it to the REPL, then switch to the repl
> and test the newly defined function(s) (usually just M-p to recall the
> just failed test).
>
> In particular, SWANK/SLIME prints the value of the last expression in
> the evaluate region in the minibuffer. At least, that's what' it's
> always done for me.
>
>         --
> Mike Meyer           http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org

-- 
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: Fighting with Emacs ;-)

2010-09-28 Thread psfblair
I'm just doing simple Clojure exercises with simple evaluations of
regions in the .clj buffer. I don't have an ns form, but I was under
the impression that this put me in the user namespace, which is what
my REPL is in. If I evaluate *ns* in the .clj buffer I get # in the minibuffer, and I get the same when evaluating *ns* in
the SLIME buffer. Is it possible that this is some kind of mismatch
between Unicode and ASCII?

On Sep 28, 3:16 am, Phil Hagelberg  wrote:
> On Mon, Sep 27, 2010 at 4:03 AM, psfblair  wrote:
> > I found the old thread below, but unfortunately the solution isn't
> > working for me. If I have a foo.clj file in a buffer and evaluate
> > region on
>
> > (defn foo [] (+ 1 2))
>
> > I get
>
> > #'user/foo in the minibuffer.
>
> What does your ns form look like? SLIME uses a regex to determine the
> namespace; it could be that your ns form isn't getting caught by it.
>
> -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


Re: Fighting with Emacs ;-)

2010-09-28 Thread psfblair
I could do this, but right now I'm just playing with C-c C-r to
evaluate regions, instead of compiling the entire file. And I'd swear
this used to put the evaluation in the REPL.

On Sep 27, 10:59 pm, Alan  wrote:
> C-c C-k in the .clj buffer is easier and equivalent (or at least very
> similar)
>
> On Sep 27, 12:27 pm, Linus Ericsson 
> wrote:
>
>
>
> > I recognize that one. The repl haven't loaded the file your editing.
>
> > My (temporary) solution is to do a (load-file "")
> > after each edit that I want to debug, but that's a bit boring. I guess there
> > is some kind of reload feature somewhere...
>
> > /Linus
>
> > 2010/9/27 psfblair 
>
> > > I found the old thread below, but unfortunately the solution isn't
> > > working for me. If I have a foo.clj file in a buffer and evaluate
> > > region on
>
> > > (defn foo [] (+ 1 2))
>
> > > I get
>
> > > #'user/foo in the minibuffer. If I then evaluate region on
>
> > > (foo)
>
> > > I get 3 in the minibuffer. The slime REPL is giving me a prompt user>
> > > so I'm assuming it's in the user namespace, but I can't seem to get
> > > expressions from the text buffer to evaluate in there.
>
> > > On Mar 28, 5:01 am, Michał Marczyk  wrote:
>
> > > > On 27 March 2010 22:25, alux  wrote:
>
> > > > > But now I see people use the result of this evaluation in their REPL
> > > > > (I see this in videos, so I cant ask 'em :). This doesnt work at all
> > > > > for me. I get the result in the minibuffer (this thing at the very
> > > > > bottom) and thats it.
>
> > > > If the form you evaluate is of the def* variety, it's going to affect
> > > > the namespace it resides in and not the namespace of the REPL. Thus,
> > > > if you have e.g. (ns foo) at the top of the file, yet you're working
> > > > in the user namespace at the REPL, then after using C-x C-e to
> > > > evaluate a function definition in your file, you'll have to say
> > > > something like foo/bar to reach it from the REPL. (Or (use :reload-all
> > > > 'foo), if you prefer.)
>
> > > > If there is no namespace declaration in the file, then the expression
> > > > will be evaluated in the user namespace, which means that you'll be
> > > > able to use it straight away if that's your REPL's namespace. (If you
> > > > say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say
> > > > something like user/bar to reach your function.)
>
> > > > Sincerely,
> > > > Michał
>
> > > --
> > > 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


Re: Fighting with Emacs ;-)

2010-09-27 Thread psfblair
I found the old thread below, but unfortunately the solution isn't
working for me. If I have a foo.clj file in a buffer and evaluate
region on

(defn foo [] (+ 1 2))

I get

#'user/foo in the minibuffer. If I then evaluate region on

(foo)

I get 3 in the minibuffer. The slime REPL is giving me a prompt user>
so I'm assuming it's in the user namespace, but I can't seem to get
expressions from the text buffer to evaluate in there.


On Mar 28, 5:01 am, Michał Marczyk  wrote:

> On 27 March 2010 22:25, alux  wrote:
>
> > But now I see people use the result of this evaluation in their REPL
> > (I see this in videos, so I cant ask 'em :). This doesnt work at all
> > for me. I get the result in the minibuffer (this thing at the very
> > bottom) and thats it.
>
> If the form you evaluate is of the def* variety, it's going to affect
> the namespace it resides in and not the namespace of the REPL. Thus,
> if you have e.g. (ns foo) at the top of the file, yet you're working
> in the user namespace at the REPL, then after using C-x C-e to
> evaluate a function definition in your file, you'll have to say
> something like foo/bar to reach it from the REPL. (Or (use :reload-all
> 'foo), if you prefer.)
>
> If there is no namespace declaration in the file, then the expression
> will be evaluated in the user namespace, which means that you'll be
> able to use it straight away if that's your REPL's namespace. (If you
> say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say
> something like user/bar to reach your function.)
>
> Sincerely,
> Michał

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