1. Procedure main
- Posted by irv Aug 19, 2022
- 740 views
Dropped by https://github.com/OpenEuphoria/euphoria.
Example programs seem to be written by someone who doesn't use Euphoria. Every example encapsulates the main body of the program as a procedure, and then calls it. Trying to make Euphoria look like Python?
include std/io.e procedure main() puts( STDOUT, "Hello, world!\n" ) end procedure main()
2. Re: Procedure main
- Posted by jmduro Aug 19, 2022
- 713 views
Not only Python: C and many other languages do so. It is a clean way to identify where the program starts for beginners.
I like to start some of my programs this way:
procedure main(sequence cmd) end procedure main(command_line()) -- maybe_any_key() //for windows console programs
Jean-Marc
3. Re: Procedure main
- Posted by jmduro Aug 19, 2022
- 700 views
I'll take a short example. I have written to files:
First one: my_string.ex
public sequence my_string public function create_string(integer len) return repeat(' ', len) end function -- initialise my_string my_string = create_string(10)
It ends with some function calls. Is it the main file ?
Second one: where_to_begin.ex
include my_string.ex puts(1, append_string("I am Irv's greatest fan.") & "\n") function append_string(sequence s) return my_string & s end function
It ends with a function: is is a library ?
You and I know the answers but how can a beginner understand easily where to start?
eui where_to_begin.ex I am Irv's greatest fan.
Jean-Marc
4. Re: Procedure main
- Posted by petelomax Aug 19, 2022
- 695 views
In several of my commonly used programs (eg filedump.exw, hd.exw) it is often the case I want to change some load statement every 20th or 30th time I run it, eg
-- load_file(`E:\downloads\misc\arm\FASMARM_win32\helloworld`) -- load_file(`E:\downloads\misc\arm\FASMARM_win32\formatNum`) -- load_file(`E:\downloads\misc\arm\FASMARM_win32\binarydigit`) -- load_file(`E:\downloads\misc\arm\FASMARM_win32\System_time`) load_file(`E:\downloads\misc\arm\FASMARM_win32\cmdln`)
In my editor, Ctrl Q lists the routines, so that's much easier to get to if it's in a main().
In fact, as I'm currently playing with ELF files, and having ELF in the filter for Ctrl Q lists all
the routines I'm currently working on, I've renamed main() as mainELF(), so that it appears too.
5. Re: Procedure main
- Posted by ghaberek (admin) Aug 19, 2022
- 702 views
Dropped by https://github.com/OpenEuphoria/euphoria.
Example programs seem to be written by someone who doesn't use Euphoria. Every example encapsulates the main body of the program as a procedure, and then calls it.
Well they were written by me... do you consider me a Euphoria user? You're telling me you don't do this? Is this not common? It seems intuitive to me. Suggestions and changes are welcome at any time.
Trying to make Euphoria look like Python?
I guess when you write code in ten different languages and most of them require a main function, you end up carrying your habits around between languages. But I definitely didn't get this habit from Python.
-Greg
6. Re: Procedure main
- Posted by euphoric (admin) Aug 19, 2022
- 702 views
Every example encapsulates the main body of the program as a procedure, and then calls it.
Is this not common?
I use this pattern for all my apps.