On Thu, Sep 17, 2015 at 4:07 PM, Eduardo Bellani <ebell...@gmail.com> wrote:
>
> Hello Jay,
>
> Thanks, I've figured out the raco incantation beforehand. I should've
> read more about the docs before asking.
>
> One other question that slipped my mind before, about wildcards. Let's
> take this example again:
>
>
>  (define *db* (make-theory))
>
>  (datalog *db*
>           ;; shareholders
>           (! (shareholder "Jorge"    person))
>           (! (shareholder "Bob"      person))
>           (! (shareholder "Googly"   company))
>           (! (shareholder "Megasoft" company))
>           ;; ownership
>           (! (owns-a-share "Jorge"  "Construction SA" 60.8))
>           (! (owns-a-share "Bob"    "Construction SA" 39.2))
>           (! (owns-a-share "Bob"    "WAKA SA"         100 ))
>           (! (owns-a-share "Googly" "Toys SA"         100 )))
>
>
>  (let ((majority? (λ (percent)
>                     (> percent 50))))
>    (datalog *db*
>             (! (:- (major-stockholder COMPANY)
>                    (shareholder SHAREHOLDER _) ;; <- I don't care about this 
> attribute
>                    (owns-a-share SHAREHOLDER COMPANY PERCENT)
>                    (majority? PERCENT :- #t)))))
>
> This is throwing this error:
>
>  _: wildcard not allowed as an expression
>
> Any idea of what I'm doing wrong?

_ is this: 
http://docs.racket-lang.org/reference/stx-patterns.html?q=_#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29

Since it is an identifier, with a binding, then Datalog tries to
insert the value into the query and fails because you can't use _ as
an expression.

To do what you want in Datalog, you should just use a variable and not
constrained it anywhere else, so

(shareholder SHAREHOLDER IGNORED)

Jay

> Thanks again.
>
> Jay McCarthy writes:
>
>> I would do "raco pkg update --clone datalog" from "$PLTHOME/extra-pkgs"
>>
>> Jay
>>
>> On Thu, Sep 17, 2015 at 2:05 PM, Eduardo Bellani <ebell...@gmail.com> wrote:
>>>
>>> Hello Jay, thanks for your time.
>>>
>>> I'll try the update asap. One question to anyone, what would the the
>>> canonical way of fetching such an update in racket's package system?
>>>
>>>
>>>
>>> Jay McCarthy writes:
>>>
>>>> On Wed, Sep 16, 2015 at 2:50 PM, Eduardo Bellani <ebell...@gmail.com> 
>>>> wrote:
>>>>> Hello list
>>>>>
>>>>> I'm trying to use racket's implementation of datalog as a query language
>>>>> for a small database (5 gb). I'm running into some problems that I'd
>>>>> appreciate your help with:
>>>>>
>>>>> * Is there support for negating a subgoal? E.g: [1]
>>>>>
>>>>>  Get the names of employees who do not work on any project.
>>>>>  temp1(S) :- works_on(S,_,_).
>>>>>  answer(F,M,L) :- employee(F,M,L,S,_,_,_,_,_,_), not temp1(S).
>>>>
>>>> No, but I have no objection to someone adding this. I believe it will
>>>> require a different evaluation technique (bottom-up vs the present
>>>> top-down) to run efficiently.
>>>>
>>>>> * Is there support for other comparison operators outside {=, !=}? E.g.
>>>>>
>>>>> (datalog *db*
>>>>>          ;; shareholders
>>>>>          (! (shareholder "Jorge"    person))
>>>>>          (! (shareholder "Bob"      person))
>>>>>          (! (shareholder "Googly"   company))
>>>>>          (! (shareholder "Megasoft" company))
>>>>>          ;; ownership
>>>>>          (! (owns-a-share "Jorge"  "Construction SA" 60.8))
>>>>>          (! (owns-a-share "Bob"    "Construction SA" 39.2))
>>>>>          (! (owns-a-share "Bob"    "WAKA SA"         100 ))
>>>>>          (! (owns-a-share "Googly" "Toys SA"         100 )))
>>>>>
>>>>>
>>>>> (let ((majority? (λ (percent)
>>>>>                    (> percent 50))))
>>>>>   (datalog *db*
>>>>>            (! (:- (major-stockholder COMPANY)
>>>>>                   (shareholder SHAREHOLDER person)
>>>>>                   (owns-a-share SHAREHOLDER COMPANY PERCENT)
>>>>>                   (majority? PERCENT :- TEMP)
>>>>>                   (= TEMP true)))))
>>>>
>>>> You could write (majority? PERCENT :- #t)
>>>>
>>>> Here's a tiny example
>>>>
>>>> #lang racket/base
>>>> (require datalog)
>>>>
>>>> (datalog (make-theory)
>>>>          (! (number 0))
>>>>          (! (number 1))
>>>>          (! (number 2))
>>>>          (! (number 3))
>>>>          (! (:- (awesome N)
>>>>                 (number N)
>>>>                 (even? N :- #t)))
>>>>          (? (awesome N)))
>>>>
>>>>> * A syntax extension difficulty, not very much related to datalog per
>>>>>   se. I have this syntax extension:
>>>>>
>>>>>
>>>>> (define-syntax (->relations stx)
>>>>>   ;; point here being getting true relations (sets) out of the results
>>>>>   (syntax-case stx ()
>>>>>     [(_ rel-name rel-size)
>>>>>      (with-syntax ([rel-vars (for/list ([x (in-range (syntax->datum 
>>>>> #'rel-size))])
>>>>>                                (gensym 'X))])
>>>>>        #`(map (λ (dic)
>>>>>                 (list->set
>>>>>                  (map (λ (rel-var)
>>>>>                         (hash-ref dic rel-var))
>>>>>                       #'rel-vars)))
>>>>>               (datalog *db* (? (#,#'rel-name
>>>>>                                 #,@#'rel-vars)))))]))
>>>>>
>>>>> This is an case of an usage, in the context of the previous example:
>>>>>
>>>>> (->relations major-stockholder 1)
>>>>>
>>>>> I'm bumping in the following error:
>>>>>
>>>>> make-variable: contract violation
>>>>>   expected: (or/c #f (list/c any/c (or/c exact-positive-integer? #f) 
>>>>> (or/c exact-nonnegative-integer? #f) (or/c exact-nonnegative-integer? #f) 
>>>>> (or/c exact-positive-integer? #f)))
>>>>>   given: '(#f #f #f #f 0)
>>>>>   in: the 1st argument of
>>>>>       (->
>>>>>        (or/c
>>>>>         #f
>>>>>         (list/c
>>>>>          any/c
>>>>>          (or/c exact-positive-integer? #f)
>>>>>          (or/c exact-nonnegative-integer? #f)
>>>>>          (or/c exact-nonnegative-integer? #f)
>>>>>          (or/c exact-positive-integer? #f)))
>>>>>        symbol?
>>>>>        variable?)
>>>>>   contract from: <pkgs>/datalog/ast.rkt
>>>>>
>>>>> Which I interpreted as the LOC being lost in the syntax generator. I
>>>>> haven't being able to resolve that yet. Any light on the subject?
>>>>
>>>> This is an error on my part. It should be POS NONNEG POS NONNEG but I
>>>> wrote POS NONNEG NONNEG POS. I just did a push, let me know if that
>>>> fixes it (or you could just change it on your own copy.)
>>>>
>>>> Jay
>>>>
>>>>> Thanks in advance for any pointers.
>>>>>
>>>>> [1] http://tinman.cs.gsu.edu/~raj/8710/f05/datalog.pdf
>>>>>
>>>>> --
>>>>> Eduardo Bellani
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "Racket Users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>>>> email to racket-users+unsubscr...@googlegroups.com.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> Eduardo Bellani
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> Eduardo Bellani



-- 
Jay McCarthy
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to