Re: Idiomatic parsing of objects from several lines of a text file
On Jul 31, 9:42 pm, Lau wrote: > Hey, > > I wanted to do something with Git and Qt, and the result was a project > which never really got off the ground. However its capable of reading > an entire Gitlog into a hash-map in the form {:hash > 129412849 :commit ..} > and so on. Ẃe used it at work to provide a better alternative than > Gitweb, > and its easily extended to show filecontents and what not. > > http://github.com/Lau-of-DK/gitdoc/tree/master Thank you, that's very helpful to see your approach. I'll digest that for a while... --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
On Jul 31, 8:15 pm, Baishampayan Ghose wrote: > I think David is trying to solve the Github Contest problem > -http://contest.github.com/and not really trying to write a Git client > in Clojure :) Actually no, although that looks pretty fun. --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
> I don't know about you, but I personally prefer to only use symbols > that I can actually type. Copying and pasting from Character Map > kind of interrupts flow, if you know what I mean? Heh, yes indeed :) That was the reason behind writing "suppose"! Sure-fire way to turn off Windows users — at least folks on a Mac have easy access to [–—…¢›‹€⁄∞] and so on using only modifier keys (and so I use proper punctuation in my string literals). The poor Windows folks would be heading for the numeric keypad all day. --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
I think it's MY C++ background shining through, but I keep reading (ref->commit) as "execute the commit method of the ref datastructure." I'll have to echo the lack of enthusiasm of inputting fancy characters, though the Emacs mode to prettify the display look interesting. Good luck with the contest, -- Aaron On Thu, Jul 30, 2009 at 9:37 PM, Richard Newman wrote: > > > What is this convention you are using with the -> ? > > > > Are you coming from a C or C++ background or is this something lispy > > I haven't seen before? > > A fair proportion of Common Lispers do that (though I've witnessed > debates about its merit, usually in the context of low-level code > where the symbols are already cluttered with [-_+>] etc), exploiting > the much richer options for symbol names than most languages. It's > certainly not a dereferencing operation, which is the only context in > which it would arise for a C/C++ user. > > Usually it means "to", either as a conversion or lookup. > > (defn ref->commit [ref] > ...) > > thus means "take this ref and give me the corresponding commit (in the > context of this repo)". Similarly, > > (defn tree-entry->map [e] > ...) > > takes a Git tree entry string and returns a Clojure map that > represents it. This is slightly less confusing than `tree-entry-map`, > which could very well mean some mapping construct over a tree entry, > or a map of multiple tree entries, or something else. > > I haven't been entirely consistent, though -- witness `tree-entry- > seq`, which should really be `tree-entry->seq`. I said it was a work > in progress :) > > I suppose in Clojure we could use a real arrow character, with UTF-8 > available in symbol names... > > -R > > > > > --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
On Thu, Jul 30, 2009 at 9:37 PM, Richard Newman wrote: > I suppose in Clojure we could use a real arrow character, with UTF-8 > available in symbol names... I don't know about you, but I personally prefer to only use symbols that I can actually type. Copying and pasting from Character Map kind of interrupts flow, if you know what I mean? --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
Hey, I wanted to do something with Git and Qt, and the result was a project which never really got off the ground. However its capable of reading an entire Gitlog into a hash-map in the form {:hash 129412849 :commit ..} and so on. Ẃe used it at work to provide a better alternative than Gitweb, and its easily extended to show filecontents and what not. http://github.com/Lau-of-DK/gitdoc/tree/master /Lau On Jul 30, 11:26 pm, David Plumpton wrote: > I'm trying to find an idiomatic way to read through a text file (e.g. > a Git history log) where an object will be represented by several > lines of text, and when we find a line that starts a new entry we > create the old entry and continue. For example here's my first clumsy > attempt. Can anybody advise on how to do this in a more functional > style? > > (def *line-re* #"[^\n]{1,}") > > (defstruct commit :id :parent :msg) > > (defn parse-log [filename] > (let [text (slurp filename) > lines (re-seq *line-re* text)] > (with-local-vars > [commits {} > commit-id "" > parent "" > msg ""] > (doseq [line lines] > (if (.startsWith line "commit ") > (do > (if (not= @commit-id "") > (do > (var-set commits (conj @commits {...@commit-id (struct > commit @commit-id @parent @msg)})) > (var-set msg "") > (var-set parent nil))) > (var-set commit-id (subs line 7 > (if (.startsWith line "parent ") > (var-set parent (subs line 7))) > (if (.startsWith line " ") > (var-set msg (str @msg "\n" (subs line 4) > (var-set commits (assoc @commits @commit-id (struct commit > @commit-id @parent @msg))) > @commits))) --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
Richard Newman wrote: >> I'm trying to find an idiomatic way to read through a text file (e.g. >> a Git history log) > > Sidenote: I'm hacking on this: > > http://github.com/rnewman/clj-git/tree/master > > I haven't got to commit messages etc. yet -- I'm primarily using git > as a backing store, not accessing existing repositories, so there are > much more pressing things -- but there might be something useful there > for you. > > The usual caveats of hacky, bad, probably-buggy code apply :) I think David is trying to solve the Github Contest problem - http://contest.github.com/ and not really trying to write a Git client in Clojure :) Regards, BG -- Baishampayan Ghose oCricket.com signature.asc Description: OpenPGP digital signature
Re: Idiomatic parsing of objects from several lines of a text file
On Jul 30, 2009, at 7:24 PM, Aaron Cohen wrote: > Are you coming from a C or C++ background or is this something lispy > I haven't seen before? I first ran into this in Scheme, where I think its use is somewhat more idiomatic than in CL. As the author observes, it's generally used instead of "to" in the CL libraries on my system, though it wouldn't surprise me much to see it used in code wrapping C structures. CL usually takes the most verbose option available, confirmed anecdotally by 241 occurrences of "-to-" in a function name in the selection of libraries on my system, versus 129 occurrences of "->." This structure is even employed in SRFI #4, published in 1998, suggesting that its use in the Scheme community has been uncontroversial for at least 11 years. Scheme has always prized a terse kind of elegance where Lisp has sought comprehensiveness. On Jul 30, 2009, at 7:37 PM, Richard Newman wrote: > I suppose in Clojure we could use a real arrow character, with UTF-8 > available in symbol names... Clojure being the 21st century language it is, I would be delighted to see '¬ instead of 'not, 'ƒ instead of 'fn, '∑ instead of a hypothetical 'sum builtin, and → instead of ->. I'm sure I'd enjoy reading code with such conventions, but I think I would find typing it out is somewhat tedious. You might find the Emacs mode "Pretty Lambda" to be useful; the effect on Haskell code is really quite nice: http://alexott.blogspot.com/2009/02/emacs-haskell-pretty-lambda.html It can be customized for other languages, but I can't find any references to anyone doing it with Clojure yet. Details on the mode here: http://www.emacswiki.org/emacs/PrettyLambda — Daniel Lyons --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
> What is this convention you are using with the -> ? > > Are you coming from a C or C++ background or is this something lispy > I haven't seen before? A fair proportion of Common Lispers do that (though I've witnessed debates about its merit, usually in the context of low-level code where the symbols are already cluttered with [-_+>] etc), exploiting the much richer options for symbol names than most languages. It's certainly not a dereferencing operation, which is the only context in which it would arise for a C/C++ user. Usually it means "to", either as a conversion or lookup. (defn ref->commit [ref] ...) thus means "take this ref and give me the corresponding commit (in the context of this repo)". Similarly, (defn tree-entry->map [e] ...) takes a Git tree entry string and returns a Clojure map that represents it. This is slightly less confusing than `tree-entry-map`, which could very well mean some mapping construct over a tree entry, or a map of multiple tree entries, or something else. I haven't been entirely consistent, though -- witness `tree-entry- seq`, which should really be `tree-entry->seq`. I said it was a work in progress :) I suppose in Clojure we could use a real arrow character, with UTF-8 available in symbol names... -R --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
What is this convention you are using with the -> ? Are you coming from a C or C++ background or is this something lispy I haven't seen before? -- Aaron On Thu, Jul 30, 2009 at 7:56 PM, Richard Newman wrote: > > On 30 Jul 2009, at 2:26 PM, David Plumpton wrote: > > > I'm trying to find an idiomatic way to read through a text file (e.g. > > a Git history log) > > Sidenote: I'm hacking on this: > > http://github.com/rnewman/clj-git/tree/master > > I haven't got to commit messages etc. yet -- I'm primarily using git > as a backing store, not accessing existing repositories, so there are > much more pressing things -- but there might be something useful there > for you. > > The usual caveats of hacky, bad, probably-buggy code apply :) > > -R > > > > > --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
On 30 Jul 2009, at 2:26 PM, David Plumpton wrote: > I'm trying to find an idiomatic way to read through a text file (e.g. > a Git history log) Sidenote: I'm hacking on this: http://github.com/rnewman/clj-git/tree/master I haven't got to commit messages etc. yet -- I'm primarily using git as a backing store, not accessing existing repositories, so there are much more pressing things -- but there might be something useful there for you. The usual caveats of hacky, bad, probably-buggy code apply :) -R --~--~-~--~~~---~--~~ 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: Idiomatic parsing of objects from several lines of a text file
Hi, I would suggest to have a look at fnparse[1]. It's really cool. A commit-log parser might look like this: (def linebreak (alt (conc (opt (lit \return)) (lit \newline)) (lit \return))) (def hex-digit (alt-lit-seq "0123456789abcdef")) (def checksum (semantics (rep+ hex-digit) #(apply str %))) (def commit (complex [_ (conc-lit-seq "commit ") commit-id checksum _ linebreak _ (conc-lit-seq "parent ") parent-id checksum _ (rep= 2 linebreak) msg (semantics (rep* (except anything (conc linebreak (conc-lit-seq "commit " #(apply str %))] {:id commit-id :parent parent-id :message msg})) (def commit-log (rep* commit)) This should parse a log like: commit a2b5927f24c parent c726fe5211a This is the message commit 285abb36e12 parent 81f2e35bc61 Another message. The result would be: [{:id a2b5927f24c :parent c726fe5211a :message "This is\nthe\nmessage"} {:id 285abb36e12 :parent 81f2e35bc61 :message "Another\nmessage."}] Note, the code is not tested, but should be close. Hope this helps. Sincerely Meikel [1]: http://github.com/joshua-choi/fnparse/tree/master smime.p7s Description: S/MIME cryptographic signature
Idiomatic parsing of objects from several lines of a text file
I'm trying to find an idiomatic way to read through a text file (e.g. a Git history log) where an object will be represented by several lines of text, and when we find a line that starts a new entry we create the old entry and continue. For example here's my first clumsy attempt. Can anybody advise on how to do this in a more functional style? (def *line-re* #"[^\n]{1,}") (defstruct commit :id :parent :msg) (defn parse-log [filename] (let [text (slurp filename) lines (re-seq *line-re* text)] (with-local-vars [commits {} commit-id "" parent "" msg ""] (doseq [line lines] (if (.startsWith line "commit ") (do (if (not= @commit-id "") (do (var-set commits (conj @commits {...@commit-id (struct commit @commit-id @parent @msg)})) (var-set msg "") (var-set parent nil))) (var-set commit-id (subs line 7 (if (.startsWith line "parent ") (var-set parent (subs line 7))) (if (.startsWith line "") (var-set msg (str @msg "\n" (subs line 4) (var-set commits (assoc @commits @commit-id (struct commit @commit-id @parent @msg))) @commits))) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---