Skip to content

Commit

Permalink
refactor: ♻️ Refine the cmd register
Browse files Browse the repository at this point in the history
1.  Refine the cmd `register` documentation
2.  Now cmd `register` registering operations via the reasoner of the current NARS interface
  • Loading branch information
ARCJ137442 committed Oct 19, 2023
1 parent 85f05b2 commit 06e3522
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pynars/ConsolePlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,15 @@ def eval_code(*args: List[str]) -> None:

@cmd_register(('register-operation', 'register'))
def register_operation(*args: List[str]) -> None:
'''Format: register-operation <Operation(Term) Name> <"eval"/"exec"> <Python Code>
Register an operation to the whole PyNARS instance.
'''Format: register-operation <Operation(Term) Name> <'eval'/'exec'> <Python Code>
Register an operation to NARS interface.
function signature:
execution_F(arguments: Iterable[Term], task: Task=None, memory: Memory=None) -> Union[Task,None]
default fallback of execution_F when code='' is equivalent to:
print(f'executed: arguments={arguments}, task={task}, memory={memory}. the "task" will be returned')
! Unsupported: register mental operations
'''
name = args[0]
Expand All @@ -300,9 +305,8 @@ def execution_F(arguments: Iterable[Term], task: Task=None, memory: Memory=None)
execution_F.__doc__ = f'''
The execution is auto generated from operator {name} in {eType} mode with code={code}
'''
from pynars.NARS.Operation.Register import register
from pynars.NARS.Operation import Operation
register(Operation(name), execution_F)
current_NARS_interface.reasoner.register_operation(Operation(name), execution_F)
print(f'Operation {name} was successfully registered in mode "{eType}" with code={code}')


Expand Down

0 comments on commit 06e3522

Please sign in to comment.