Closed DaddyWesker closed 4 months ago
I've updated the code to ensure it works with new import system.
General question: why do you added two implementations?
Two implementations are using different lists representations. (1 2 3) and (Cons 1 (Cons 2 ( Cons 3 Nil))) . I was working on adding first variant but then Alexey said that this is not in metta style to use cons-atom/cdr-atom/car-atom to work with lists (only with expressions) so I've implemented second variant. I don't know, maybe someone will find useful both variants, or different people would like to see different variants. If you think I should delete one variant - no problem.
I'll check how other suggestions works with the code (I think your suggestion with tree could probably lead to errors with asserts, or to some sort of re-implementation of some functions, so i need to sure it works. I've already borke several spears on this with Alexey and Anatoly).
Current implementation looks strange. For example (== (get-type $x) Number)
is used to find out whether $x
is a leaf of the tree. In this manner we need to define tree traversing function for each type of the tree item. Also it looks strange to me that list
returns tree
s. If you don't need list
here then use tree
everywhere.
As this repository is a MeTTa examples repo I would prefer adding idiomatic example here, so I would leave the only implementation. At least having two big scripts which are different in details of the type implementation is superfluous. One proper way to keep both implementations is to decouple script and data structure. Then have two different data structure modules which has different implementations of the list/tree
.
so I would leave the only implementation
The only which? With Cons and Nill lists?
In this manner we need to define tree traversing function for each type of the tree item
Well, I've mentioned in the chapter that I'm using only numbers there (just like in book's chapter). But anyway, your variant seems more elegant so I'll give it a try and re-implement functions.
Also it looks strange to me that list returns tree
Just like in Scheme. I don't see any strangness there. But if you want to separate this functionality - okay. I just need to re-check that resulting trees works fine with current cdr/car/cons implementations since it is crucial in my opinion that both tree and lists uses same car/cdr implementation since actually tree is just a list of lists. If your tree implementation will allow to use current cons/car/cdr - I'll leave it.
Just like in Scheme. I don't see any strangness there.
Could you please provide an example in Scheme which corresponds to (list ((1 2) (3 4)))
from your implementation.
Just like in Scheme. I don't see any strangness there.
Could you please provide an example in Scheme which corresponds to
(list ((1 2) (3 4)))
from your implementation.
(define lst (list 1 2 3))
(print lst)
(list lst lst)
Just like in Scheme. I don't see any strangness there.
Could you please provide an example in Scheme which corresponds to
(list ((1 2) (3 4)))
from your implementation.(define lst (list 1 2 3)) (print lst) (list lst lst)
It is not similar to (list ((1 2) (3 4)))
it is similar to (list ((list (1 2)) (list (3 4))))
which works with my version of the list
. In Scheme (list (1 2) (3 4))
returns error. So why do you implementing (list ((1 2) (3 4)))
to return tree?
In Scheme
(list (1 2) (3 4))
returns error
(list '(1 2 3) '(3 4 5))
No if you write like this. Anyway, if you are telling me your code will work if I write something like this:
(= (lst) (list (1 2 3 4)))
!(list ((lst) (lst)))
AND it will be parsable by current car/cdr/cons, It'll be fine.
(list '(1 2 3) '(3 4 5))
No if you write like this.
Using quote
and writing (list (1 2 3) (3 4 5))
are not the same. '
in this case is another list constructor. I am talking about consistency. What does list
in Scheme do? It constructs list from its arguments. And what if argument is (1 2 3)
it will be evaluated and result will be added as a single element of the list. What does your implementation of the list
do? It gets each tuple and calls list
on it. And what if argument is (1 2 3)
it will be used to construct list recursively. It is different behavior.
The only which? With Cons and Nill lists?
Yes, I would leave Cons
and Nil
.
@vsbogd all is done. Please check if everything is fine.
So, here I've added exercises and code in between for chapter 2.2. Two files included chapter_2_2 and chapter_2_2_metta. Probably not the best naming. Difference is list representation. In chapter_2_2.metta regular scheme-like lists were used (1 2 3 4). In chapter_2_2_metta.metta metta-like representation was used (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))). And because of that almost every function is different more or less between two scripts.
Scripts are kinda big. I don't know if i should split these scripts somehow. Currently it takes a while to launch scripts. I've also commented out launching of drawing examples since some of them takes too long to complete. Drawing uses external python script with function drawLine and finishDraw. First draws line using two points, second waits 5 seconds (so turtle window won't close too fast and we can see what was drawn) and clears current window. Turtle library was used for drawing.
Since I can't choose reviewers here, I'll mention @vsbogd and @Necr0x0Der .