hikari-no-yume / Firth

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

Add boolean constants & basic boolean algebra #13

Closed mathroc closed 9 years ago

mathroc commented 9 years ago

Hi!

If you don't mind contributions, here is an implementation of boolean constants & algebra. Is that what you has in mind in #2?

hikari-no-yume commented 9 years ago

So far as I can see this is great! Only problem: doesn't amend the spec to actually add boolean literals (and remove true and false variables, if I put them in).

hikari-no-yume commented 9 years ago

Oh and yeah, I'm fine with contributions, I'd really appreciate them since I don't work on this often enough.

mathroc commented 9 years ago

yeah I first tried to declare true and false in stdlib.js but with this implementation I had to use it like that : false. not. show. By making true and false literals I can now use them without the dot : false not. show.

I might have missed something obvious ^^ but as you said it can be changed later

(spec amended)

hikari-no-yume commented 9 years ago

Oh, I mean define them in stdlib as variables, not functions. stdlib functions are just variables containing function values anyway, I just didn't make plain def yet.

hikari-no-yume commented 9 years ago

You only have to use the . because using a function's name merely places it on the stack, while . executes it. For a variable you need only place it on the stack, nothing to execute.

mathroc commented 9 years ago

Oh that was actually so simple! https://github.com/mathroc/Firth/commit/814b29e7a37d193c0cede9ab6ce1279a0efde51e ( note: I guess that would need to be flagged as a constant to disallow shadowing or changing the value )

would you like me to replace this PR with it instead ?

hikari-no-yume commented 9 years ago

Well, I've decided that I want to allow shadowing (and I'll close that issue) after reading Guido's blog post I linked earlier. So, I'll keep it as a literal so it can't be shadowed. We can always change it later to not be a literal, but the reverse is less doable (backwards-compatibility, though that's currently unimportant). By the way, I don't plan to allow variables to be re-assigned, so that's not a problem. (If they are to be mutable, I guess I'll require some special flag?)

hikari-no-yume commented 9 years ago

One final thing: you should probably move this pull request to another branch on your repository, and revert your master branch to be in sync with mine.

hikari-no-yume commented 9 years ago

(otherwise you're gonna have problems later!)

hikari-no-yume commented 9 years ago

Anyway, thanks for doing this! :)