Re: Extending core.logic (Datomic example)

2012-05-19 Thread Thomas G. Kristensen
That link is dead - sorry,

Thomas

On May 19, 3:24 am, David Nolen  wrote:
> core.logic has had the facilities to integrate with external data sources
> for a very long time. However this feature has been poorly documented.
> Hopefully the following improves the situation a little bit:
>
> http://github.com/clojure/core.logic/wiki/Extending-core.logic-(Datom...)
>
> David

-- 
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: core.logic, comparators

2012-05-19 Thread David Nolen
Such operators are available in core.logic.arithmetic. In general such
operations are non-relational and require projection. cKanren offers a
better story here.

On Saturday, May 19, 2012, Brent Millare wrote:

> I understand how to construct goals using the primitives provided in
> core.logic, like a conjunction with fresh or all, and using relations
> defined with defrel. However, I don't really understand the protocols of
> goals once I no longer use these primitives.
>
> How would I define my own comparison like function? Instead of unifying,
> I'd like to do a comparison.
>
> Something like this:
>
> ...
>
> (l/fact person :bob 3)
> (l/fact person :april 2)
>
> (l/run 5 [q]
> (l/> q 2)
> (l/fresh [name]
> (person name q)))
> (3)
>
> What would be the definition for l/>?
>
> --
> 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 '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  'clojure%2bunsubscr...@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 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

core.logic, comparators

2012-05-19 Thread Brent Millare
I understand how to construct goals using the primitives provided in 
core.logic, like a conjunction with fresh or all, and using relations 
defined with defrel. However, I don't really understand the protocols of 
goals once I no longer use these primitives.

How would I define my own comparison like function? Instead of unifying, 
I'd like to do a comparison.

Something like this:

...

(l/fact person :bob 3)
(l/fact person :april 2)

(l/run 5 [q]
(l/> q 2)
(l/fresh [name]
(person name q)))
(3)

What would be the definition for l/>?

-- 
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: algebra system & core.logic

2012-05-19 Thread Brent Millare
That's more or less what I'm going to have to do anyways. It's great that 
clojure + core.logic make that as easy as possible.

On Friday, May 18, 2012 10:42:16 PM UTC-4, David Nolen wrote:
>
> It might also be interesting to pursue a hybrid system - that's the whole 
> point of core.logic - being able to mix functional and relational 
> programming with minimal hassle.
>
> David
>
>
>

-- 
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: Lexer and parser generator in Clojure

2012-05-19 Thread Brent Millare
I wrote a library on parsing expression grammars (PEGs). Its not completely 
independent from clojurescript since I use java's regular expressions for 
the token component, but technically it works on sequences and its easy to 
rewrite this for js's regexps. Performance hasn't been measured but theres 
less invocations than a general parsec library. The code is heavily 
documented and should at least get you started.

https://github.com/bmillare/dj-peg

On Friday, May 18, 2012 8:46:19 AM UTC-4, Alexsandro Soares wrote:
>
> Hi,
>
>  I'm trying to build a compiler using Clojure. Is there any tools 
> like flex and bison generating Clojure code? 
>  I'm interested in a lexer/parser in pure Clojure because I think
>  in use the same code with Javascript (via ClojureScript) and Java (via 
> Clojure). 
> I already know isolated tools like Jflex, JavaCup and Bison generating 
> Java and
> Jison, JS/CC and friends for Javascript, but I am just interested in a 
> pure Clojure solution.
>
> Thanks in advance for any answer.
>
> Cheers,
> Alex
>

-- 
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: Lexer and parser generator in Clojure

2012-05-19 Thread Jason Jackson
I didn't read the part about clojure/clojurescript interop. 

Also, you could write a parser by hand in clojure[script], which takes a 
parse table as input. The parse table can be generated with from any 
language. 



On Saturday, 19 May 2012 15:44:28 UTC-4, Jason Jackson wrote:
>
> I wrote a compiler in Clojure for a 4th year course.
>
> For parsing I used this combinator parser library: 
> https://github.com/jasonjckn/clarsec  which is modeled after haskell's 
> parsec. 
> However the performance was kind of bad, combinator parsers in general can 
> be pretty slow. 
>
> In retrospect, I would have tried https://github.com/cgrand/parsley afaik 
> it has ~LR1 performance characteristics. 
>
> Beyond the above options, there's many LR1/LL1 parsers written in Java 
> that are perfectly fine options. If you're parsing with a grammar file, you 
> don't gain anything if the parser was written in Clojure versus Java. 
>
> For lexing, I just used clojure's regular expression implementation. Not 
> sure what libraries exist. 
>
> -Jason
>
> On Friday, 18 May 2012 08:46:19 UTC-4, Alexsandro Soares wrote:
>>
>> Hi,
>>
>>  I'm trying to build a compiler using Clojure. Is there any tools 
>> like flex and bison generating Clojure code? 
>>  I'm interested in a lexer/parser in pure Clojure because I think
>>  in use the same code with Javascript (via ClojureScript) and Java (via 
>> Clojure). 
>> I already know isolated tools like Jflex, JavaCup and Bison generating 
>> Java and
>> Jison, JS/CC and friends for Javascript, but I am just interested in a 
>> pure Clojure solution.
>>
>> Thanks in advance for any answer.
>>
>> Cheers,
>> Alex
>>
>

-- 
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: Lexer and parser generator in Clojure

2012-05-19 Thread Jason Jackson
I wrote a compiler in Clojure for a 4th year course.

For parsing I used this combinator parser 
library: https://github.com/jasonjckn/clarsec  which is modeled after 
haskell's parsec. 
However the performance was kind of bad, combinator parsers in general can 
be pretty slow. 

In retrospect, I would have tried https://github.com/cgrand/parsley afaik 
it has ~LR1 performance characteristics. 

Beyond the above options, there's many LR1/LL1 parsers written in Java that 
are perfectly fine options. If you're parsing with a grammar file, you 
don't gain anything if the parser was written in Clojure versus Java. 

For lexing, I just used clojure's regular expression implementation. Not 
sure what libraries exist. 

-Jason

On Friday, 18 May 2012 08:46:19 UTC-4, Alexsandro Soares wrote:
>
> Hi,
>
>  I'm trying to build a compiler using Clojure. Is there any tools 
> like flex and bison generating Clojure code? 
>  I'm interested in a lexer/parser in pure Clojure because I think
>  in use the same code with Javascript (via ClojureScript) and Java (via 
> Clojure). 
> I already know isolated tools like Jflex, JavaCup and Bison generating 
> Java and
> Jison, JS/CC and friends for Javascript, but I am just interested in a 
> pure Clojure solution.
>
> Thanks in advance for any answer.
>
> Cheers,
> Alex
>

-- 
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: Core.logic, dynamically generated goals

2012-05-19 Thread Alex Robbins
Oh, so instead of trying to unroll my requirements into a bunch of
conditions, just make a single condition function that checks through
the list. That helps a lot!

Thanks!
Alex

On Sat, May 19, 2012 at 2:11 PM, Jason Jackson  wrote:
> Are you trying to see if a person meets multiple requirements? Here's how:
>
>
>
> (defrel grade person course g)
> (fact grade 'Bob 'Algebra 'B)
> (fact grade 'Bob 'Art 'C)
> (fact grade 'John 'Algebra 'A)
> (fact grade 'John 'Art 'A)
> (fact grade 'Ricky 'Algebra 'D)
> (fact grade 'Ricky 'Art 'A)
>
> (defn meets-requirements [person [k & nowledge]]
>   (if-let [{:keys [course g]} k]
>     (all
>      (grade person course g)
>      (meets-requirements person nowledge))
>     succeed))
>
>
> #_ (run* [person]
>      (meets-requirements
>       person
>       [{:course 'Algebra :g 'B}
>        {:course 'Art :g 'C}]))
>
>
> On Saturday, 19 May 2012 15:07:47 UTC-4, Alex Robbins wrote:
>>
>> Hmm, I didn't explain it very well. What if I had more knowledge?
>> Maybe I knew two grades sometimes. That could cut down on the list of
>> possible students (assuming there are more than the three in my
>> example).
>>
>> How could I write a function that worked for both of these cases?
>> (matches [{:course 'Algebra :g 'B}])
>> (matches [{:course 'Algebra :g 'B} {:course 'Art :g 'C}])
>>
>>
>> On Sat, May 19, 2012 at 2:02 PM, David Nolen 
>> wrote:
>> > I don't think you need to generate goals for something as
>> > straightforward as
>> > this:
>> >
>> > (defrel grade person course g)
>> > (fact grade 'Bob 'Algebra 'B)
>> > (fact grade 'Bob 'Art 'C)
>> > (fact grade 'John 'Algebra 'A)
>> > (fact grade 'John 'Art 'A)
>> > (fact grade 'Ricky 'Algebra 'D)
>> > (fact grade 'Ricky 'Art 'A)
>> >
>> > (defn matches [{:keys [course g]}]
>> >   (run* [q]
>> >     (fresh [p]
>> >       (grade p course g)
>> >       (== q [p course g]
>> >
>> > (matches {:course 'Algebra :g 'B})
>> >
>> > On Sat, May 19, 2012 at 2:12 PM, Alex Robbins
>> >  wrote:
>> >>
>> >> I'm just getting started with logic programming, and it is entirely
>> >> possible I'm just approaching this incorrectly.
>> >>
>> >> Is it possible to use dynamically generated goals in run* ?
>> >>
>> >> For example,
>> >>
>> >> (defrel grade person course g)
>> >> (fact grade 'Bob 'Algebra 'B)
>> >> (fact grade 'Bob 'Art 'C)
>> >> (fact grade 'John 'Algebra 'A)
>> >> (fact grade 'John 'Art 'A)
>> >> (fact grade 'Ricky 'Algebra 'D)
>> >> (fact grade 'Ricky 'Art 'A)
>> >>
>> >> (def knowledge
>> >>  {:course 'Algebra :g 'B})
>> >>
>> >> (defn generate-goals [knowledge]
>> >>  (map
>> >>    (fn [{:keys [course g]}] (list 'grade 'person course g))
>> >>    knowledge))
>> >>
>> >> I want to do something like this (but valid clojure):
>> >> (run* [person]
>> >>  ~@(generate-goals knowledge))
>> >>
>> >> It should give me back a list of people who match my current
>> >> knowledge. If I have more knowledge about the person, it will generate
>> >> more conditions, less knowledge fewer conditions. However, since run*
>> >> and run are macros, I can't apply them to a list. I can't splice in
>> >> because I'm not in a quotes list. Any ideas?
>> >>
>> >> Thanks!
>> >>
>> >> --
>> >> 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 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 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 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: Core.logic, dynamically generated goals

2012-05-19 Thread Jason Jackson
Are you trying to see if a person meets multiple requirements? Here's how:



(defrel grade person course g)
(fact grade 'Bob 'Algebra 'B) 
(fact grade 'Bob 'Art 'C) 
(fact grade 'John 'Algebra 'A) 
(fact grade 'John 'Art 'A) 
(fact grade 'Ricky 'Algebra 'D) 
(fact grade 'Ricky 'Art 'A)

(defn meets-requirements [person [k & nowledge]]
  (if-let [{:keys [course g]} k]
(all
 (grade person course g)
 (meets-requirements person nowledge))
succeed))


#_ (run* [person]
 (meets-requirements
  person
  [{:course 'Algebra :g 'B}
   {:course 'Art :g 'C}]))


On Saturday, 19 May 2012 15:07:47 UTC-4, Alex Robbins wrote:
>
> Hmm, I didn't explain it very well. What if I had more knowledge? 
> Maybe I knew two grades sometimes. That could cut down on the list of 
> possible students (assuming there are more than the three in my 
> example). 
>
> How could I write a function that worked for both of these cases? 
> (matches [{:course 'Algebra :g 'B}]) 
> (matches [{:course 'Algebra :g 'B} {:course 'Art :g 'C}]) 
>
>
> On Sat, May 19, 2012 at 2:02 PM, David Nolen  
> wrote: 
> > I don't think you need to generate goals for something as 
> straightforward as 
> > this: 
> > 
> > (defrel grade person course g) 
> > (fact grade 'Bob 'Algebra 'B) 
> > (fact grade 'Bob 'Art 'C) 
> > (fact grade 'John 'Algebra 'A) 
> > (fact grade 'John 'Art 'A) 
> > (fact grade 'Ricky 'Algebra 'D) 
> > (fact grade 'Ricky 'Art 'A) 
> > 
> > (defn matches [{:keys [course g]}] 
> >   (run* [q] 
> > (fresh [p] 
> >   (grade p course g) 
> >   (== q [p course g] 
> > 
> > (matches {:course 'Algebra :g 'B}) 
> > 
> > On Sat, May 19, 2012 at 2:12 PM, Alex Robbins 
> >  wrote: 
> >> 
> >> I'm just getting started with logic programming, and it is entirely 
> >> possible I'm just approaching this incorrectly. 
> >> 
> >> Is it possible to use dynamically generated goals in run* ? 
> >> 
> >> For example, 
> >> 
> >> (defrel grade person course g) 
> >> (fact grade 'Bob 'Algebra 'B) 
> >> (fact grade 'Bob 'Art 'C) 
> >> (fact grade 'John 'Algebra 'A) 
> >> (fact grade 'John 'Art 'A) 
> >> (fact grade 'Ricky 'Algebra 'D) 
> >> (fact grade 'Ricky 'Art 'A) 
> >> 
> >> (def knowledge 
> >>  {:course 'Algebra :g 'B}) 
> >> 
> >> (defn generate-goals [knowledge] 
> >>  (map 
> >>(fn [{:keys [course g]}] (list 'grade 'person course g)) 
> >>knowledge)) 
> >> 
> >> I want to do something like this (but valid clojure): 
> >> (run* [person] 
> >>  ~@(generate-goals knowledge)) 
> >> 
> >> It should give me back a list of people who match my current 
> >> knowledge. If I have more knowledge about the person, it will generate 
> >> more conditions, less knowledge fewer conditions. However, since run* 
> >> and run are macros, I can't apply them to a list. I can't splice in 
> >> because I'm not in a quotes list. Any ideas? 
> >> 
> >> Thanks! 
> >> 
> >> -- 
> >> 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 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 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: Core.logic, dynamically generated goals

2012-05-19 Thread Alex Robbins
Hmm, I didn't explain it very well. What if I had more knowledge?
Maybe I knew two grades sometimes. That could cut down on the list of
possible students (assuming there are more than the three in my
example).

How could I write a function that worked for both of these cases?
(matches [{:course 'Algebra :g 'B}])
(matches [{:course 'Algebra :g 'B} {:course 'Art :g 'C}])


On Sat, May 19, 2012 at 2:02 PM, David Nolen  wrote:
> I don't think you need to generate goals for something as straightforward as
> this:
>
> (defrel grade person course g)
> (fact grade 'Bob 'Algebra 'B)
> (fact grade 'Bob 'Art 'C)
> (fact grade 'John 'Algebra 'A)
> (fact grade 'John 'Art 'A)
> (fact grade 'Ricky 'Algebra 'D)
> (fact grade 'Ricky 'Art 'A)
>
> (defn matches [{:keys [course g]}]
>   (run* [q]
>     (fresh [p]
>       (grade p course g)
>       (== q [p course g]
>
> (matches {:course 'Algebra :g 'B})
>
> On Sat, May 19, 2012 at 2:12 PM, Alex Robbins
>  wrote:
>>
>> I'm just getting started with logic programming, and it is entirely
>> possible I'm just approaching this incorrectly.
>>
>> Is it possible to use dynamically generated goals in run* ?
>>
>> For example,
>>
>> (defrel grade person course g)
>> (fact grade 'Bob 'Algebra 'B)
>> (fact grade 'Bob 'Art 'C)
>> (fact grade 'John 'Algebra 'A)
>> (fact grade 'John 'Art 'A)
>> (fact grade 'Ricky 'Algebra 'D)
>> (fact grade 'Ricky 'Art 'A)
>>
>> (def knowledge
>>  {:course 'Algebra :g 'B})
>>
>> (defn generate-goals [knowledge]
>>  (map
>>    (fn [{:keys [course g]}] (list 'grade 'person course g))
>>    knowledge))
>>
>> I want to do something like this (but valid clojure):
>> (run* [person]
>>  ~@(generate-goals knowledge))
>>
>> It should give me back a list of people who match my current
>> knowledge. If I have more knowledge about the person, it will generate
>> more conditions, less knowledge fewer conditions. However, since run*
>> and run are macros, I can't apply them to a list. I can't splice in
>> because I'm not in a quotes list. Any ideas?
>>
>> Thanks!
>>
>> --
>> 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 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 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: Core.logic, dynamically generated goals

2012-05-19 Thread David Nolen
I don't think you need to generate goals for something as straightforward
as this:

(defrel grade person course g)
(fact grade 'Bob 'Algebra 'B)
(fact grade 'Bob 'Art 'C)
(fact grade 'John 'Algebra 'A)
(fact grade 'John 'Art 'A)
(fact grade 'Ricky 'Algebra 'D)
(fact grade 'Ricky 'Art 'A)

(defn matches [{:keys [course g]}]
  (run* [q]
(fresh [p]
  (grade p course g)
  (== q [p course g]

(matches {:course 'Algebra :g 'B})

On Sat, May 19, 2012 at 2:12 PM, Alex Robbins  wrote:

> I'm just getting started with logic programming, and it is entirely
> possible I'm just approaching this incorrectly.
>
> Is it possible to use dynamically generated goals in run* ?
>
> For example,
>
> (defrel grade person course g)
> (fact grade 'Bob 'Algebra 'B)
> (fact grade 'Bob 'Art 'C)
> (fact grade 'John 'Algebra 'A)
> (fact grade 'John 'Art 'A)
> (fact grade 'Ricky 'Algebra 'D)
> (fact grade 'Ricky 'Art 'A)
>
> (def knowledge
>  {:course 'Algebra :g 'B})
>
> (defn generate-goals [knowledge]
>  (map
>(fn [{:keys [course g]}] (list 'grade 'person course g))
>knowledge))
>
> I want to do something like this (but valid clojure):
> (run* [person]
>  ~@(generate-goals knowledge))
>
> It should give me back a list of people who match my current
> knowledge. If I have more knowledge about the person, it will generate
> more conditions, less knowledge fewer conditions. However, since run*
> and run are macros, I can't apply them to a list. I can't splice in
> because I'm not in a quotes list. Any ideas?
>
> Thanks!
>
> --
> 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 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

Core.logic, dynamically generated goals

2012-05-19 Thread Alex Robbins
I'm just getting started with logic programming, and it is entirely
possible I'm just approaching this incorrectly.

Is it possible to use dynamically generated goals in run* ?

For example,

(defrel grade person course g)
(fact grade 'Bob 'Algebra 'B)
(fact grade 'Bob 'Art 'C)
(fact grade 'John 'Algebra 'A)
(fact grade 'John 'Art 'A)
(fact grade 'Ricky 'Algebra 'D)
(fact grade 'Ricky 'Art 'A)

(def knowledge
  {:course 'Algebra :g 'B})

(defn generate-goals [knowledge]
  (map
(fn [{:keys [course g]}] (list 'grade 'person course g))
knowledge))

I want to do something like this (but valid clojure):
(run* [person]
  ~@(generate-goals knowledge))

It should give me back a list of people who match my current
knowledge. If I have more knowledge about the person, it will generate
more conditions, less knowledge fewer conditions. However, since run*
and run are macros, I can't apply them to a list. I can't splice in
because I'm not in a quotes list. Any ideas?

Thanks!

-- 
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: core.logic, goals and facts

2012-05-19 Thread David Nolen
They probably should though I don't think that's a hard requirement. In
Prolog you can write a fact that looks like this:

likes(X,X).

To say that everyone likes themselves. This is probably better expressed as
a regular relation in core.logic and not as a fact.

(defn likes [x y]
  (== x y))

David

On Sat, May 19, 2012 at 1:01 PM, Brent Millare wrote:

> Basic follow up question. I assumed that all facts must be grounded, but I
> never really found the answer to this. Is it true?
>
>
>  --
> 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 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: core.logic, goals and facts

2012-05-19 Thread Brent Millare
Basic follow up question. I assumed that all facts must be grounded, but I 
never really found the answer to this. Is it true?

-- 
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: Lexer and parser generator in Clojure

2012-05-19 Thread John Szakmeister
On Fri, May 18, 2012 at 8:46 AM, Alexsandro Soares
 wrote:
> Hi,
>
>  I'm trying to build a compiler using Clojure. Is there any tools
> like flex and bison generating Clojure code?
>  I'm interested in a lexer/parser in pure Clojure because I think
>  in use the same code with Javascript (via ClojureScript) and Java (via
> Clojure).
> I already know isolated tools like Jflex, JavaCup and Bison generating Java
> and
> Jison, JS/CC and friends for Javascript, but I am just interested in a pure
> Clojure solution.

You might want to look at Parsley:


-John

-- 
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: Different behavior at REPL vs compiled code

2012-05-19 Thread Armando Blancas

>
> Why is there this difference in behavior between interactive and 
> compiled code? 
>

In case you'd wonder why it works at the repl since what we type there are 
strings, too. The repl gets them through a call to (read) which parses 
strings into data structures that are Clojure code.
This step is missing for gen-class classes and the contents of 
*command-line-args* but you could mimic it with something like:
(def argv (map read-string *command-line-args*))
Though you'd want to parse numbers safely as Jim showed, for quick tests 
this can help.

-- 
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: Clojure Bee iPhone app updated

2012-05-19 Thread Robert Stuttaford
Awesome, Kyle, thank you. I'm looking forward to the iPad version with
great anticipation!

On 19 May 2012 16:19, Kyle Oba  wrote:

> Hi Robert,
>
> Thanks for the feedback.  Also, thank you for using the app.  I'm
> flattered.
>
> Doc strings and source code are only available (via Clojure for some of
> the items).  As far as doc strings go, that's a limitation based on whether
> the author of the library attached that metadata to their code.
>
> As for source code, I'm currently pulling that from the
> clojure.repl/source-fn function.  For some items, the source code cannot be
> found.  It seems I can find the source for all the org.clojure/clojure, but
> nothing else.  I'm open to suggestions here, or perhaps I'm doing it wrong?
>  I have some ideas on how to get around this, but don't want to make any
> promises for updates here yet.
>
> An iPad version may materialize at a later date.  But, there are a few
> things on my todo list before then.  As for the returning from the source
> code view, that's something I'm working on and the interaction here will
> probably change in the future.  Sorry that's vague, but I'm working through
> it at the moment.
>
> Thanks again for the feedback.  It's great to hear how things are working,
> or not, as the case may be.
>
> Best,
> Kyle
>
> On Saturday, May 19, 2012 1:42:04 AM UTC-10, Robert Stuttaford wrote:
>>
>> Hey Kyle,
>>
>> I bought this, it looks great. However, browsing around I get a lot of
>> "Sorry, (doc string|Clojure source) not available" messages. Was this
>> intentional? If so, why? If not, will it be fixed sometime soon?
>>
>> Also, could I ask you a huge, massive favour and make the app universal?
>> I'd be completely happy if all you did was allow the app to fill the iPad
>> screen and nothing else. Bonus points for setting up a left-menu,
>> right-detail view configuration on iPad.
>>
>> Lastly, when I viewed a method in landscape, (it was on my iPad, resting
>> on its LapLog), it wasn't clear how to get out of it back to the menus. I
>> realised I had to rotate the device to get out. Providing an X button, or
>> even better, supporting a tap or a pinch gesture to cancel out of that view
>> would be great.
>>
>> This is a great effort, and I'm certain I'm going to be using it a lot.
>>
>> Thanks!
>> Robert
>>
>> On Thursday, May 17, 2012 2:45:26 AM UTC+2, Kyle Oba wrote:
>>>
>>> Just a quick announcement that the Clojure Bee iPhone app was just
>>> updated.  This release eliminates crashiness and updates the font for
>>> the source code view.
>>>
>>> More info on the app here:
>>> http://itunes.apple.com/us/**app/clojure-bee-api-**
>>> documentation/id524862532?ls=**1&mt=8
>>>
>>> Anyone interested in a free copy, please email me directly (it's $1).
>>> I'm more than happy to give free copies to the Clojure community.
>>>
>>> Thanks!
>>> Kyle
>>>
>>> PS - It's called Clojure *Bee* because there is a quiz component, yet
>>> to be released (coming soon!).
>>
>>  --
> 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 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: Clojure Bee iPhone app updated

2012-05-19 Thread Kyle Oba
Hi Robert,

Thanks for the feedback.  Also, thank you for using the app.  I'm flattered.

Doc strings and source code are only available (via Clojure for some of the 
items).  As far as doc strings go, that's a limitation based on whether the 
author of the library attached that metadata to their code.

As for source code, I'm currently pulling that from the 
clojure.repl/source-fn function.  For some items, the source code cannot be 
found.  It seems I can find the source for all the org.clojure/clojure, but 
nothing else.  I'm open to suggestions here, or perhaps I'm doing it wrong? 
 I have some ideas on how to get around this, but don't want to make any 
promises for updates here yet.

An iPad version may materialize at a later date.  But, there are a few 
things on my todo list before then.  As for the returning from the source 
code view, that's something I'm working on and the interaction here will 
probably change in the future.  Sorry that's vague, but I'm working through 
it at the moment.

Thanks again for the feedback.  It's great to hear how things are working, 
or not, as the case may be.

Best,
Kyle

On Saturday, May 19, 2012 1:42:04 AM UTC-10, Robert Stuttaford wrote:
>
> Hey Kyle,
>
> I bought this, it looks great. However, browsing around I get a lot of 
> "Sorry, (doc string|Clojure source) not available" messages. Was this 
> intentional? If so, why? If not, will it be fixed sometime soon?
>
> Also, could I ask you a huge, massive favour and make the app universal? 
> I'd be completely happy if all you did was allow the app to fill the iPad 
> screen and nothing else. Bonus points for setting up a left-menu, 
> right-detail view configuration on iPad.
>
> Lastly, when I viewed a method in landscape, (it was on my iPad, resting 
> on its LapLog), it wasn't clear how to get out of it back to the menus. I 
> realised I had to rotate the device to get out. Providing an X button, or 
> even better, supporting a tap or a pinch gesture to cancel out of that view 
> would be great.
>
> This is a great effort, and I'm certain I'm going to be using it a lot.
>
> Thanks!
> Robert
>
> On Thursday, May 17, 2012 2:45:26 AM UTC+2, Kyle Oba wrote:
>>
>> Just a quick announcement that the Clojure Bee iPhone app was just 
>> updated.  This release eliminates crashiness and updates the font for 
>> the source code view. 
>>
>> More info on the app here: 
>>
>> http://itunes.apple.com/us/app/clojure-bee-api-documentation/id524862532?ls=1&mt=8
>>  
>>
>> Anyone interested in a free copy, please email me directly (it's $1). 
>> I'm more than happy to give free copies to the Clojure community. 
>>
>> Thanks! 
>> Kyle 
>>
>> PS - It's called Clojure *Bee* because there is a quiz component, yet 
>> to be released (coming soon!).
>
>

-- 
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: Different behavior at REPL vs compiled code

2012-05-19 Thread Michael Gardner
On May 19, 2012, at 3:19 AM, Andy Fingerhut wrote:

> Whereas Perl would automatically convert from a string to a number in a case 
> like this, Clojure does not.  One could argue that such auto-conversion of 
> types, while convenient in many cases in Perl, is also a source of errors in 
> programs.

Indeed. To put it another way, weak typing allows certain logic errors to go 
undetected longer (vs. strong typing). One could argue the same for dynamic vs. 
static typing, but I don't think the same answer has to hold in both cases, 
since the trade-offs differ.

-- 
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: Lexer and parser generator in Clojure

2012-05-19 Thread Matt Mitchell
Here's a parser: https://github.com/joshua-choi/fnparse

Doesn't look like it's active, but could be a starting point?

- Matt

On Friday, May 18, 2012 8:46:19 AM UTC-4, Alexsandro Soares wrote:
>
> Hi,
>
>  I'm trying to build a compiler using Clojure. Is there any tools 
> like flex and bison generating Clojure code? 
>  I'm interested in a lexer/parser in pure Clojure because I think
>  in use the same code with Javascript (via ClojureScript) and Java (via 
> Clojure). 
> I already know isolated tools like Jflex, JavaCup and Bison generating 
> Java and
> Jison, JS/CC and friends for Javascript, but I am just interested in a 
> pure Clojure solution.
>
> Thanks in advance for any answer.
>
> Cheers,
> Alex
>

-- 
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: Clojure Bee iPhone app updated

2012-05-19 Thread Robert Stuttaford
Hey Kyle,

I bought this, it looks great. However, browsing around I get a lot of 
"Sorry, (doc string|Clojure source) not available" messages. Was this 
intentional? If so, why? If not, will it be fixed sometime soon?

Also, could I ask you a huge, massive favour and make the app universal? 
I'd be completely happy if all you did was allow the app to fill the iPad 
screen and nothing else. Bonus points for setting up a left-menu, 
right-detail view configuration on iPad.

Lastly, when I viewed a method in landscape, (it was on my iPad, resting on 
its LapLog), it wasn't clear how to get out of it back to the menus. I 
realised I had to rotate the device to get out. Providing an X button, or 
even better, supporting a tap or a pinch gesture to cancel out of that view 
would be great.

This is a great effort, and I'm certain I'm going to be using it a lot.

Thanks!
Robert

On Thursday, May 17, 2012 2:45:26 AM UTC+2, Kyle Oba wrote:
>
> Just a quick announcement that the Clojure Bee iPhone app was just 
> updated.  This release eliminates crashiness and updates the font for 
> the source code view. 
>
> More info on the app here: 
>
> http://itunes.apple.com/us/app/clojure-bee-api-documentation/id524862532?ls=1&mt=8
>  
>
> Anyone interested in a free copy, please email me directly (it's $1). 
> I'm more than happy to give free copies to the Clojure community. 
>
> Thanks! 
> Kyle 
>
> PS - It's called Clojure *Bee* because there is a quiz component, yet 
> to be released (coming soon!).

-- 
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: [ANN] Clojure Namespace Browser (clj-ns-browser "1.0.0")

2012-05-19 Thread Roberto Mannai
I got the error:

*user=>  (use 'clj-ns-browser.sdoc)
ClassNotFoundException com.fasterxml.jackson.core.JsonFactory*
java.net.URLClassLoader$1.run (URLClassLoader.java:366)

Should I add any jackson dependency? I followed these instructions on
Windows / lein 1.7:

;; Leiningen version 1
:dev-dependencies [[clj-ns-browser "1.2.0"]]

$ lein deps
$ lein repl
user=> (use 'clj-ns-browser.sdoc)


On Thu, May 17, 2012 at 3:34 AM, Andy Fingerhut wrote:

> Did you use the instructions under "Install & Start-up" on this page?
>
> https://github.com/franks42/clj-ns-browser
>
> Also, what OS are you using (and if Windows, are you using Cygwin, too?),
> and what do you get as output of the command "lein version"?
>
> Thanks,
> Andy
>
> On May 16, 2012, at 6:16 PM, thenwithexpandedwingshesteershisflight wrote:
>
> > I get NoSuchMethodError
> org.apache.http.conn.ssl.SSLSocketFactory.(Lorg/apache/http/conn/ssl/TrustStrategy;)V
>  clj-http.core/fn--5014 (core.clj:64)
>
> --
> 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 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: Different behavior at REPL vs compiled code

2012-05-19 Thread Andy Fingerhut
Clojure does "know" the type -- it knows that it is a string, rather than a 
number, and it does not support doing arithmetic operations on strings, hence 
the error.

Whereas Perl would automatically convert from a string to a number in a case 
like this, Clojure does not.  One could argue that such auto-conversion of 
types, while convenient in many cases in Perl, is also a source of errors in 
programs.

Andy

On May 19, 2012, at 1:05 AM, Ankit Goel wrote:

> Thanks a lot for the help Meikel and Jim.
> @ Meikel: it worked great as per your suggestion.
> 
> I was just hoping it would be a bit more dynamic and infer the types!!
> 
> On May 18, 11:48 pm, "Jim - FooBar();"  wrote:
>> Try wrapping your if statement in a let with a binding : [k
>> (Integer/parseInt n) ]
>> and then use k from then onas Ankit said, arguments passed from cmd
>> are always strings...
>> 
>> Jim
>> 
>> On 18/05/12 07:39, Ankit Goel wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Hi,
>> 
>>> I have recently started learning clojure and have been setting up
>>> leiningen for managing projects.
>>> I create a new project using "lein new" and modified the "src/
>>> factorial/core.clj" file to contain the following code
>> 
>>> (ns factorial.core
>>>(:gen-class))
>> 
>>> (defn fact [n]
>>>(if (= n 1)
>>> 1
>>>  (*  n  (fact (- n 1)
>> 
>>> (defn -main [n]
>>>(fact n))
>> 
>>> This code runs fine in the REPL. However, when i run the jar file
>>> obtained after running "lein uberjar" i get the following error:
>> 
>>> "Exception in thread "main" java.lang.ClassCastException:
>>> java.lang.String cannot be cast to java.lang.Number"
>> 
>>> Why is there this difference in behavior between interactive and
>>> compiled code?
>> 
>>> Thanks,
>> 
>>> Ankit
> 
> -- 
> 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 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: Different behavior at REPL vs compiled code

2012-05-19 Thread Ankit Goel
Thanks a lot for the help Meikel and Jim.
@ Meikel: it worked great as per your suggestion.

I was just hoping it would be a bit more dynamic and infer the types!!

On May 18, 11:48 pm, "Jim - FooBar();"  wrote:
> Try wrapping your if statement in a let with a binding : [k
> (Integer/parseInt n) ]
> and then use k from then onas Ankit said, arguments passed from cmd
> are always strings...
>
> Jim
>
> On 18/05/12 07:39, Ankit Goel wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I have recently started learning clojure and have been setting up
> > leiningen for managing projects.
> > I create a new project using "lein new" and modified the "src/
> > factorial/core.clj" file to contain the following code
>
> > (ns factorial.core
> >    (:gen-class))
>
> > (defn fact [n]
> >    (if (= n 1)
> >         1
> >          (*  n  (fact (- n 1)
>
> > (defn -main [n]
> >    (fact n))
>
> > This code runs fine in the REPL. However, when i run the jar file
> > obtained after running "lein uberjar" i get the following error:
>
> > "Exception in thread "main" java.lang.ClassCastException:
> > java.lang.String cannot be cast to java.lang.Number"
>
> > Why is there this difference in behavior between interactive and
> > compiled code?
>
> > Thanks,
>
> > Ankit

-- 
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