Open ozra opened 8 years ago
This explanation is difficult to follow. And even after following it, I don't see the point. The '
suffix is used in mathematics because there is no implied sense of the passage of time:
a = a + 1 -- total nonsense in mathematical terms
a' = a + 1 -- the suffix is needed to indicate a change is occurring, rather than an assertion
In programming, this is not needed:
value = some-calculation
value = value.some-further-processing
puts value
In the case of wrapped functions, as in your second example, I personally suffix an underscore. Ruby example:
def print(hash)
print_(hash, 0)
end
private def print_(hash, indent_level)
hash.each do |k,v|
case v
when Hash, Array
puts "%s: " % k
print_(v, indent_level+1)
else
puts "%s: %s" % [k,v]
end
end
end
Also, sometimes it's better to make it a nested function, or an anonymous function. Speaking of which, it'd be handy to be able to recurse an anonymous function. We'd need a keyword (a la super
) or some kind of lexical reference, that means "the current function":
->(){
.() # infinite recursion
}.()
In programming, this is not needed
Those derived values are all used subsequently. The imperative mutating example you show doesn't counter that use example. I write zillions of lines of code like that in series analysis, where there are often derived series from others with slight variations that occur again and again, and where tacking on name-suffixes makes little sense or help.
In the case of wrapped functions, as in your second example, I personally suffix an underscore.
That's a valid approach. I don't think it looks better or clearer though.
Further discussion on anon self reference should go into it's own issue.
derived series from others with slight variations that occur again and again
Then I'm afraid I don't really understand the problem we're trying to solve.
Exactly what I described in the examples? :-P
Yet other examples where "pretty much the same thing" is needed, the very idiomatic "assign to local to lock the state for flow inference":
type Foo
@foo Int32? 'get 'set
@bar Str? 'get 'set
do-some-shit() ->
if foo' = foo && bar' = bar
do-stuff-with foo', bar'
foo'.more-stuff bar'
end
end
end
Not necessarily an argument for '
specifically, but for the ability to have a character to de-facto signify such uses.
I still don't understand the problem we're trying to solve here.
Get a good way of naming the temp, derivative or main-impl, etc. commonly reoccurring constructs where a new var/func is needed, but it's not really something that reasonably should be named differently.
Like you solve it with foo_
. (That is common for initialization lists in C++ also, and sometimes instance vars - different style guides). So simply something that does have such a connotation (which prime has) rather than using, for instance, underscore.
I think it would be a helpful feature for some idiomatic patterns.
Btw, the real prime character (′
) isn't supported in any of the popular monofonts (when I tried on google fonts) :-(
Well, this will definitely be a go. It's super-useful. And some syntax to do auto-var-naming: if (foo?.stuff?.here?)' and (qwo())' then use(foo-stuff-here', qwo')
Auto-vars might actually be pretty useful.
I still feel an urge to allow apostrophes (mimicking primes) at the end of identifiers. I've wanted that since the beginning, but put it of again and again because of fear of confusion when reading code - but I think it's very moot!
The prime is used for (grave generalizations here) "it's like x, but processed a step more", or "it's similar to x but not quite". The most common case is derivations. This for both values and functions.
The "fear" is (un)founded in that Onyx currently has two uses of
'
. One common, the other not yet that "known":foo() -> 47 'inline
,@my-ivar Int 'get 'set
, etc. It always starts the pragma identifier, and they are always lowercase.foo(x 'Int) -> 'Real
,@my-ivar 'Int 'get 'set
. Where ever there is a type declaration, for instance annotating a param, for restriction of arg type, or on an ivar for definite typing, one may use the "type prefix", which is simply'
. It's not required in any current case. It is put right at the start of the type and these always begin with capital letters. The main use will be for typing local variables. But it can also be used to disambiguate or clarify. I've been tinkering with the idea of'
always meaning "of the type", so if used in an expression it would then type the expression (acting likeas
), if the type is meant to be passed as a value, it's bare. I've not yet made any decisions here, or allowed time for it, there are more experimental parts of type annotations too, that simply lie waiting half implemented. There will be a time for that.Now, finally: on to the issue at hand, damn it.
Of course, they should probably also be protected, I just avoided it, to not cause confusion regarding this issue (
update'*() -> do-stuff
, cough, cough)This pattern is seen everywhere in code - sometimes with crazy naming schemes, like
do_the_thing
anddo_the_thing_without_this_and_that
as the main function, wrapped by thedo_the_thing
.Instead, making
the-super-func
andthe-super-func'
idiomatically popular naming schemes in Onyx would be a great gain in that aspect imo. When you want the meat of the functionality, and there are several "gateway"-functions of different type specializations, you know how to find the real deal - it's namedthe-muddafuckin-func-name'() ->
I have not yet found a suitable unicode point that represents it nicely, and being implemented in popular fonts.
Well, that was that.