1. ifdef commands

Dear EU users,

We have now very useful top level commands which act before main compilation - ifdef, elsifdef etc.

But these good commands look something ugly among other short and elegant classical EU keywords.

What about IF, ELSE, ELSIF, THEN, END IF for these and, maybe, other *new* commands introduced just for top level?

Top level -> upper key words, why not?

I can imagine much more useful EU top level commands than just "IF" series.

Regards, Igor Kachan kinz@peterlink.ru

new topic     » topic index » view message » categorize

2. Re: ifdef commands

Any thoughts on this? I never did like the ifdef, elseifdef words but failed to come up with a better solution. Is this it?

Jeremy

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

3. Re: ifdef commands

jeremy said...

Any thoughts on this? I never did like the ifdef, elseifdef words but failed to come up with a better solution. Is this it?

ifdef means "if defined," right? that seems plain and simple and right. it's not like you'll have tons of those all over your code, eh?

i don't think an allcaps solution is the best solution, but i don't care if we adopt it. allcaps or ifdef is the same to me.

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

4. Re: ifdef commands

I am interested to know more about the "ifdef" construct. The manual says:

The ifdef statement is unlike all of the other statements in that it is executed at parse time not runtime. This allows you to change the way your program operates in a very efficient manner. Since the ifdef statement works at parse time, runtime values cannot be checked, instead special definitions can be set or unset at parse time as well. Euphoria defines some common words itself:

EU400 - Version of Euphoria
DOS32 - Platform is DOS
WIN32 - Platform is Windows
LINUX - Platform is Linux
FREEBSD - Platform is FreeBSD
OSX - Platform is Mac OS X
UNIX - Platform is any Unix (currently Linux, FreeBSD or OS X)
SAFE - The interpreter is version 4.0 or later.

Further, you can define your own words either in source:

with define MY_WORD defines
without define OTHER_WORD
undefines

or by command line:

exwc -D MY_WORD myprog.ex
...

The tags being used may contain characters that are not legal in Euphoria identifiers, like accented characters. Avoid using spaces or any whitespace though.

The ifdef statement is very efficient in that it makes the decision only once during parse time and only emits the TRUE portions of code to the resulting interpreter. Thus, in loops that are iterated many times there is zero performance hit when making the decision.

Do the defined words or "tags" have any value associated with them?

Can they be used in places outside the construct?

Can normal constants or values be used inside the construct?

What are the scope of tags?

regards, Spock

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

5. Re: ifdef commands

Spock said...

I am interested to know more about the "ifdef" construct. The manual says:

[snip]

Do the defined words or "tags" have any value associated with them?

Can they be used in places outside the construct?

Can normal constants or values be used inside the construct?

What are the scope of tags?

The only 'value' they have is whether they are defined or not. The preprocessor is not as powerful as C's. The only other place that they can be used is with/without define directives.

Matt

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

6. Re: ifdef commands

euphoric said...
jeremy said...

Any thoughts on this? I never did like the ifdef, elseifdef words but failed to come up with a better solution. Is this it?

ifdef means "if defined," right? that seems plain and simple and right. it's not like you'll have tons of those all over your code, eh?

i don't think an allcaps solution is the best solution, but i don't care if we adopt it. allcaps or ifdef is the same to me.

Since its both a new word and a new concept for Euphoria, maybe simply "ifdefined", as it does speak more clearly to its meaning. Of course, authorship and repeated usage would make "ifdef" clear to anyone, but as a new word, it's not as automatically clear as "ifdefined" would be, & maybe you could still allow alias of "ifdef" for quicker typing.

Dan

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

7. Re: ifdef commands

Spock said...

The manual says:


The ifdef statement is very efficient in that it makes the decision only once during parse time and only emits the TRUE portions of code to the resulting interpreter. Thus, in loops that are iterated many times there is zero performance hit when making the decision.

So does that mean that:

constant DEBUG=0 if DEBUG then printf(1,"...) end if

is not handled properly/is handled in just about the most ineffcient way it possibly coule be? If so, the ifdef construct is a nasty wart which should be removed and the desired handling implemented properly!

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

8. Re: ifdef commands

anon said...
Spock said...

The manual says:


The ifdef statement is very efficient in that

So does that mean that:

constant DEBUG=0 if DEBUG then printf(1,"...) end if

is not handled properly/is handled in just about the most ineffcient way it possibly coule be? If so, the ifdef construct is a nasty wart which should be removed and the desired handling implemented properly!

I see nothing with regards to ifdef in your example. Your example is about if statements, not ifdef statements. A non sequitor? I do not entirely follow.

As a side note, both the interpreter and the translator effectively optimize the above if statement into a nop at parse time.

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

9. Re: ifdef commands

The manual says:

The ifdef statement is very efficient in that it makes the decision only once during parse time and only emits the TRUE portions of code to the resulting interpreter. Thus, in loops that are iterated many times there is zero performance hit when making the decision.

What I meant to say is why introduce ifdef to do that, why not just make the if statement do that?

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

10. Re: ifdef commands

anon said...

The manual says:

The ifdef statement is very efficient in that it makes the decision only once during parse time and only emits the TRUE portions of code to the resulting interpreter. Thus, in loops that are iterated many times there is zero performance hit when making the decision.

What I meant to say is why introduce ifdef to do that, why not just make the if statement do that?

A common request was to allow

if platform() = LINUX then 
	include linux.e 
else 
	include doswindows.e 
end if 

The way to do this now is

ifdef LINUX then 
	include linux.e 
elsedef 
	include doswindows.e 
end ifdef 

ifdef has more unconventional uses, such as:

ifdef ABORTWITHCRASH then 
	!#$##@ some garbage here to halt the program 
end ifdef 
new topic     » goto parent     » topic index » view message » categorize

11. Re: ifdef commands

jimcbrown said...

As a side note, both the interpreter and the translator effectively optimize the above if statement into a nop at parse time.

Now I am confused. What is the point of ifdef then?

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

12. Re: ifdef commands

anon said...
jimcbrown said...

As a side note, both the interpreter and the translator effectively optimize the above if statement into a nop at parse time.

Now I am confused. What is the point of ifdef then?

I've already answered this.

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

13. Re: ifdef commands

anon said...
jimcbrown said...

As a side note, both the interpreter and the translator effectively optimize the above if statement into a nop at parse time.

Now I am confused. What is the point of ifdef then?

Here it is: All the action of ifdef happens at parse time, not run time. Regular if statements happen at run time (with some caveats for some optimizations). The ifdef block does not move from "top level" code to "not top level" code, so statements such as constant declarations and includes are still legal.

Please refer to this statement (or any other statement) if you have any further questions. I thought that Jim had answered your question as well, so there's not much more we can do except for rephrasing the answer again without a more specific question.

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu