Talk:Modulinos: Difference between revisions

Line 91:
 
==What ''is'' an "Execuatable library"==
''(This section needs expansion and discussion to see if we have enough to create a task that is capable of being completed by enough languages.)'' --[[User:Paddy3118|Paddy3118]] 07:45, 7 March 2011 (UTC)<br><br>
 
When given a task in a programming 'contest' such as to create a simple function and to find values of that function at certain points; then you would be giving your example in the form of an executable library if:
 
'''For an interpreted language:'''
* When the interpreter is called on the source file, the result is the generation of all the values needed for the 'contest'. Although a command-line argument specifying that the library is being directly executed is permitted, an executable library must be able to contain all the code to produce the values for the competition.
* When another source file includes the library source file as a library/module resource, the simple function can then be called, but the code in the library file for producing results specific to the competition, should ''not'' be automatically called at all.
 
'''For a compiled language:'''<br>
The equivalent would be an executable shared object file (Unix) or executable DLL (Windows).
* When the .so or DLL is called/run/clicked on, the result is the generation of all the values needed for the 'contest'.
* Another executable must be able to access the same .so/DLL file as a resource from which the simple function can then be called, but the code in the .so/DLL file for producing results specific to the competition, should ''not'' be automatically called at all.
 
====Examples====
An example would be the [[Hailstone sequence#Python|Python]] entry for [[Hailstone sequence]].
 
:<lang python>def hailstone(n):
seq = [n]
while n>1:
n = 3*n + 1 if n & 1 else n//2
seq.append(n)
return seq
 
if __name__ == '__main__':
h = hailstone(27)
assert len(h)==112 and h[:4]==[27, 82, 41, 124] and h[-4:]==[8, 4, 2, 1]
print("Maximum length %i was found for hailstone(%i) for numbers <100,000" %
max((len(hailstone(i)), i) for i in range(1,100000)))</lang>
 
In the case of the Python language the interpreter maintains a module level variable called __name__. If a file hailstone.py is ''imported'' (as <code>import hailstone</code>), then the __name__ variable is set to the import name of 'hailstone' and the <code>if __name__ == '__main__'</code> expression would then be false, and only the hailstone function is available to the importer.
 
If the same file hailstone.py is ''run'', (as maybe <code>python hailstone.py</code>; or maybe double-clicking the hailstone.py file), then the __name__ variable is set to the special name of '__main__' and the <code>if __name__ == '__main__'</code> expression would then be true causing its block of code to be executed.
 
--[[User:Paddy3118|Paddy3118]] 07:45, 7 March 2011 (UTC)
Anonymous user