1. ifdef commands
- Posted by kinz Dec 03, 2008
- 1109 views
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
2. Re: ifdef commands
- Posted by jeremy (admin) Dec 04, 2008
- 1167 views
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
3. Re: ifdef commands
- Posted by euphoric (admin) Dec 04, 2008
- 1132 views
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.
4. Re: ifdef commands
- Posted by Spock Dec 07, 2008
- 1092 views
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 undefines
without define OTHER_WORD
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.
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
5. Re: ifdef commands
- Posted by mattlewis (admin) Dec 07, 2008
- 1115 views
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
6. Re: ifdef commands
- Posted by DanM Dec 09, 2008
- 1070 views
- Last edited Dec 10, 2008
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
7. Re: ifdef commands
- Posted by anon Dec 10, 2008
- 1045 views
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!
8. Re: ifdef commands
- Posted by jimcbrown (admin) Dec 10, 2008
- 1058 views
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.
9. Re: ifdef commands
- Posted by anon Dec 10, 2008
- 1042 views
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?
10. Re: ifdef commands
- Posted by jimcbrown (admin) Dec 10, 2008
- 1047 views
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
11. Re: ifdef commands
- Posted by anon Dec 10, 2008
- 1041 views
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?
12. Re: ifdef commands
- Posted by jimcbrown (admin) Dec 10, 2008
- 1035 views
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.
13. Re: ifdef commands
- Posted by mattlewis (admin) Dec 10, 2008
- 1060 views
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