1. Syntactic sugar
- Posted by begin Mar 20, 2018
- 1476 views
hi,
would it be possible to have '#' as an alternative for '!=' ? it's easier to read and less typing.
phix maybe?
richard
2. Re: Syntactic sugar
- Posted by _tom (admin) Mar 20, 2018
- 1504 views
hi,
would it be possible to have '#' as an alternative for '!=' ? it's easier to read and less typing.
phix maybe?
richard
The # is already in use by OE
- At the moment # is used for to mean "hexadecimal"
? #FE --> 256
That suggests that:
-- suggested syntax ? #FE # #FC --> 1 -- compared to existing syntax ? #FE != #FC --> 1
- #! is the Unix shebang comment; also in use by OE
- # is used in conventional languages to mean "comment"
My observations:
- not a trivial change to the OE syntax
- not sure the syntactic sugar is an improvement
- quick search does not reveal # is used to mean != elsewhere
Need more convincing that # needs another meaning in OE beyond the existing meanings.
_tom
3. Re: Syntactic sugar
- Posted by begin Mar 20, 2018
- 1506 views
used in modula (https://www.modula2.org/modula-2.php), j etc
but if the effort is large then it doesn't matter - just a suggestion for readability (subjective).
richard
4. Re: Syntactic sugar
- Posted by _tom (admin) Mar 20, 2018
- 1473 views
So "≠" (U+2260) becomes # when you can not enter a enter a UTF character.
Lets wait for comments from others.
_tom
5. Re: Syntactic sugar
- Posted by ghaberek (admin) Mar 20, 2018
- 1494 views
would it be possible to have '#' as an alternative for '!=' ? it's easier to read and less typing.
I don't like it. Doesn't seem easier to read to me at all.
I use a lot of different languages and a majority of them use != while some might use <>. A majority of them also use # for single-line comments.
I'm not saying we should continue to do what we've always done, but sometimes conventions stick around because they work and I think what we have works well.
Keep in mind, if readable is what you want, then you can always just use the equal() function.
if not equal( a, b ) then
-Greg
6. Re: Syntactic sugar
- Posted by begin Mar 20, 2018
- 1465 views
So "≠" (U+2260) becomes # when you can not enter a enter a UTF character.
in the old day, there was just '#'.
7. Re: Syntactic sugar
- Posted by begin Mar 20, 2018
- 1450 views
I don't like it. Doesn't seem easier to read to me at all.a matter of taste said the monkey and ate the soap. it should/could be an alias, so it will not break existing code. for anyone with some math background, the # and = make sense. just because some some scripters took an easy way out for comments, does not make it bad.
I'm not saying we should continue to do what we've always done, but sometimes conventions stick around because they work and I think what we have works well.
this was/is convention, just like = and == in math oriented syntaxes.
never the less, if it is not trivial and/or a lot of effort, then please forget the suggestion. it is not religious, but a lazy, readable way to say # instead of != (c/d/c# ...) or <> (pascal ...).
richard
8. Re: Syntactic sugar
- Posted by ghaberek (admin) Mar 20, 2018
- 1449 views
- Last edited Mar 22, 2018
it should/could be an alias, so it will not break existing code. for anyone with some math background, the # and = make sense. just because some some scripters took an easy way out for comments, does not make it bad.
never the less, if it is not trivial and/or a lot of effort, then please forget the suggestion. it is not religious, but a lazy, readable way to say # instead of != (c/d/c# ...) or <> (pascal ...).
I'm not the final authority on these things, but I don't see it being a realistic possibility.
You're welcome to implement this yourself using the preprocessor. (I'm sure this code could be made more smarter.)
include std/io.e include std/search.e sequence cmd = command_line() sequence inFileName, outFileName for i = 3 to length( cmds ) do switch cmd[i] do case "-i" then inFileName = cmd[i+1] case "-o" then outFileName = cmd[i+1] end switch end for sequence lines = read_lines( inFileName ) for i = 1 to length( lines ) do if search:begins( "#!", lines[i] ) then -- skip shebang line continue end if -- replace all instances of " # " with " != " -- using spaces should prevent accidentally -- replacing hex numbers (e.g. #80040023) lines[i] = match_replace( " # ", lines[i], " != " ) end for write_lines( outFileName, lines )
-Greg
9. Re: Syntactic sugar
- Posted by begin Mar 21, 2018
- 1430 views
thanks greg, that is a good idea. but i would have to run an additional program to modify the language. i don't want to do that - so i'll live with !=
richard
10. Re: Syntactic sugar
- Posted by jimcbrown (admin) Mar 21, 2018
- 1461 views
but i would have to run an additional program to modify the language.
You wouldn't have to manually run it yourself beforehand.
http://openeuphoria.org/docs/preproc.html#_672_pdefineapreprocessor
You could easily set up eu.cfg to do this automatically every time.
11. Re: Syntactic sugar
- Posted by begin Mar 21, 2018
- 1422 views
thank for the hint, i try that. but in the end i think i stay with what the language offers.
richard