Re: Discard
- Posted by Hawke <mdeland at NWINFO.NET> Sep 23, 1998
- 503 views
Tom ©upka wrote: >The "if" substitute hasn't this side-effect; on the >other hand it is time-consuming - it tests the return >value every time >(Can I discard sequences this way?!). no. 'if..then' can only handle atoms. to discard a sequence you have to do something like: -------------------code that prolly won't work :-> include blahblah.e object junk,Config procedure discard(object a) end procedure function InitGraphics(atom mode) object VC,success if mode=0 then success = select_mode(mode) else success=graphics_mode(mode) end if VC=video_config() return {success,VC[VC_XPIXELS],VC[VC_YPIXELS]} end function --usage #1, i wanna keep the values Config = InitGraphics(18) --usage #2, just set the best mode. if discard(InitGraphics(0)) then end if --alternate usage#2, just set the best mode junk =InitGraphics(0) ------------------------------------------ here's the crux of the dilemma: in usage #2a,2b we don't even want the "return {success,...}" line executed at all, *whatsoever*, as if it was a remark. >so I should very appreciate if Euphoria allows function >call as a statement: > my_func() --my example:InitGraphics(0) >The implementation could be simple - the interpreter knows >that my_func is function so it simply discards the return value. well, there is more to it than that, as seen above. this proposal *won't* get the benefit we wish. to do that, the return value must not even be calculated. also, i think it begins to impair readability and clarity. however!, if the interpreter was to see this my_func() or InitGraphics(0) on a line by itself, and then remarked out the "return" line before tokenizing the guts of the function and executing the guts of the function... then, we would have something. still not sure it would be the 'best' way as far as clarity, and it's looking awful "C'ish" this way... i'd almost *prefer* the verbosity... hrmmmm.... neigh, i *would prefer* the verbosity of: discard=InitGraphics(0) IF!!! the interpreter did as suggested above (remarking the return) because it let's others *KNOW* you're throwing it away. if 'discard' is too verbose, then let's use 'junk'... 2 less wittle letters to type, for those worried about such things... [heh, i clock in at 60-90 WPM, so (it != bothers_me)] take care all --Hawke'