deathbeam / spoon

:ramen: Spoon is a programming language that runs blazingly fast, compiles to native code and works everywhere.
https://spoonlang.org
MIT License
56 stars 11 forks source link

Support for "and" and "or" #17

Closed Peekmo closed 8 years ago

Peekmo commented 8 years ago

It will be nice if && and || should be replace by and and or keywords

francescoagati commented 8 years ago

also == can be is and != isnt like in livescript

deathbeam commented 8 years ago

Yeah, that would be nice addition

kobi2187 commented 8 years ago

+1! moreover, allow non-null values to be considered true. for example if (obj) do... if obj isn't null, then do is executed. this is also from the cobra language. it's quite useful. I'm not sure, but I think they also support 0 as false, in the if statement.

I think it's objective-c that has yes and no, aliased to true and false. sometimes it reads really nice this way. (maybe also: on and off)

deathbeam commented 8 years ago

This will be added to next version :) According to @kobi2187 suggestion, I am not sure if this will be possible, because in statoc languages you cannot check Int and Bool for null, and I have no way to check it.

deathbeam commented 8 years ago

Fixed with commit add518a536bc0d9f90efa08dead95223ab2fca0f

kobi2187 commented 8 years ago

by the way good progress with all the requests! thanks! to clarify, my suggestion was: [ false, 0, null ] are false in if statements. The down side is that this breaks some of the static typing (if only accepts bool), which may be a little confusing at first, but it looks simple and works well in practice. it improves clarity, but reduces only little code. the idea is that every if expression is checked:

# basic code idea
switch (typeof(ifexpr))
    case Bool:
         return ifexpr
    case Int: # or uint
        return ifexpr != 0
    default:
        if ifexpr not inherits Object
             assert (false, "add match for ifexpr here")  
        else
            return ifexpr isnt null