Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HE vs ML discrepancy: In the REPL, (get-atoms &self) returns a lot of clutter in ML #242

Open
zariuq opened this issue Feb 5, 2025 · 0 comments

Comments

@zariuq
Copy link

zariuq commented Feb 5, 2025

  • A lot seems to be stored in the context or default space that is not present in HE (or is filtered out if it is)

HE:

> (someExpression)
> !(get-atoms &self)
[(someExpression)]

ML:

metta+>(someExpression)
metta+>!(get-atoms &self)
[error metta_NotReducible repl_true (get-atoms &self)][(someExpression), &corelib, &stdlib, (@doc Any (@desc "The universal type; any value belongs to this type.")), (: Any Type), (@doc Atom (@desc "Type representing any atom.")), (: Atom Type), (@doc LazyEvaluatable (@desc "A type of Atom/Value that hyperon does not implicitly evaluate")), (: LazyEvaluatable Type), (:> Atom LazyEvaluatable), (@doc Bool (@desc "Boolean type of True or False.")), (: Bool Type), (@doc LazyBool (@desc "A LazyEvaluatable that when evaluated returns True or False.")), (: LazyBool Type), (:> LazyBool LazyEvaluatable), (@doc Expression (@desc "Type representing an S-Expression, which is a combination of atoms.")), (: Expression Type), (:> Expression LazyEvaluatable), (@doc Number (@desc "Numeric type, including integers and floating-point numbers.")), (: Number Type), (@doc hyperon::space::DynSpace (@desc "Dynamic space type, representing an Atomspace.")), (: hyperon::space::DynSpace Type), (@doc ReturnType (@desc "Type representing a function's return value.")), (: ReturnType Type), (@doc Symbol (@desc "Type representing a symbol or identifier.")), (: Symbol Type), (@doc StateMonad (@desc "Type representing a state monad, used for encapsulating stateful computations.")), (: StateMonad Type), (@doc Type (@desc "Type representing a type.")), (: Type Type), (@doc True (@desc "Boolean value representing truth.")), (: True Bool), (@doc False (@desc "Boolean value representing falsehood.")), (: False Bool), (@doc %Undefined% (@desc "Special type representing an undefined value or type.")), (: %Undefined% Type), (@doc Variable (@desc "Type representing a variable in the language.")), (: Variable Type), (@doc : (@desc "Type declarion operator")), (@doc <: (@desc "Super Type declarion operator")), (: : %Undefined%), (: if-empty (-> Atom Atom Atom Atom)), (: if-non-empty-expression (-> Atom Atom Atom Atom)), (: if-not-reducible (-> Atom Atom Atom Atom)), (: return (-> Atom ReturnType)), (: switch (-> %Undefined% Expression Atom)), (: unify (-> Atom Atom Atom Atom %Undefined%)), (: get-vtype (-> Atom Atom)), (: get-vtype (-> Atom hyperon::space::DynSpace Atom)), (: get-types (-> Atom Atom)), (: get-types (-> Atom hyperon::space::DynSpace Atom)), (: get-dtype (-> Atom Atom)), (: get-dtype (-> Atom hyperon::space::DynSpace Atom)), (: get-ftype (-> Atom Atom)), (: get-ftype (-> Atom hyperon::space::DynSpace Atom)), (: pragma! (-> Atom Atom (->))), (: match (-> hyperon::space::DynSpace Atom Atom %Undefined%)), (: combine (-> $t $t $t)), (: import! (-> hyperon::space::DynSpace Atom (->))), (@doc type-check (@desc "The value of type-check determines MeTTa's type-checking behavior. Set via pragma!. When set to auto (i.e. !(pragma! type-check auto)), types are checked immediately on adding an expression to the space. By default, when unset (or set to anything other than auto), types are checked only on evaluation. For example !(+ 1 \"2\") would trigger a type violation, but (= (foo $x) (+ $x \"2\")) would not, unless type-check is set to auto, in which case both would trigger type violations.")), (: type-check Symbol), (iz predicate-arity MeTTaLog), (@doc predicate-arity (@desc "Specifies the arity (number of arguments) for a given predicate, allowing it to be queriable in the system's match framework. This is particularly useful for enabling built-in functions, such as `size-atom`, to be used as predicates in declarative contexts and run in reverse to compute inputs based on outputs.\n\n\nFor example:\n  ; Enable the built-in function `size-atom` that takes an atom and returns the size\n    as a predicate with arity 2\n  (predicate-arity size-atom 2)\n\n\n  ; Now `size-atom` can be used as a predicate in pattern matching\n  !(match &dyn-space '(size-atom (a b c) $size) \n         (The abc tuple was len $size))\n  ; This pattern will resolve `Size = 3` and execute the action.\n\n\nAdditionally, by running `size-atom` in reverse, you can compute a new atom based on a desired size:\n  !(match &dyn-space '(size-atom $new-atom 4) \n         (The new atom is $new-atom))\n  ; This resolves `$new-atom` to a tuple of size 4, such as ($1 $2 $3 $4).\n\n\nThis reverse functionality is made possible because predicates can describe relationships, allowing you to infer inputs from outputs.") (@params ((@param "Predicate symbol" "The name of the predicate whose arity is being defined."))) (@return "The number of arguments required for the predicate.")), (: predicate-arity (-> Symbol Number)), (predicate-arity predicate-arity 2), (function-arity predicate-arity 1), (@doc function-arity (@desc "Defines the arity of a function, allowing predicates or built-in facts to also behave as callable functions. This enables procedural-style execution where the last argument of the predicate becomes the function's return value, and the system internally resolves the function using a `match` query. \n\n\nFor example:\n  ; Declare the built-in predicate `max` with arity 3\n  (predicate-arity max 3)\n\n  ; Enable `max` as a function\n  (function-arity max 2)\n\n\n  ; Define the rules for `max`\n  (= (max $X $Y $Y) (<= $X $Y))\n  (= (max $X $Y $X) (> $X $Y))\n\n\n  ; Using `max` declaratively as a predicate\n  !(match &self (max (5 10) $max)\n         (The maximum is $max))\n  [(The maximum is 10)]\n\n\n  ; Using `max` procedurally as a function\n  !(max 5 10)\n  [10]\n  \n\n\n  ; Reverse execution with `max`\n  !(let True (== (max $a $b) 10) ($a $b)) ; as a function\n  [(#(exists $a (=< $a 10)) 10), (10 #(exists $b (=< 10 $b )))]\n  !(match &self (max $a $b 10) ($a $b)) ; or as a predicate\n  [(#(exists $a (=< $a 10)) 10), (10 #(exists $b (=< 10 $b )))]\n\n\n  This dual behavior allows predicates to act as functions, bridging procedural and declarative paradigms. By defining `function-arity`, the function automatically resolves using the logic of the associated predicate.") (@params ((@param "Function symbol" "The name of the function or predicate to enable as a callable function."))) (@return "The number of arguments expected by the function.")), (: function-arity (-> Symbol Number)), (predicate-arity function-arity 2), (function-arity function-arity 1), (iz MettaMorph-If MeTTaMorph), (@doc MettaMorph-If (@desc "Conditional function that evaluates and returns one of the provided atoms based on a boolean condition.") (@params ((@param "Boolean condition") (@param "Atom to return if condition is True") (@param "Atom to return if condition is False (optional)"))) (@return "Either the second or third argument depending on the condition")), (: MettaMorph-If (-> Bool Atom Atom Atom)), (: MettaMorph-If (-> Bool Atom Atom)), (= (MettaMorph-If True $then)  $then), (= (MettaMorph-If False $then)  
  (let $n 0 
    (let $n 1 $n))), (= (MettaMorph-If $cond $then $else)  
  (if $cond $then $else)), (iz SrcPredicate MeTTa), (@doc SrcPredicate (@desc "Type representing a source predicate.")), (: SrcPredicate Type), (iz SrcFunction MeTTa), (@doc SrcFunction (@desc "Type representing a source function.")), (
@zariuq zariuq changed the title HE vs ML discrepancy: (get-atoms &self) returns a lot of clutter in ML HE vs ML discrepancy: In the RPEL, (get-atoms &self) returns a lot of clutter in ML Feb 5, 2025
@zariuq zariuq changed the title HE vs ML discrepancy: In the RPEL, (get-atoms &self) returns a lot of clutter in ML HE vs ML discrepancy: In the REPL, (get-atoms &self) returns a lot of clutter in ML Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant