Also:
> I suggesting adding printlns or logging or a debugger and checking the
> value of this-users-params, it is almost certainly not what you expect
> it to be.
I showed the output previously, but I will do it again.
If I add a println like this:
(defn add-to-logged-in-registry [this-users-params]
(let [right-now (. (Date.) getTime)
new-user-entry (conj this-users-params { "updated" right-now })]
(println apply str new-user-entry)
(if (:username new-user-entry)
(swap! registry assoc (:username new-user-entry) new-user-entry))))
This code works perfectly at the REPL so to show a problem I have to upload
this to the live server. So I compile this and upload it to the server and
start it up and immediately the Javascript in the browsers of dozens of
users starts to bombard the app:
java -jar who-is-logged-in-1.0.1-standalone.jar 40000
App 'Who is logged in?' is starting
port: 40000
2012-10-19 11:37:02.731:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
2012-10-19 11:37:02.846:INFO:oejs.AbstractConnector:Started
[email protected]:40000
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661023079, username rumbella,
first_name , last_name , user_image , site www.wpquestions.com}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661023140, username karlorihoo,
first_name Karlo, last_name Rihoo, user_image , site www.wpquestions.com}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661023698}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661024149, username Rainner,
first_name Rainner, last_name Lins, user_image Rainner_phptZ2nEJ.jpg, site
www.javascriptquestions.com}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661024159}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661024269}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661024646}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661024833, username dbranes,
first_name Dbranes, last_name , user_image dbranes_phpPJVl3f.jpg, site
www.wpquestions.com}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661025140, username Christianto,
first_name Christianto, last_name , user_image Christianto_phpqESzHW.jpg,
site www.wpquestions.com}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661025337, username jsoni,
first_name Jatin, last_name Soni, user_image jsoni_phpYlWQTr.jpg, site
www.wpquestions.com}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661025651}
#<core$apply clojure.core$apply@d1fba79> #<core$str
clojure.core$str@7dfde44e> {updated 1350661025996}
So, why does this not work? And what is the right way to be sure that this:
{updated 1350661025996}
Is never added to the registry (since there is no username).
On Friday, October 19, 2012 3:53:26 AM UTC-4, [email protected] wrote:
>
> conj can surely produce maps, and does so happily in the following cases:
>
> (conj {} [:foo :bar])
> (conj {} {:foo :bar})
>
> I suggesting adding printlns or logging or a debugger and checking the
> value of this-users-params, it is almost certainly not what you expect
> it to be.
>
> as a side note creating a date object just to call getTime is kind of
> gross, try (System/currentTimeMillis)
>
> On Fri, Oct 19, 2012 at 12:42 AM, Sean Corfield
> <[email protected]<javascript:>>
> wrote:
> > On Fri, Oct 19, 2012 at 12:10 AM, larry google groups
> > <[email protected] <javascript:>> wrote:
> >>
> >> (defn add-to-logged-in-registry [this-users-params]
> >> (let [right-now (. (Date.) getTime)
> >> new-user-entry (conj this-users-params { "updated" right-now
> })]
> >> (if (:username new-user-entry)
> >> (swap! registry assoc (:username new-user-entry)
> new-user-entry))))
> >>
> >> The if statement seems to never be true.
> >
> >
> > conj produces a sequence, not a map, so the lookup of :username fails.
> Try
> > new-user-entry (assoc this-users-params "updated" right-now)
> > --
> > Sean A Corfield -- (904) 302-SEAN
> > An Architect's View -- http://corfield.org/
> > World Singles, LLC. -- http://worldsingles.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 [email protected]<javascript:>
> > Note that posts from new members are moderated - please be patient with
> your
> > first post.
> > To unsubscribe from this group, send email to
> > [email protected] <javascript:>
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
>
>
>
> --
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en