Open julochrobak opened 11 years ago
DO NOT merge, there is a bug in this branch. The COMP crashes when using a parallel execution:
$ bin/comp '[a|a<~ [1,2]]'
panic: runtime error: index out of range
goroutine 4 [running]:
main.(*Program).Run(0xc2000de300, 0xc2000fe000, 0xc2000c1c90, 0x5)
/Users/julo/comp/src/comp/machine.go:146 +0x19a6
main.func·018(0xc2000de300, 0xc2000fe000)
/Users/julo/comp/src/comp/machine.go:189 +0x38
created by main.(*Program).Run
/Users/julo/comp/src/comp/machine.go:190 +0x242d
goroutine 1 [chan receive]:
main.(*Program).Run(0xc2000de280, 0xc2000ed000, 0xc2000b4680, 0xc2000de280)
/Users/julo/comp/src/comp/machine.go:195 +0x24ba
main.Command(0x7fff5fbffae1, 0xd, 0x2b4940, 0x0, 0x24, ...)
/Users/julo/comp/src/comp/main.go:46 +0x166
main.main()
/Users/julo/comp/src/comp/main.go:98 +0x1a0
goroutine 2 [syscall]:
goroutine 5 [runnable]:
main.func·018(0xc2000de380, 0xc20010f000)
/Users/julo/comp/src/comp/machine.go:188
created by main.(*Program).Run
/Users/julo/comp/src/comp/machine.go:190 +0x242d
this is READY to be merged, the issue with parallel executions was fixed and the source branch julochrobak:tier was rebased and everything is part of the https://github.com/julochrobak/comp/commit/e230d44de30da988fc979261574fb784de6807f4 commit.
I implemented the "$" operator to allow retrieving the index of a loop. Here are some examples:
There are two things to discuss:
I also tried to implement a function which would take the iteration variable and return it's index, for example:
but I find this very complex to implement, because the "i" would have to change from an element of a list into kind of an object which contains also "iteration" information and the actual list element, and than the "index" function has to access the iteration part of this object, while everything else must access the element part:
may be there is a simple way to do it...
the other question is, why are we actually implementing this? if we only want to allow to take just part of a list we can do it either either the haskell way:
or the golang way:
I prefer to have both the
$
operator together with the golang way of getting a slice of a list.The$
is valuable for all kinds of more complex calculations/filtering, e.g. take the elements only on the every second position in the list, can be put in the result to remember a position of an element in the list, and so on...