trueagi-io / metta-examples

Discussion of MeTTa programming with examples
MIT License
17 stars 16 forks source link

Scheme's apply and map analogs in Metta #53

Open CICS-Oleg opened 4 hours ago

CICS-Oleg commented 4 hours 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 3 hours 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 30 minutes 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.