1. load user defined module
- Posted by Salix <salix at freemail.hu> Nov 07, 2002
- 436 views
include get.e object z z=prompt_string("What to load? ") procedure inc(sequence x) include x end procedure inc(z) -- This doesn't work -- But how to get around it? -- Cheers, Salix
2. Re: load user defined module
- Posted by Sabal.Mike at notations.com Nov 07, 2002
- 412 views
Correct, this won't work because include must be a top level routine with a static filename. One oft-proposed solution is to open an include file, puts(fn,"include "&x&"\n"), close fn, then include the include file. It's not a very elegant solution, but it should do what you need it do. I've proposed before, and in light of current discussions will do so again now, that some sort of overlay mechanism is needed. I should be able to launch a variable Euphoria program from within a Euphoria program without executing a new shell or console. This, IMHO, would be a much more valuable addition than certain other features that I never use. Mike Sabal >>> salix at freemail.hu 11/07/02 10:13AM >>> include get.e object z z=prompt_string("What to load? ") procedure inc(sequence x) include x end procedure inc(z) -- This doesn't work -- But how to get around it? -- Cheers, Salix
3. Re: load user defined module
- Posted by stabmaster_ at hotmail.com Nov 07, 2002
- 446 views
Personally, I'd like to see something like this: ifplatform DOS32 -- DOS-specific code and includes goes here endif ifplatform LINUX -- and so on... ifplatform should be checked by Ex/Exw/Exu as a first pass, only reading code for the given platform (since the current platform is known by the interpreter at all times).
4. Re: load user defined module
- Posted by Derek Parnell <ddparnell at bigpond.com> Nov 07, 2002
- 394 views
To: Robert Craig Rob, how would you recommend that coders deal with this issue of platform-specific code, using the current incarnation of Euphoria? 8/11/2002 11:46:30 AM, stabmaster_ at hotmail.com wrote: > >Personally, I'd like to see something like this: > >ifplatform DOS32 >-- DOS-specific code and includes goes here >endif > >ifplatform LINUX >-- and so on... > > >ifplatform should be checked by Ex/Exw/Exu as a first pass, only reading >code for the given platform (since the current platform is known by the >interpreter at all times). > > > > --------- Cheers, Derek Parnell
5. Re: load user defined module
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 07, 2002
- 425 views
Derek Parnell writes: > Rob, how would you recommend that coders deal with > this issue of platform-specific code, using the > current incarnation of Euphoria? You can use platform() to determine which platform you are running on. platform() is fast. It's as if you had coded a constant, like 1, 2 or 3. No subroutine call is made. Euphoria does not have conditional compilation built into it, like C does. I'd like to keep it that way. Why add a new concept to the language, for such a small advantage? With conditional compilation, or a preprocessor of some kind, you could eliminate code that's only used on another platform, thereby saving a few K bytes. However it's extremely rare, and getting rarer each year, for a program to run out of memory because it contains too much code. It's almost always an excess amount of data that causes the problem. Over time, programs grow linearly (at most) in size, while memory is still growing exponentially, so I expect this to be even less of a problem in the future. If you really want to save a few K by stripping out code, you can develop your own simple preprocessor in an hour or so. I know from coding in C, that it's more readable if all your nested conditional statements are at the same linguistic level, using if-else, rather than having two levels, with static ifdef's and dynamic if's mixed together. Something I could do is optimize statements like: if platform()=LINUX then code-block-1 else code-block-2 end if so that no intermediate code is generated for code-block-2 when the platform is LINUX. I'd rather do that, than introduce conditional compilation. Also the code above, when translated with E to C, will produce C code like: if 3 = 3 then code-block-1 else code-block-2 end if where I know that Watcom (at least) will eliminate code-block-2 at compile-time. Keep in mind also, that the 2-pass binder and the translator will eliminate all unused routines. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
6. Re: load user defined module
- Posted by stabmaster_ at hotmail.com Nov 08, 2002
- 407 views
>Euphoria does not have conditional compilation built into it, >like C does. I'd like to keep it that way. Why add >a new concept to the language, for such a small advantage? I see it as a bit more than a "small" advantage. Since Euphoria is a multi-platform language, and hopefully will be ported to even more platforms in the future, conditional interpretation would imo be the most straightforward way to write programs that will run on all supported platforms. Sure, writing include-statements to a bogus file and then including it works. But it's not really intuitive, it kind of a trick that just so happens to work.
7. Re: load user defined module
- Posted by Derek Parnell <ddparnell at bigpond.com> Nov 08, 2002
- 399 views
Robert, is this the sort of thing you are suggesting for us ? ... include linux/ui.e as lui include win32/ui.e as wui include dos/ui.e as dui . . . function CreateWidget( object WidgetType, object Caption, ... ) object lResult if platform() = UNIX then lResult = lui:CreateWidget(WidgetType, Caption, ...) elsif platform() = WIN32 then lResult = wui:CreateWidget(WidgetType, Caption, ...) elsif platform() = MSDOS then lResult = dui:CreateWidget(WidgetType, Caption, ...) end if return lResult end function procedure PositionCaret( object Widget, object Left, object Top) if platform() = UNIX then lui:PositionCaret(Widget, Left, Top) elsif platform() = WIN32 then wui:PositionCaret(Widget, Left, Top) elsif platform() = MSDOS then dui:PositionCaret(Widget, Left, Top) end if end procedure procedure RenderText( object Widget, object Text) if platform() = UNIX then lui:RenderText(Widget, Text) elsif platform() = WIN32 then wui:RenderText(Widget, Text) elsif platform() = MSDOS then dui:RenderText(Widget, Text) end if end procedure procedure ProcessMessages( object Widget) if platform() = UNIX then lui:ProcessMessages( Widget ) elsif platform() = WIN32 then wui:ProcessMessages( Widget ) elsif platform() = MSDOS then dui:ProcessMessages( Widget ) end if end procedure object Window, Button, . . . if platform() = UNIX then Window = lui:Window Button = lui:Button . . . elsif platform() = WIN32 then Window = wui:Window Button = wui:Button . . . elsif platform() = MSDOS then Window = dui:Window Button = dui:Button . . . end if constant MainWindow = CreateWidget( Window, "My Window", ...), OkayBtn = CreateWidget( Button, "Okay", ...) PositionCaret(MainWindow, 20, 20) RenderText(MainWindow, "Hello, World!") ProcessMessages(MainWindow) ---------------- As you could imagine, it would not take much for this to become very hard to maintain. Can you suggest a better approach? Maybe something along the lines of ... if platform() = UNIX then include linux/ui.e if platform() = WIN32 then include win32/ui.e if platform() = MSDOS then include dos/ui.e end if constant MainWindow = CreateWidget( Window, "My Window", ...), OkayBtn = CreateWidget( Button, "Okay", ...) PositionCaret(MainWindow, 20, 20) RenderText(MainWindow, "Hello, World!") ProcessMessages(MainWindow) -------------- cheers, Derek Parnell ----- Original Message ----- From: "Robert Craig" <rds at RapidEuphoria.com> To: "EUforum" <EUforum at topica.com> Sent: Friday, November 08, 2002 3:46 PM Subject: Re: load user defined module > > Derek Parnell writes: > > Rob, how would you recommend that coders deal with > > this issue of platform-specific code, using the > > current incarnation of Euphoria? > > You can use platform() to determine which platform > you are running on. platform() is fast. It's as if you had > coded a constant, like 1, 2 or 3. No subroutine call is made. > > Euphoria does not have conditional compilation built into it, > like C does. I'd like to keep it that way. Why add > a new concept to the language, for such a small advantage? > > With conditional compilation, or a preprocessor of some kind, > you could eliminate code that's only used on another platform, > thereby saving a few K bytes. > > However it's extremely rare, and getting rarer each year, for > a program to run out of memory because it contains > too much code. It's almost always an excess amount of data that > causes the problem. Over time, programs grow linearly (at most) > in size, while memory is still growing exponentially, > so I expect this to be even less of a problem in the future. > > If you really want to save a few K by stripping out code, > you can develop your own simple preprocessor in > an hour or so. > > I know from coding in C, that it's more readable if all > your nested conditional statements are at the same linguistic level, > using if-else, rather than having two levels, with static ifdef's > and dynamic if's mixed together. > > Something I could do is optimize statements like: > if platform()=LINUX then > code-block-1 > else > code-block-2 > end if > so that no intermediate code is generated for code-block-2 > when the platform is LINUX. I'd rather do that, than introduce > conditional compilation. > > Also the code above, when translated with E to C, > will produce C code like: > > if 3 = 3 then > code-block-1 > else > code-block-2 > end if > > where I know that Watcom (at least) will eliminate > code-block-2 at compile-time. > > Keep in mind also, that the 2-pass binder and the translator > will eliminate all unused routines. > > Regards, > Rob Craig > Rapid Deployment Software > http://www.RapidEuphoria.com > > > >
8. Re: load user defined module
- Posted by Derek Parnell <ddparnell at bigpond.com> Nov 08, 2002
- 385 views
Ooops, I clicked send before I could add ... Now consider the possibility of a Palm OS version of Euphoria. Using the current platform() method, we now have a lot of work to do to port it. (Assuming that a palm/ui.e was already defined). Whereas the idea of an include being used inside an IF would be a trival exercise. ---------------- cheers, Derek Parnell
9. Re: load user defined module
- Posted by Igor Kachan <kinz at peterlink.ru> Nov 08, 2002
- 397 views
Hello stabmaster, Try please, is the code below too bad ? -- code global procedure prepare_libs(sequence name, sequence list_libs) integer fn fn=open(name, "wb") puts(fn, list_libs[platform()]) close(fn) end procedure sequence conditional_libs conditional_libs ={ -------------------dos "include c.e\n" & "include d.e\n" & "include e.e\n" , -------------------win "include b.e\n" & "include f.e\n" & "include g.e\n" , -------------------lin "include a.e\n" & "include h.e\n" & "include i.e\n" } prepare_libs("con_libs.e", conditional_libs) include con_libs.e -- end of code See please, you can make the *conditional* including without any if & elsif & else conditions. More complicated interpreter is more buggy interpreter. And just this current 'simple' interpreter is a great tool, I think. Regards, Igor Kachan kinz at peterlink.ru ---------- > ïÔ: stabmaster_ at hotmail.com > ëÏÍÕ: EUforum <EUforum at topica.com> > ôÅÍÁ: Re: load user defined module > äÁÔÁ: 8 ÎÏÑÂÒÑ 2002 Ç. 15:48 > > >Euphoria does not have conditional compilation built into it, > >like C does. I'd like to keep it that way. Why add > >a new concept to the language, for such a small advantage? > > I see it as a bit more than a "small" advantage. Since Euphoria is a > multi-platform language, and hopefully will be ported to even more platforms > in the future, conditional interpretation would imo be the most > straightforward way to write programs that will run on all supported > platforms. Sure, writing include-statements to a bogus file and then > including it works. But it's not really intuitive, it kind of a trick that > just so happens to work.
10. Re: load user defined module
- Posted by petelomax at blueyonder.co.uk Nov 08, 2002
- 391 views
{{{ On Sat, 9 Nov 2002 00:26:38 +1100, Derek Parnell <ddparnell at bigpond.com> wrote:
Robert, <that's my middle name>
is this the sort of thing you are suggesting for us ? ...
include linux/ui.e as lui
include win32/ui.e as wui
include dos/ui.e as dui
.
.
function CreateWidget( object WidgetType, object Caption, ... )
object lResult
if platform() = UNIX then
lResult = lui:CreateWidget(WidgetType, Caption, ...)
elsif platform() = WIN32 then
lResult = wui:CreateWidget(WidgetType, Caption, ...) .... <snip> Is there any problem launching the app from stub files:
include linux/ui.e as lui
include win32/ui.e as wui
include dos/ui.e as dui
.
.
function CreateWidget( object WidgetType, object Caption, ... )
object lResult
if platform() = UNIX then
lResult = lui:CreateWidget(WidgetType, Caption, ...)
elsif platform() = WIN32 then
lResult = wui:CreateWidget(WidgetType, Caption, ...) .... <snip> Is there any problem launching the app from stub files:
app.ex: include dos/ui.e include main.e
app.exw: include win32/ui.e include main.e
app.exu: include linux/ui.e include main.e
Providing the three variants of ui.e have a consistent api which you are suggesting then main.e need only contain platform independent code & no calls to platform() either.
I think it would be a mistake to actually include say win32lib.ew when running on say linux where it is never going to get called.
Pete
11. Re: load user defined module
- Posted by stabmaster_ at hotmail.com Nov 08, 2002
- 395 views
>More complicated interpreter is more buggy interpreter. >And just this current 'simple' interpreter is a great tool, >I think. > >Regards, >Igor Kachan >kinz at peterlink.ru > I wouldn't exactly regard a preprocessor that looks for "ifplatform" statements and discards code that is written for other platforms as complicated. I'm perfectly aware that the method you used in your example code works, i've done the same thing myself. It's just that i think conditional interpretation would be a more elegant and straightforward way of doing the same thing.
12. Re: load user defined module
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 08, 2002
- 389 views
Derek Parnell writes: > Robert, > is this the sort of thing you are suggesting for us ? ... > ... > ... > As you could imagine, it would not take much for this to > become very hard to maintain. Can you suggest a better approach? I don't know. There are various approaches that you could take. Igor's dynamic include approach is one, although it won't work with the binder or translator. A lot depends on the specific situation - how much code is in common across platforms, can the differences be expressed as different data rather than different code, etc. You might even use 3 different sequences of routine id's for 3 platforms. I'm sure you can come up with as good a solution as I might. The conditional compilation approach can get ugly too. If you look at the C source for Euphoria, you'll see sections of very ugly code because of all the conditional compilation directives for different platforms. I do it because people demand maximum speed and minimum interpreter size. I'd need to see some real cross-platform examples to get interested in adding conditional compilation. I just haven't seen many. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
13. Re: load user defined module
- Posted by Kat <kat at kogeijin.com> Nov 08, 2002
- 392 views
On 8 Nov 2002, at 21:50, Robert Craig wrote: > > Derek Parnell writes: > > Robert, > > is this the sort of thing you are suggesting for us ? ... > > ... > > ... > > As you could imagine, it would not take much for this to > > become very hard to maintain. Can you suggest a better approach? > > I don't know. There are various approaches that you could take. > Igor's dynamic include approach is one, although it won't > work with the binder or translator. > A lot depends on the specific situation - how much code is in > common across platforms, can the differences be expressed as > different data rather than different code, etc. You might even > use 3 different sequences of routine id's for 3 platforms. > I'm sure you can come up with as good a solution as I might. > The conditional compilation approach can get ugly too. > If you look at the C source for Euphoria, you'll see sections of > very ugly code because of all the conditional compilation > directives for different platforms. I do it because people > demand maximum speed and minimum interpreter size. > I'd need to see some real cross-platform examples > to get interested in adding conditional compilation. > I just haven't seen many. Too bad i can't run my windows code on the FreeBSD shell, or i'd be able to show you some. The only reason i don't have a cheapie PDA is because i can't program it in Eu or mirc, altho Dialect will program a WinCE and it's free with free source too.... someone must have shown them a use for it,, oh wait, Aristar has their own reason, they make $$$$$ with their medical stuff, including the PDAs the doctors carry. Kat, meow.
14. Re: load user defined module
- Posted by Juergen Luethje <jluethje at gmx.de> Nov 09, 2002
- 419 views
Rob wrote: <snip> > I'd need to see some real cross-platform examples > to get interested in adding conditional compilation. > I just haven't seen many. Sorry, I don't understand. What do you mean with "real cross-platform examples"? TIA and regards, Juergen -- while not asleep do sheep += 1 end while
15. Re: load user defined module
- Posted by Igor Kachan <kinz at peterlink.ru> Nov 09, 2002
- 417 views
Hello Robert, ---------- > Îò: Robert Craig <rds at RapidEuphoria.com> > Êîìó: EUforum <EUforum at topica.com> > Òåìà: Re: load user defined module > Äàòà: 9 íîÿáðÿ 2002 ã. 5:50 > > Derek Parnell writes: > > Robert, > > is this the sort of thing you are suggesting for us ? ... > > ... > > ... > > As you could imagine, it would not take much for this to > > become very hard to maintain. Can you suggest a better approach? > > I don't know. There are various approaches that > you could take. > Igor's dynamic include approach is one, although > it won't work with the binder or translator. It works with binder and translator for me Just delete old con_libs.e from the current directory then run code with ex.exe interpreter. You'll have new con_libs.e for the DOS platform in the current directory. Then run bind code. You'll have .exe for DOS with that new con_libs.e included. bind.bat must run ex.exe, not exw.exe. Then run ec with code, then run emake.bat and you'll have compiled .exe for DOS. Then delete con_libs.e for DOS from the current directory and run code with exw.exe interpreter. You'll have new con_libs.e for the WIN platform in the current directory. Then run bindw code. You'll have .exe for WIN with that new con_libs.e included. bindw.bat must run exw.exe as it runs. Then run ecw with code, then run emake.bat and you'll have compiled .exe for WIN. So, the trick is to DELETE the bad con_libs.e and CREATE new good one with needed interpreter before binding or translation for the needed platform. <snip> Regards, Igor Kachan kinz at peterlink.ru
16. Re: load user defined module
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 09, 2002
- 401 views
Juergen writes: > Sorry, I don't understand. What do you mean with > "real cross-platform examples"? There are lots of Euphoria programs and libraries that run on multiple platforms. e.g. ed.ex, sort() etc. Sometimes there's a need to use platform() to select different statements for different platforms, e.g if platform() = LINUX then system("rm temp", 2) else system("del temp", 2) end if In the examples that I've seen so far, the platform-dependent sections are usually fairly small, and only form a small percentage of the code. I suppose what I meant by the fuzzy term "real cross-platform example", was a large program or library with many big chunks of code that are different on the different platforms. You might imagine something like a combined Windows/Linux version of Win32Lib, except that the differences in that case would be so great that you'd be better off maintaining two completely separate win32lib.ew files, rather than using platform() all over the place. There are probably some better examples, where it would make sense to maintain one source with heavy use of platform(), but I was just saying that I haven't seen those examples yet, so I don't see an urgent need for better support in this area, such as C-style conditional compilation. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com