Code Monkey home page Code Monkey logo

Comments (5)

ifesdjeen avatar ifesdjeen commented on August 26, 2024

I can't quite understand the problem, what are you trying to achieve?

If you want to serialize the data structure, so it will look pretty much like that:

#=(clojure.lang.PersistentHashMap/create {:tag :a, :attrs #=(clojure.lang.PersistentArrayMap/create {:title "Equals si\
gn", :href "/wiki/Equals_sign"}), :content ("=")})

You can read it back and it will evaluate to:

{:content ("="), :attrs {:title "Equals sign", :href "/wiki/Equals_sign"}, :tag :a}

Am I missing something?

from enlive.

ifesdjeen avatar ifesdjeen commented on August 26, 2024

Probably I have to cc @jackrusher

from enlive.

jackrusher avatar jackrusher commented on August 26, 2024

Sorry it has taken me so long to reply.

I tend to do loads of exploratory programming using emacs + SLIME/nrepl, quite a bit of which involves scraping/spidering. An example of this might be:

(def symbols
(html/html-resource (java.net.URL. "http://en.wikipedia.org/wiki/List_of_mathematical_symbols")))

(html/select symbols [:table.wikitable :td :a])
;; C-u C-x C-e in emacs to bring the result of evaluating this express into the buffer
;; => ({:tag :a, :attrs {:title "Equals sign", :href "/wiki/Equals_sign"}, :content ("=")} ... )

... which I would then wrap in a (def) form to use as data for whatever program I might be writing at the time.

Sadly, the form returned by (html/select) cannot be used in this way because the reader tries to execute the string at the head of the :content list. In Common Lisp or Scheme, I'd expect the :content list to be quoted to avoid this problem, whereas in Clojure I'd expect the data to be stored in a vector (using vectors literals rather than quoted lists seems like the preferred convention in Clojure).

Thanks for your consideration.

from enlive.

cgrand avatar cgrand commented on August 26, 2024

To me it's the difference between readable and evaluable.
The sensible solution seems to just quite the whole thing when you wrap it
into a def -- after all it's a value not a piece code (Code is data but all
data is not ocde.)

(def foo '({:tag :a, :attrs {:title "Equals sign", :href

"/wiki/Equals_sign"}, :content ("=")} ... )))

On Wed, Jan 23, 2013 at 7:15 PM, Jack Rusher [email protected]:

Sorry it has taken me so long to reply.

I tend to do loads of exploratory programming using emacs + SLIME/nrepl,
quite a bit of which involves scraping/spidering. An example of this might
be:

(def symbols

(html/html-resource (java.net.URL. "
http://en.wikipedia.org/wiki/List_of_mathematical_symbols")))

(html/select symbols [:table.wikitable :td :a])
;; C-u C-x C-e in emacs to bring the result of evaluating this express
into the buffer
;; => ({:tag :a, :attrs {:title "Equals sign", :href "/wiki/Equals_sign"},
:content ("=")} ... )

... which I would then wrap in a (def) form to use as data for whatever
program I might be writing at the time.

Sadly, the form returned by (html/select) cannot be used in this way
because the reader tries to execute the string at the head of the :content
list. In Common Lisp or Scheme, I'd expect the :content list to be quoted
to avoid this problem, whereas in Clojure I'd expect the data to be stored
in a vector (using vectors literals rather than quoted lists seems like the
preferred convention in Clojure).

Thanks for your consideration.


Reply to this email directly or view it on GitHubhttps://github.com//issues/50#issuecomment-12613574.

On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/

from enlive.

jackrusher avatar jackrusher commented on August 26, 2024

On 23 Jan, 2013, at 16:00, Christophe Grand [email protected] wrote:

The sensible solution seems to just quite the whole thing when you wrap it
into a def -- after all it's a value not a piece code (Code is data but all
data is not ocde.)

I can, of course, work around this, but what is the advantage of making me do so? That is, why would one not want this data to be usable in this way?

from enlive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.