ekzhang/crepe

Implement disaggregates

Cypher1 opened this issue · 3 comments

Similar to aggregates using bindings in #10, it seems useful to be able to disaggregate/iterate over data.

Enumerating values from an iterator would allow us to use data from outside of crepe without having to convert functions to use work-arounds like range predicates inside Crepe.

I have a suggestion for the syntax as well as some possible use cases below:

e.g. Accessing the characters in a string inside Crepe.

Name(*str);

NameContainsLetter(name, letter) <- Name(name), for letter in name; 

e.g. Using a 'shortest_path' function that returns a list of edges traversed.

struct Node(i32);
struct ShortestPath(i32, i32, i32, i32); //start, finish, from, to

ShortestPath(start, finish, from, to) <- Node(start), Node(finish), for (from, to) in shortest_path(start, finish);

Thanks for the suggestion! This is really interesting. I like the idea a lot. Just so we're on the same page, it be adding another term of the form:

for :pat in :expr

Which gets translated directly to the same loop in Rust code. The way we would detect this kind of term is that it starts with the keyword for. Is that right?

Implemented in v0.1.6.