On 13/04/14 02:21, Stephen Feyrer wrote:
// Get the java file io library
(import '(java.io <http://java.io> File))
// Get some files
(def f (File. "/My/files/"))
(def fs (file-seq f))
// Filters for suffixes ".mp3"
(def get-mp3 (filter #(.endsWith (.getName %) ".mp3") fs))
// Get the path of one mp3
(println (take 1 get-mp3))
This code is gathered from various unrelated Clojure forum posts. The
resultant collection, I must admit defeats my understanding.
My first question is the println statement returns "(#<File
/My/files/path/to/Some of/My Music Collection.mp3>)", would someone
explain this data structure for me, bearing in mind that white spaces
and commas are synonymous.
It's not a data structure, it's just the way clojure prints out java object:
user=> f
#<File /My/files>
In the REPL Clojure tries to print out readable output, meaning
something that can be read again by the reader as input:
user=> (def a '(1 2 3))
#'user/a
user=> #'user/a
#'user/a
user=> (var a)
#'user/a
user=> map
#<core$map clojure.core$map@23130c0a>
In the case of object instances, it cannot be printed into such readable
form, so it uses the #< to indicate this is unreadable:
user=> #<File /tmp>
clojure.lang.LispReader$ReaderException: java.lang.RuntimeException:
Unreadable form
java.lang.RuntimeException: Unreadable form
See also the answer to this stackoverflow question:
http://stackoverflow.com/questions/17263929/clojure-read-string-on-functions
If you want to know more about reader macros:
http://en.wikibooks.org/wiki/Learning_Clojure/Reader_Macros
There's also this chapter from an online beginner's book I recommend
(you may want to read the stuff before):
http://www.braveclojure.com/read-and-eval/
Please note, while I have programmed a little in the past this does
not prevent me from asking dumb questions. Thus finally, if this is
not the appropriate place for this sort question could you point me in
the right direction?
You're perfectly fine here, newbies welcome.
In fact your question is about something that isn't much talked or
written about in clojure.
HTH
--
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.