Julia equivalent of Fortran common blocks or, even better, Fortran 90 Modules

321 views
Skip to first unread message

salg...@gmail.com

unread,
Oct 20, 2013, 10:00:17 PM10/20/13
to julia...@googlegroups.com


Hello, everyone:

I just found Julia yesterday, it looks really interesting. I am a Fortran (number crunching)/Python (gui) kind of guy...could Julia be the sole solution to replace both? (for the most part?).

Anyway...

One thing I read that I thought sounded odd was something about modules and variables being read-only; so, question: how do I achieve in Julia what I do with Fortran90 modules?  In Fortran, I can say "use mymodule" and all the variables in the module are available for read/write in the current scope and all the functions in the module are also available.

Any pointers or usage example much appreciated. 

Germán 

Matthias Bussonnier

unread,
Oct 21, 2013, 2:32:13 AM10/21/13
to julia...@googlegroups.com, julia...@googlegroups.com
Looking at module documentation for current dev:


I think you are referring to 

Using <modulename>

(Which python equivalent would be:
from <modulename> import * )
-- 
M

Envoyé de mon iPhone

salg...@gmail.com

unread,
Oct 21, 2013, 8:15:40 PM10/21/13
to julia...@googlegroups.com
Yes, that is the section I am referring to, in particular paragraph:
Once a variable is imported this way (or, equivalently, with the import keyword), a module may not create its own variable with the same name. Imported variables are read-only; assigning to a global variable always affects a variable owned by the current module, or else raises an error.
In Fortran, I can have two or more separate files/subroutines and for as long as all "use mymodule", they all can read and write to its variables and so communicate with each other that way....the text above from the Julia docs says that imported variable are read only...so, either I am missing something or this is simply not a replacement to Fortran's modules...and, maybe, simply, one needs to always keep passing around a pointer to the data as argument to every function interested in manipulating it.

?

Germán 



Kevin Squire

unread,
Oct 21, 2013, 8:34:53 PM10/21/13
to julia...@googlegroups.com
Hello Germán,

modules...and, maybe, simply, one needs to always keep passing around a pointer to the data as argument to every function interested in manipulating it.

In many languages, including Julia, this is considered good practice.

Kevin

salg...@gmail.com

unread,
Oct 21, 2013, 8:42:01 PM10/21/13
to julia...@googlegroups.com
O.k., got it.
 
thanks,

Germán
Reply all
Reply to author
Forward
0 new messages