1. Syntactic sugar

hi,

would it be possible to have '#' as an alternative for '!=' ? it's easier to read and less typing.

phix maybe?

richard

new topic     » topic index » view message » categorize

2. Re: Syntactic sugar

begin said...

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Syntactic sugar

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Syntactic sugar

So "≠" (U+2260) becomes # when you can not enter a enter a UTF character.

Lets wait for comments from others.

_tom

new topic     » goto parent     » topic index » view message » categorize

5. Re: Syntactic sugar

begin said...

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

new topic     » goto parent     » topic index » view message » categorize

6. Re: Syntactic sugar

So "≠" (U+2260) becomes # when you can not enter a enter a UTF character. 

in the old day, there was just '#'.

new topic     » goto parent     » topic index » view message » categorize

7. Re: Syntactic sugar

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

new topic     » goto parent     » topic index » view message » categorize

8. Re: Syntactic sugar

begin said...

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

new topic     » goto parent     » topic index » view message » categorize

9. Re: Syntactic sugar

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

new topic     » goto parent     » topic index » view message » categorize

10. Re: Syntactic sugar

begin said...

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.

new topic     » goto parent     » topic index » view message » categorize

11. Re: Syntactic sugar

thank for the hint, i try that. but in the end i think i stay with what the language offers.

richard

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu