Skip to content

clean up functions for smoother run #18

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Bitseat
Copy link

@Bitseat Bitseat commented Jul 10, 2025

No description provided.

Copy link
Collaborator

@ngeiswei ngeiswei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding flatten, it outputs (Error (bc (→ B C)) IncorrectNumberOfArguments), meaning that somewhere down the line, as flatten manipulates the expression it ends up with (bc (→ B C)) and the MeTTa interpreter tries to run it. I don't know why it didn't fail before.

Do you mind attempting to figure out what is wrong?

The following much simpler expression fails for the same reason

!(flatten (: bc A))

Surely, we should be able to prevent MeTTa from running intermediary expressions, using quote or such. Or maybe modify the code so that it does not create such intermediary expression, not sure.

;; Test len-str
!(assertEqual
(len-str "abc")
3)

(: concat-str (-> String String String))
(= (concat-str $lhs $rhs) (charsToString ($lhs $rhs)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is an exploit of weak typing, charsToString is not supposed to work with strings. Although it works, I would recommend to use https://github.com/singnet/ai-dsl/blob/aaa702e9eb6c95268b085ed1906bba6f728ea76f/experimental/ai-service-composition/english-to-chinese-song/etcs-combinator-data-uncurry-xp.metta#L203

(chain (eval (stringToChars $joined-str)) $str-expr ;; working version befor edit just characters are returned as 'A' instead of "A" ..
;; attempt to fix that using charsToString function
(chain (toString $str-expr) $result
(return $result)))))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it is not used anywhere, maybe split-str can be removed.

(chain (eval (charsToString ($head))) $head-str
(chain (eval (toString $tail)) $rest
(chain (cons-atom $head-str $rest) $result (return $result))))
(return ())))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus this could be removed as well (I suppose).

@Bitseat
Copy link
Author

Bitseat commented Jul 11, 2025

Regarding flatten, it outputs (Error (bc (→ B C)) IncorrectNumberOfArguments), meaning that somewhere down the line, as flatten manipulates the expression it ends up with (bc (→ B C)) and the MeTTa interpreter tries to run it. I don't know why it didn't fail before.

Do you mind attempting to figure out what is wrong?

The following much simpler expression fails for the same reason

!(flatten (: bc A))

Surely, we should be able to prevent MeTTa from running intermediary expressions, using quote or such. Or maybe modify the code so that it does not create such intermediary expression, not sure.

On my end, I am getting (Error (bc (→ B C)) BadType). I am on Hyperon version 0.2.4. When I tested it on version 0.2.5, all the flatten tests failed due to the expressions returning in an unevaluated state. I can try to solve this, but on which version did you test it?

@ngeiswei
Copy link
Collaborator

On my end, I am getting (Error (bc (→ B C)) BadType). I am on Hyperon version 0.2.4. When I tested it on version 0.2.5, all the flatten tests failed due to the expressions returning in an unevaluated state. I can try to solve this, but on which version did you test it?

I'm running 0.2.6, but maybe it is not relevant, though I suppose it is probably indeed better if you use the latest version, just in case.

@Bitseat
Copy link
Author

Bitseat commented Jul 15, 2025

The reason for the IncorrectNumberOfArguments error is that we've defined bc as

(: bc (-> $a                            
          Nat                           
          $b                            
          $b))    

Using the same variable name bc in the test

!(assertEqual
  (flatten (: ((ModusPonens (: bc (→ B C)))
               (: ((ModusPonens (: ab (→ A B))) (: a A)) B)) C))
  (: (ModusPonens (: bc (→ B C)) (: (ModusPonens (: ab (→ A B)) (: a A)) B)) C))

causes (bc (→ B C)) to be evaluated, which results in IncorrectNumberOfArguments.

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

Successfully merging this pull request may close these issues.

2 participants