Dot notation
- Posted by SDPringle Sep 26, 2014
- 1453 views
If we adopt a syntax like this it might be a good idea to always have the parenthesis. In this case, for C plus plus programmers, dot notation is nice. I find it convincing that one should always use parenthesis whether we use dot notation or what I will call function= notation.
-- s = {1,2} s append=(3) -- s = {1,2,3}
Dot notation is like C plus plus and looks more like pass by reference.
s.append(3)
Forked from Re: Append
I have been thinking of adding a syntax extension that would work not only for builtins but also user created routines.
My first reaction was great! SDPringle can invent, and implement, new ideas.
Delayed reaction is: my head might explode. Euphoria does not take kindly to shortcuts and new syntax.
To show that you are working with a subroutine you need an argument list, possibly empty, shown by ( ) parenthesis.
s = append(s, pair ) s append= (pair) s = store(s, key, data ) s store=(key,data)
Allowing () to "vanish" is a nice shortcut that adds another rule, an exception, that must be learned. Extra congnitive effort means not simple. The result is that
--either s append= pair -- breaks a pattern, so it is a problem -- or s store=(key,data) -- adds a pattern, so it is a problem
Will I get confused between a binary operator and a two argument function?
-- two argument function x = append(x,3) x append=(3) -- binary operator ... two arguments x = x + 2 x += 2 -- another kind of two argument function function add( atom a, atom b ) return a+b end function x = add(2,3) x add=(2,3) -- the previous pattern suggests that somehow "add" must be a three argument function -- with the first argument being "x" -- but, that is not what I have in add(2,3)
My point is that I, thats one viewpoint, will make various typing errors in working with this syntax.
Then again, if you had dot notation, then the transition to your shortcut notation might be easy to visualize.
s = append(s, pair ) s = s.append( pair ) s append=(pair) s = store(s, key, data ) s = s.store( key, data ) s store=(key,data)
In dot notation the "self" argument moves to a new location but does not vanish. In the shortcut notation the "self" argument vanishes. If something vanishes, then it is not Euphoric syntax.
_tom