How to Implement and register an operation in NARS?

56 views
Skip to first unread message

stevenc...@gmail.com

unread,
May 18, 2021, 12:40:17 PM5/18/21
to open-nars
Hi all 
how to Implement and register an operation in NARS?

I want register an sorting algorithm as an operation in NARS which is implemented by other System and the operation can be call in narsese.

Take the example below:

<(*,1,3,5,4) --> ^sort>.

And then it will call the implementation of sort and it will echo "<(*, 1,3, 4,5)--> is_sorted>. "

Thanks very much.


Patrick Hammer

unread,
Jun 20, 2021, 11:56:16 PM6/20/21
to open...@googlegroups.com
Hi!

Sorry for the late reply.

This depends on the implementation.
OpenNARS: create a class which extends Operator and implements the execute method, there the sorting needs to be done and a feedback event as you suggested with the sorted version of the product can be invoked. Register the op with nar.addOperation(new Sort("^sort"));

ONA: if Python wrapper is used: NAR.AddInput("*setopname 1 ^sort").
Now when NAR.AddInput is called, it will return a dict, with key "executions". Check for a call of ^sort and the arguments, if present do the sorting in Python and add the feedback event with another NAR.AddInput call such as NAR.AddInput("<({SELF * (1 * 2)) --> ^sort>.") Little detail: n-ary products need to be 2-ary nested products instead, e.g. (1 * (2 * 3)).
C/C++:
NAR_AddOperation(Narsese_AtomicTerm("^sort"), SortFunction);
whereby SortFunction is function pointer to a function with void return value and Term (the args product) as input.

Best regards,
Patrick




--
You received this message because you are subscribed to the Google Groups "open-nars" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-nars+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/open-nars/2008f38a-4e9c-4d2d-8780-af83ff16c67an%40googlegroups.com.

stevenc...@gmail.com

unread,
Jun 29, 2021, 1:54:37 AM6/29/21
to open-nars
Got it.

Thanks Very much.

Reply all
Reply to author
Forward
0 new messages