I'm wondering how to work with autoNumbered refmode predicates in LogicBlox / LogiQL
I followed the example in the manual but then am having trouble asserting facts into the entity predicate, the first one would be added but subsequent attempts would not be.
Here is what I tried to do in the LB interactive shell:
lb> create wibble
created workspace 'wibble'
lb wibble> addblock '
>auto(x), auto_id(x:id) -> int(id).
>lang:autoNumbered(`auto_id).
>cons_auto[] = x -> auto(x).
>lang:constructor(`cons_auto).'
added block 'block_1Z2ZWC0N'
lb wibble> exec '+auto(x), +cons_auto[] = x.'
lb wibble> popcount auto
1: auto
lb wibble> exec '+auto(x), +cons_auto[] = x.'
lb wibble> popcount auto
1: auto
The issue here is the constructor, cons_auto. The way constructors work is that, for every unique key-tuple to the constructor, a unique entity is created, regardless how many times you assert into the constructor with the same key-tuple
You have defined a constructor with no key. This means exactly one entity will be created using this constructor no matter how many times you execute a delta rule asserting into it.
You can define the constructor a bit differently, with one key for example:
cons_auto_onekey[key] = x -> int(key), auto(x).
lang:constructor(`cons_auto_onekey).
Now you can do:
+cons_auto_onekey[1] = x, +auto(x).
And then,
+cons_auto_onekey[2] = x, +auto(x).
You would see that there would be two auto entities created.
Now of course, I suspect this is not what you want -- because how are you suppose to get the keys? The whole point you made auto an auto-numbered entity is probably because you wanted to automatically generate "references".
This is where transaction:id would be useful. e.g.
+cons_auto_onekey[key] = x, +auto(x) <-
transaction:id[] = key.
Note that, transaction:id is unique per transaction, per workspace. That means in the same transaction, you get only one transaction:id, and if you want to create more than one auto entity in the same transaction, you'll have to do some computation off of transaction:id to get further unique numbers within the transaction.
There's also a uid series function that can also help generate unique id's. But you'll have to have something unique to use to generate using it. I'm not sure that'll help you but let me know if the above doesn't get you far enough, and we can explore whether uid can help.