I made a pattern matching tool, please help!
Can regular expressions be applied *within* the map pattern? such as "...{event-type: error|warning}", or would you have to write it as "...{event-type: error}|{event-type: warning}" ?
As is, I think it could definitely be useful as a way to search through server logs, though there are often more complex queries you'd want to perform there. For example: "Get all records where the UserID is 12345, then search them for a span of errors starting at (some regex pattern) and ending at (some regex pattern)". If the original sequence contains several UserIDs all at once, it would be difficult to write a single regular expression to do this. You'd need to pipe the results of one search into another.
@Nypyren (is this doing something? :p)
Right now it can not be used recursively, but it would be pretty easy to implement I think, if I could just decide on a good syntax for it. Same with the error|warning. But in that case, since Clojure has pretty convenient function literals (for example #(> % 3) is a function that checks whether the input is larger than 3) something like {event-type: #(contains? [error warning] %)} could be used if I made functions as values be applied as predicates. I'm not up to date with Java, but it's getting lambdas too, right?
In your last example, yes, piping the results to a next step seems easiest, and something that seems perfectly acceptable.
In C# normally we have a set of features called "LINQ" which can be used for processing sequences of data. They work more like what you'd see in a functional language:
// filters all log entries for one user and skips everything until the first error record.
var results = logEntries.Where(x => x.UserID == 12345).SkipWhile(x => x.EntryType != EntryType.Error);
The built-in LINQ functions provided in .Net don't have the power of regular expressions (as far as I know...), but it would be possible to implement a LINQ-compatible library that does, like yours. I think that would be pretty awesome.
I don't know Clojure, correct me if I'm wrong, but it seems that you can only search through hashmaps in memory.
Server logs are usually on disks, zipped, or in the cloud. If you can have this library run on top of a hadoop cluster, redis, or some document-based database, then it can be more useful.
I don't know Clojure, correct me if I'm wrong, but it seems that you can only search through hashmaps in memory.
Server logs are usually on disks, zipped, or in the cloud. If you can have this library run on top of a hadoop cluster, redis, or some document-based database, then it can be more useful.
First of all, Clojure has lazy sequences, so it could pretty easily be read bit by bit from disk and process it. Same with zips I guess. It can also fairly easily be used together with Cascalog http://cascalog.org/ which is a declarative language for use on Hadoop. I have done it before but don't have it installed right now. I could also extend it to data types other than hashmaps. Just need to come up with a good syntax for everything.
I usually use C#, and I don't use Java or Clojure, so I won't be able to actually try out your lib. It seems cool though - I like the idea of applying regular expression-style pattern matching to sequences and structured data instead of just text.
In C# normally we have a set of features called "LINQ" which can be used for processing sequences of data. They work more like what you'd see in a functional language:
The built-in LINQ functions provided in .Net don't have the power of regular expressions (as far as I know...), but it would be possible to implement a LINQ-compatible library that does, like yours. I think that would be pretty awesome.// filters all log entries for one user and skips everything until the first error record. var results = logEntries.Where(x => x.UserID == 12345).SkipWhile(x => x.EntryType != EntryType.Error);
There is an implementation of Clojure for .NET too, so it should be farily easy to port it. If anyone is really interested then let me know. And those LINQ operators looks like `filter` and `drop-while` in Clojure. Btw I highly recommend Clojure over Java and C#, it is really, really good. :P
(drop-while (fn [m] (not= (:entry-type m) :error))
(filter (fn [m] (= (:user-id m) 12345)) log-entries)