Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for unary plus #484

Closed
wandernauta opened this Issue · 11 comments

4 participants

@wandernauta

Rock currently supports unary minus for literals just fine, but I would like rock to have support for unary plus too :)

glVertex2f(-1, 1) // Works
glVertex2f(+1, 1) // Doesn't work
@duckinator
Collaborator

I'm not sure of the usefulness of this, but there have been a few things I thought would look nicer with an explicit + (like coordinates). Would this work on variables? If so, would it basically just make +a the same as (a > 0 ? a : -a)?

@nddrylliog
Collaborator

I'm pretty much for it. Makes copy/pasting from C OpenGL examples easier ;)

@shamanas
Collaborator

Ok, this sounds easy enough to implement.
@duckinator, I'm not quite sure if +a should be equivalent to a abs(), I'd rather have it the mathematical way, +a == a

@nddrylliog
Collaborator

Agree with @shamanas here. No funny business, no surprises.

@duckinator
Collaborator

Sounds good to me!

@wandernauta

Some languages (including, I believe, C) have the unary + as an upcast (psuedo):

fun foo(short): print "Short"
fun foo(int): print "Int"

short x
foo(+x) # prints "Int"

I don't know ooc/rock well enough to know if this makes sense for ooc. Personally I wouldn't like it - I hate surprises and would rather have the + as a noop (i.e. +a == a).

@duckinator
Collaborator

Noop > upcast, imo.

@nddrylliog
Collaborator

I'm not sure if we should depart from C's behaviour here...

@nddrylliog
Collaborator

I don't think having + as type promotion would be a bad surprise for the unknowing: you never lose precision anyway.

However, having + as a noop would be a bad surprise for people coming from C and expecting it to behave the same way.

My points:

  • Using + unknowingly = no big harm, doesn't change much to your code
  • Using + because it upcasts = disappointed/wtf-y if ooc differes from C.
@wandernauta
@nddrylliog
Collaborator

Alright, after reading various answers in this StackOverflow thread I came to join @duckinator's side (hi nick!) and to say fuck upcasting.

Can we please just get this in as a no-op for the 0.9.8 release?

@nddrylliog nddrylliog closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.