hikari-no-yume / Firth

Firth is a functional, strongly dynamically-typed, concatenative stack-oriented programming language.
Other
29 stars 2 forks source link

fix if & ifelse #25

Closed mathroc closed 9 years ago

hikari-no-yume commented 9 years ago

No, using getValue() won't work for internal functions. I just needed to rewrite it in terms of .invoke(), so (condition.getValue() ? trueCase : falseCase).invoke();

hikari-no-yume commented 9 years ago

There's also no real need for getValue in functions just yet, so I won't add it.

mathroc commented 9 years ago

well, source returned by getValue() for function is actually useful for the \ast command in the REPL (see #24). or maybe it should be some other name ?

hikari-no-yume commented 9 years ago

Obsoleted by https://github.com/TazeTSchnitzel/Firth/commit/039b22f10b0d639890d1acf6316e0045c21c2f3a

mathroc commented 9 years ago

oh, I finally understood what's wrong. when calling execute, the first argument needs to be an AST, but in if and ifelse it "just" a function so ast,length is undefined and nothing happens.

so it should be either [trueCase, {type: 'invoke'}] or trueCase,getValues()

mathroc commented 9 years ago

or just trueCase.invoke(stack, scope); as you just pushed ^^

hikari-no-yume commented 9 years ago

I think I'll make execute use forEach to iterate over the array. for (var i = 0; i < ast.length; i++) is an anachronism, and this'll make failure more obvious.

hikari-no-yume commented 9 years ago

Done: https://github.com/TazeTSchnitzel/Firth/commit/dbef1d4cc9b61e8d6e386bf5667cc465ca3ecfbe

mathroc commented 9 years ago

:+1: