trueagi-io / metta-examples

Discussion of MeTTa programming with examples
MIT License
20 stars 18 forks source link

Scheme's apply and map analogs in Metta #53

Open CICS-Oleg opened 2 months ago

CICS-Oleg commented 2 months ago

Do we have ones? I've made my own funtional variants inspired by SICP examples, but it seems they are lacking efficiency.

Necr0x0Der commented 2 months ago

We don't have a library for them. Their implementation in pure metta will be relatively slow, and this is possibly the reason why we still don't have a library for them. There are two options (besides keeping things as is): 1) implement functional stuff in pure metta and hope that in the future it will be compilable 2) implement more efficient ("precompiled") versions in Rust. In fact, we discussed that some recursion schemes could be a part of Atomspace implementation. For example, it doesn't make sense to retrieve a lot of atoms from DAS and filter them on the interpreter side. At least, map-reduce framework on the DAS (or other type of space) side would make sense. But it will not cover all higher-order functional programming. The question is whether we want 1 or 2 or both... @vsbogd , do you have any thoughts on this?

vsbogd commented 2 months ago

We actually have a functional version of map-atom and foldl-atom in stdlib. @CICS-Oleg have you tried them? I would implement both options using different names. Functional version can become faster if it is compiled or if interpreter performance is better. Native version can be used as a manual optimization.

CICS-Oleg commented 2 months ago

have you tried them?

Not yet. I searched for them but perhaps inattentively. Where are they?

vsbogd commented 2 months ago

Where are they?

https://github.com/trueagi-io/hyperon-experimental/blob/c775589c108d62d3f8f9ef2061e43031de0907ea/lib/src/metta/runner/stdlib_minimal.metta#L293 https://github.com/trueagi-io/hyperon-experimental/blob/c775589c108d62d3f8f9ef2061e43031de0907ea/lib/src/metta/runner/stdlib_minimal.metta#L309

CICS-Oleg commented 2 months ago

@vsbogd Thank you!