trueagi-io / hyperon-experimental

MeTTa programming language implementation
https://metta-lang.dev
MIT License
133 stars 44 forks source link

Overloading over different numbers of arguments not fully supported #630

Open ngeiswei opened 5 months ago

ngeiswei commented 5 months ago

What is your problem?

Overloading a function with structure with different numbers of arguments confuses the interpreter.

How to reproduce your problem?

Run the following code

;; Unary lambda
(: λ (-> Variable Atom Atom))
(= ((λ $x $f) $y) (let $x $y $f))
!((λ $x (+ 1 $x)) 1)

;; Binary lambda
(: λ (-> Variable Variable Atom Atom Atom))
(= ((λ $x $y $f) $z $w) (let* (($x $z) ($y $w)) $f))
!((λ $x $y (+ $x $y)) 1 2)

What would you normally expect?

[2]
[3]

What do you get instead?

[2]
[3, 3]

What else do you have to say?

The following code

;; Unary foo
(: foo (-> Number Number))
(= (foo $x) (+ 1 $x))
!(foo 1)

;; Binary foo
(: foo (-> Number Number Number))
(= (foo $x $y) (+ $x $y))
!(foo 1 2)

properly works, indicating that the problem comes from the fact that the function is an expression instead of a mere symbol.

luketpeterson commented 5 months ago

There was a discussion about var-args and arity in the context of the import op here: Much of the discussion is pertinent to var-args in general. https://github.com/trueagi-io/hyperon-experimental/pull/580#discussion_r1491332304

luketpeterson commented 5 months ago

Also, it seems like var-args support might be gated on https://github.com/trueagi-io/hyperon-experimental/issues/346 Although that should be fixable.