ozra / onyx-lang

The Onyx Programming Language
Other
97 stars 5 forks source link

Gotchas For Crystalers and Rubyists #5

Open ozra opened 8 years ago

ozra commented 8 years ago

Gotchas For Crystalers and Rubyists

It's reasonable that some of you who find interest in Onyx know a bit of Crystal.

There are some differences that can be confusing, likewise if you come from a Ruby background.

Probably some more things - help out by commenting on what confuses you!

stugol commented 8 years ago

I must disagree strongly with the statement:

A "soft-lambda" is part of the arguments, not an "add-on". That means it goes inside parentheses if they're used in a parenthesized call, and is separated with a comma if there are arguments before it. It still only goes last among the arguments.

I'm afraid that is a terrible idea, and a deal-breaker for me. Please reconsider.

stugol commented 8 years ago

What is meant by:

instance-vars do not need @ prefix at declaration site.

?

I also don't see what is wrong with @@, or with .|.

I approve of many of the other changes listed.

ozra commented 8 years ago

@stugol:

  1. Both these are valid atm:
type Foo
   @x Int32
end

type Bar
   x Int32
end
  1. Since type level variables are like globals and the @@-notation is way to close to the @-notation for such a different use-case imo. Self.type-level-var looks more appropriate imo, clearly showing that it is a globally scoped variable, scoped under current type. Do you have some side-by-side code, to compare which looks clearer?

What you approve of - I care little What you like and dislike - I make note of What constructive arguments you present - I value and enjoy

;-)

ozra commented 8 years ago

[regarding "soft lambdas"]

I'm afraid that is a terrible idea, and a deal-breaker for me. Please reconsider.

Why? Care to elaborate on the reason and give some examples? So far I've personally only experienced it as an improvement.

stugol commented 8 years ago

Self.type-level-var is alright, but should not completely replace @@var.

As to soft lambdas, in Ruby, I can do this:

[...].select { |n|
   code
}.map { |n|
   code
}

Granted, there are no parentheses in this example, but my point stands. To do the same with the blocks inside parentheses would be horrible:

[...].select({ |n|
   code
}).map({ |n|
   code
})

reduce takes arguments and blocks.

ozra commented 8 years ago

Well, that would simply be like this in Onyx with the current syntax (parentheses are not required in calls, the soft-lambda simply go inside iff you use paren call):

-- no parens used:
list.select (n) ~>
   code
.map (n) ~>
   code

-- with parens:
list.select((n) ~>
   code
).map((n) ~>
   code
)

-- using auto parametrization:
list.select ~>
   code
.map ~>
   code

Regarding @@var; why would that notation be good to keep in your opinion? Example?

ozra commented 8 years ago

Oh, and reduce:

list = [1, 2, 3]

reduced = list.reduce 0, ~> _1 + _2

-- or:
reduced = list.reduce 0, (acc, v) ~> acc + v

-- or:
reduced = list.reduce(0, ~> _1 + _2)

-- or:
reduced = list.reduce(0, (acc, v) ~> acc + v)
stugol commented 8 years ago
list.select (n) ~>
   code
.map (n) ~>
   code

Does Onyx cope well with lines starting with a .? Ruby does not, for example. As soon as it finds a complete statement, it assumes that the statement is finished. Meaning that only the first two lines of your code would be parsed; and the third line would be an error.

Regarding @@var; why would that notation be good to keep in your opinion? Example?

Mainly because my editor highlights @@-vars with a deeper orange than @-vars. Whereas it would be unable to distinguish between class variables and class methods, and not highlight them at all.

Also, the @@ stands out, just like $. You wouldn't replace $ with Global., would you? Because then it wouldn't be obvious at a glance that you were using a potentially dangerous global variable.

ozra commented 8 years ago

Does Onyx cope well with lines starting with a .

Well, fairly, I'm sure there's room for improvement, after all everything's very new and alpha atm. Just tested this which works fine:

x = list
.select (n) ~>
   code
.map (n) ~>
   code

Regarding @@ var...

You're right damn it! There must be a distinction between type level vars and funcs, otherwise one will always get precedence in name clashes (must verify this!).

I'll throw in another idea: Type@type-level-var, Type.type-level-func

stugol commented 8 years ago

I've had a thought. In Ruby and Crystal, you can't access class-level variables (or instance variables) from outside the class. So Type@var or Type.var make no sense whatsoever. Just use @@, and take the others out.