# core.logic

## generalize the notion of hash for robustness

### Details

• Type: Defect
• Status: Closed
• Priority: Major
• Resolution: Completed
• Affects Version/s: None
• Fix Version/s: None
• Component/s: None
• Labels:
None

### Description

The second nom/hash throws an exception, because the nom/hash constraint is ran before the predc one.

(is (= (run* [q]
(nom/fresh [x]
(fresh [y]
(predc y nom? `nom?)
(nom/hash y x)
(== y 'foo))))
()))

(is (= (run* [q]
(nom/fresh [x]
(fresh [y]
(nom/hash y x)
(predc y nom? `nom?)
(== y 'foo))))
()))

Perhaps, we can generalize the notion of hash.

### Attachments

1. logic-102.diff
07/Jan/13 12:39 PM
5 kB
2. refactoring.diff
08/Jan/13 7:04 AM
2 kB

### Activity

Field Original Value New Value
Description The second nom/hash throws an exception, because the nom/hash constraint is ran before the predc one.
{code}
(is (= (run* [q]
(nom/fresh [x]
(fresh [y]
(predc y nom? `nom?)
(nom/hash y x)
(== y 'foo))))
()))
(is (= (run* [q]
(nom/fresh [x]
(fresh [y]
(nom/hash y x)
(predc y nom? `nom?)
(== y 'foo))))
()))
{code}

Perhaps, we can generalize the notion of hash.
The second nom/hash throws an exception, because the nom/hash constraint is ran before the predc one.
{code}
(is (= (run* [q]
(nom/fresh [x]
(fresh [y]
(predc y nom? `nom?)
(nom/hash y x)
(== y 'foo))))
()))

(is (= (run* [q]
(nom/fresh [x]
(fresh [y]
(nom/hash y x)
(predc y nom? `nom?)
(== y 'foo))))
()))
{code}

Perhaps, we can generalize the notion of hash.
Hide
David Nolen added a comment -

Hmm but why throw in nom/hash like that instead of just failing?

Show
David Nolen added a comment - Hmm but why throw in nom/hash like that instead of just failing?
 Status Open [ 1 ] Resolved [ 5 ] Resolution Completed [ 1 ]
Hide
David Nolen added a comment -

Closed wrong ticket

Show
David Nolen added a comment - Closed wrong ticket
 Resolution Completed [ 1 ] Status Resolved [ 5 ] Reopened [ 4 ]
 Comment
Hide

ok, seems reasonable to fail.

The fix to logic-101 is not entirely satisfactory, because we can now get constraints like _1#[_1]. so i think i also want to not use predc (but still use fixc), but have a custom constraint instead of the predc that takes the two rands into account.

implementing this now.

Show
Nada Amin added a comment - ok, seems reasonable to fail. The fix to logic-101 is not entirely satisfactory, because we can now get constraints like _1#[_1]. so i think i also want to not use predc (but still use fixc), but have a custom constraint instead of the predc that takes the two rands into account. implementing this now.
Hide

The patch logic-102.diff gives up on predc and fixc, and instead does a lot of ugly special-casing to cover the new TDD test cases.

Show
Nada Amin added a comment - The patch logic-102.diff gives up on predc and fixc, and instead does a lot of ugly special-casing to cover the new TDD test cases. Not too happy about this change...
 Attachment logic-102.diff [ 11797 ]
Hide
David Nolen added a comment -

Is there something we could do to make it easier to rely on `fixc` and `predc`? Or is there some lacking feature of constraints?

Show
David Nolen added a comment - Is there something we could do to make it easier to rely on `fixc` and `predc`? Or is there some lacking feature of constraints?
Hide
David Nolen added a comment -

Also if you're OK w/ this patch, more than happy to move forward w/ this for now and it can be improved later.

Show
David Nolen added a comment - Also if you're OK w/ this patch, more than happy to move forward w/ this for now and it can be improved later.
Hide

OK, as discussed, please go ahead with the patch, and I'll think of some alternatives / refactoring soon.

Show
Nada Amin added a comment - OK, as discussed, please go ahead with the patch, and I'll think of some alternatives / refactoring soon.
Hide
David Nolen added a comment -
 Status Reopened [ 4 ] Resolved [ 5 ] Resolution Completed [ 1 ]
Hide

refactoring.diff refactors the logic a bit. Hopefully it's more readable.

For now, it seems too much trouble for the gain to generalize hash or try to write it using more primitive constraints.

Show
Nada Amin added a comment - refactoring.diff refactors the logic a bit. Hopefully it's more readable. For now, it seems too much trouble for the gain to generalize hash or try to write it using more primitive constraints.
 Attachment refactoring.diff [ 11799 ]
Hide
David Nolen added a comment -

Makes sense will apply later today.

Show
David Nolen added a comment - Makes sense will apply later today.
Hide

I am going to apply the refactoring to master.

Show
Nada Amin added a comment - I am going to apply the refactoring to master.
Hide