trueagi-io / metta-wam

A Hyperon MeTTa Interpreter/Transpilier that targets the Warren Abstract Machine
9 stars 11 forks source link

Create WIKI entry for adding functions #66

Open jazzbox35 opened 2 months ago

TeamSPoon commented 2 months ago

Somewhere around https://github.com/trueagi-io/metta-wam/wiki create a page for:

Adding a new built-in function to the MettaLog interpreter. The process includes updating several files within the codebase to ensure the function is properly defined, implemented, and documented.

Task

  1. Define the Function in stdlib_mettalog.metta:

    • Add the function definition to stdlib_mettalog.metta so that MettaLog recognizes it as a built-in function.
    • Example:
      ;; Public MeTTa
      (@doc stringToChars
      (@desc "Converts a String to an Expression of Chars")
      (@params (
      (@param "String to be expanded")))
      (@return "Expression with a list of Chars"))
      (: stringToChars (-> String Expresson))
      ;; Implemented from Interpreters
  2. Implement the Function in metta_eval.pl:

    • Add the implementation of the function to the eval_20 predicate in metta_eval.pl.
    • Use the existing implementations, like 'stringToChars' and 'charsToString', as a reference.
    • Example:
      eval_20(Eq, RetType, Depth, Self, ['yourFunctionName', Arg1], Result) :- 
       !, eval_args(Eq, RetType, Depth, Self, Arg1, EvaluatedArg),
        /* Your implementation logic here */,
       Result = /* Your result here */.
  3. Update the Help Documentation in metta_ontology.pfc.pl:

    • Add the function to the help documentation in metta_ontology.pfc.pl.
    • Example:
      properties('&corelib', 'yourFunctionName', [category, qhelp("Description of your function."), your_function_name]).
  4. Add Test Cases:

    • Add relevant test cases to ensure the function behaves as expected.
    • Example test:
      !(assertEqualToResults (yourFunctionName (inputValues)) (expectedOutput)).

Acceptance Criteria

Reference Documentation

jazzbox35 commented 2 months ago

https://github.com/trueagi-io/metta-wam/wiki/Adding-a-new-built%E2%80%90in-function-to-the-MettaLog-interpreter

jazzbox35 commented 2 months ago

complete