Euphoria Ticket #283: start a for loop inside an ifdef elsedef get an error

this may be dissallowed, not sure

 
  ifdef SC4 then 
	for i = 1 to 2 do 
  elsedef 
	for i = 1 to 3 do 
  end ifdef   
  
 ?i 
 end for 

<0138>:: Syntax error - expected to see 'for' after 'end', not 'ifdef' 
  end ifdef   
            ^ 
 

Details

Type: Feature Request Severity: Normal Category: Interpreter
Assigned To: unknown Status: Won't Fix Reported Release: 3680
Fixed in SVN #: View VCS: none Milestone: 4.1.0

1. Comment by jimcbrown Oct 31, 2010

The other day, mattlewis was discussing a desire to be able to do this

integer x = ifdef SOME then y elsedef z end ifdef 

But, this does not work right not because ifdef's are handled by parser.e not scanner.e (that is, they're handled by the parser, not the file and line scanner).

I think that for the current implementation, the behavior is correct. The parser doesn't normally allow one to mess up on the order between <flow-control> .. end <flow-control> types, and ifdef (right now) is no exception.

You can make a very good argument that ifdef should be an exception. But the right way to handle this is probably to redo all the ifdef support in scanner.e, which might turn out to be a fairly big job.

I think the current behavior is correct (in a "well, technically, it's correct" sense), so I've turned this ticket into a feature request slated for 4.1.0 (making ifdef more flexible won't break backwards compatibility with 4.0.0)

2. Comment by DerekParnell Oct 31, 2010

I feel that the current implementation is the better way to do it. The ifdef IMO should work at the AST level rather than at the textual level. This basically means that stuff in-between an ifdef and elsedef/end ifdef should be complete statements.

The experience with C/C++ macros has demonstrated how code can be made difficult to read when if defined() is used to create partial statements. It's convenience factor gets lost when code becomes costly to maintain.

The D language has not followed C in this respect for that reason.

Code legibility should be a primary driver for us, if things need to be spelled out we should be doing that. It might make initial coding a bit longer but in the long run the maintenance will be easier. Remember code gets read a whole lot more than written.

3. Comment by SDPringle Nov 02, 2010

I think we debated this kind of thing before. In general, balancing an 'ifdef' with its 'end ifdef' is bad style in my opinion. What is the intention of this ticket, is it such that this should be disallowed or is it that it should be allowed? Look at this code here:

ifdef SC4 then 
   if sc_flag then 
end ifdef 
           proc() 
ifdef SC4 then 
   end if 
end ifdef 

I argued that this was bad style because the ifdef is not balanced by an 'end ifdef' in the same level of nesting as with if. You can never format code properly when you do this kind of thing.

4. Comment by DerekParnell Nov 02, 2010

I want the current semantics to remain, though the message could be a little more clear about what the problem is.

5. Comment by ne1uno Nov 02, 2010

I am not advocating that the for loop, or any other loop start should be allowed. would probably use it in a pinch if it worked, as that is how I discovered the problem. if it was valid, probably people would use it. so it can be allowed or not, I really have no opinion.

it just seems like it is a bug because anyone who knows C for example, would assume like the C preprocessor all the ifdef are resolved first. and in that case it is a bug. the docs describe the ifdef blocks as not being part of your code at all if the word is not defined. so where is the not expecting elsedef comming from?

I understand current implementation makes this error reasonable. sure there are many other un euphoric ways to trigger a similar bug so this is going to be a sticky ticket.

6. Comment by jeremy Jan 01, 2011

What is the status of this? Is it valid? I think the coding style in the ticket description is bad. Starting a block but not finishing it inside of a block indent structure (granted, one removed before IL or conversion). The code in question could do:

ifdef SC4 then 
    integer max = 2 
elsedef 
    integer max = 3 
end ifdef 
 
for i = 1 to max do 

7. Comment by jimcbrown Jan 01, 2011

Well, it's turned into a feature request to enable using ifdef as part of a statement (instead of surrounding multiple statements).

ne1uno said it's not a big deal if we turn this down, but I don't think we have a system for declining to perform feature requests or a standard to mark them as invalid.

Search



Quick Links

User menu

Not signed in.

Misc Menu