ellxc / piperbot

old version of the new and improved pyperbot
GNU General Public License v2.0
2 stars 4 forks source link

Seval: Missing loops #75

Closed graymalkin closed 9 years ago

graymalkin commented 9 years ago
while condition: list(); of(); actions(); end. 
for x in range(y): list(x); of(); actions(); end.
ellxc commented 9 years ago

They would have to be implemented as functions, as they are invalid syntax as far as the AST is concerned. also the predicate/binding and the body would have to be strings, so that they can be evaluated multiple times. something like:

x = 0; while("x <= 6", "x+=1; x")   => [1,2,3,4,5,6]
for("x", "range(5)", "x*x")   => [0,1,4,9,16]
graymalkin commented 9 years ago

Eww, that looks kinda gross. I don't know how the AST works underneath -- but if this is indeed the case it's very unsatisfying.

ellxc commented 9 years ago

the mode that I parse for seval in with the AST does not allow loops, so this would be the only way, also the words "while" and "for" are keywords, so it would also have to use "while" and "for" or something instead.

graymalkin commented 9 years ago

Could the be passed to a sub-AST?

On 15 Apr 2015 2:00 pm, ellxc notifications@github.com wrote:

the mode that I parse for seval in with the AST does not allow loops, so this would be the only way, also the words "while" and "for" are keywords, so it would also have to use "while" and "for" or something instead.

— Reply to this email directly or view it on GitHubhttps://github.com/ellxc/piperbot/issues/75#issuecomment-93383174.

ellxc commented 9 years ago

I think this is beyond the scope of seval, and most features of a while and a for loop can be emulated in other ways, using list comprehensions and such