Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6177823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:20:39+00:00 2026-05-24T00:20:39+00:00

I’m trying to pull an integer out of localStorage with a simple clojurescript app.

  • 0

I’m trying to pull an integer out of localStorage with a simple clojurescript app. Everything I’ve tried ended up trying has some sort of wrong behavior.

Below is my program without initializing from local storage. I’ll ignore the key not found case since I’ve a JQuery version that handles that to prime the storage. Also, the JQuery app reads the ClojureScript saves to localStorage fine. So that’s working for me.

Quick summary is this. I message says “There have been $number days since the last incident” The $number is in a div named “counter.” I’ve got three buttons; one increments the count, one decrements the count, and the last resets the count to zero.

 (ns days.core
        (:require [goog.events :as events]
                  [goog.string :as string]
                  [goog.math.Integer :as int]
                  [goog.dom :as dom]))
    (defn initial-state [] 0)
    (def count (atom (initial-state)))
    (defn set-counter [n]
       (do (.setItem (.localStorage (dom/getWindow)) "count" n)
           (dom/setTextContent (dom/getElement "counter") n)))
    (defn set-button-fn [button-id f-update]
       (events/listen (dom/getElement button-id)
                      "click"
                      (fn [] (do (f-update) (set-counter @count)))))
    (defn start-app []
       (do
           (set-counter @count)
           (set-button-fn "addDay" (fn [] (swap! count inc)))
           (set-button-fn "decDay" (fn [] (swap! count dec)))
           (set-button-fn "reset" (fn [] (reset! count 0)))))
    (start-app)

When I try to use goog.math.Integer.fromString() to cast to an integer, the call to inc will append a 1 on the end (7 went to 71 and 711). The call to dec will do what I expect, decrement it numerically (711 went to 710 and 709). Here’s how I’m trying to initialize that.

(defn initial-state []
  (integer/fromString (.getItem (.localStorage (dom/getWindow)) "count")))

I realized this was a goog.math.Integer object so I tried to call .toNumber() on it. But this and .toInt() seemed to give me a function. function (){if(this.e==-1)return-w(this).D();else{for(var a=0,b=1,d=0;d=0?e:Ua+e)b;b=Ua}return a}} to be exact.

(defn initial-state [] (.toNumber 
  (integer/fromString (.getItem (.localStorage (dom/getWindow)) "count"))))

Clojure seems to use java’s Integer class to cast from a string to an int even to the point of having (int “1”) throw so that idea was shot.

I also tried to call javascript’s parseInt(). This is how I do it in the JQuery version. However the ClojureScript call always returns a 1. Even if my JQuery version stores an 8 as evidenced by Chrome’s developer tools.

(defn initial-state []
  (.parseInt (dom/getWindow)
             (.getItem (.localStorage (dom/getWindow)) "count")))

Any ideas how I can get that string value to behave as an integer? It’s got to be simple, but I’m getting nowhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:20:40+00:00Added an answer on May 24, 2026 at 12:20 am

    You can access the parseInt function via the js namespace like so:

    (js/parseInt "7")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.