2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,9 +1,12 @@
;Task:
Write a program that does the following in this order:
* Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
* [[Hello world/Text|Print]] "Sleeping..."
* Sleep the main [[thread]] for the given amount of time.
* Print "Awake!"
* End.
<br>
;Cf.:
* [[Nautical bell]]
;Related task:
* &nbsp; [[Nautical bell]]
<br><br>

View file

@ -0,0 +1,9 @@
10 POKE 768,169: POKE 770,76
20 POKE 771,168: POKE 772,252
30 INPUT "ENTER WAIT VALUE (1-256) : ";A
40 IF A < 1 OR A > 256 THEN 30
50 POKE 769,(A < 256) * A
60 LET C = (26 + 27 * A + 5 * A ^ 2) / 2
70 PRINT "WAIT FOR "C" CYCLES OR "
80 PRINT C * 14 / 14.318181" MICROSECONDS"
90 PRINT "SLEEPING": CALL 768: PRINT "AWAKE"

View file

@ -0,0 +1,8 @@
sleep = fn seconds ->
IO.puts "Sleeping..."
:timer.sleep(1000 * seconds) # in milliseconds
IO.puts "Awake!"
end
sec = if System.argv==[], do: 1, else: hd(System.argv) |> String.to_integer
sleep.(sec)

View file

@ -1,13 +1,6 @@
function sleep (s)
local t0 = os.time()
repeat until os.time() - t0 >= s
end
local seconds
repeat -- Keep asking until input is a valid number
io.write("Enter number of seconds to sleep: ")
seconds = tonumber(io.read())
until seconds ~= nil
print("Sleeping...")
sleep(seconds)
require("socket")
io.write("Input a number of seconds to sleep: ")
local input = io.read("*number")
print("Sleeping")
socket.sleep(input)
print("Awake!")

View file

@ -1,7 +1,7 @@
/*REXX program sleeps X seconds (the # of seconds supplied by the arg.*/
parse arg secs . /*get a (possible) argument. */
secs=word(secs 0,1) /*if not present, assume 0 (zero)*/
say 'Sleeping' secs "seconds." /*tell 'em what's happening. */
call delay secs /*snooze. Hopefully, a short nap*/
say 'Awake!' /*and tell 'em we're running. */
/*stick a fork in it, we're done.*/
/*REXX program sleeps X seconds (the number of seconds is supplied via the argument).*/
parse arg secs . /*obtain optional argument from the CL.*/
if secs=='' | secs=="," then secs=0 /*Not specified? Then assume 0 (zero).*/
say 'Sleeping' secs "seconds." /*inform the invoker what's happening. */
call delay secs /*Snooze. Hopefully, just a short nap.*/
say 'Awake!' /*and now inform invoker we're running.*/
/*stick a fork in it, we're all done. */

View file

@ -1,54 +1,53 @@
/*REXX program delays (or SLEEPS) a number of whole seconds. */
trace off /*suppress REXX error msgs.*/
parse arg ! /*obtain all the arguments.*/
if !all(arg()) then exit /*documentation requested? */
if !cms then address '' /*if CMS, use fast cmd path*/
signal on halt /*handle HALT gracefully.*/
signal on noValue /*handle REXX noValue error*/
signal on syntax /*handle REXX syntax errors*/
/*REXX program delays (or SLEEPS) a number of whole seconds; fractional secs are ignored*/
trace off /*suppress REXX error messages. */
parse arg ! /*obtain all the arguments. */
if !all(arg()) then exit /*documentation requested ? */
if !cms then address '' /*if CMS, then use fast cmd path.*/
signal on halt /*handle HALT gracefully. */
signal on noValue /*handle the REXX noValue error. */
signal on syntax /*handle the REXX syntax errors. */
/*┌────────────────────────────────────────────────────────────────────┐
The DELAY function is used to delay (wait) a specific amount of
(wall-clock) time specified in seconds. Any fraction part is ignored.
If the REXX program invoking DELAY function is running under PC/REXX
or Personal REXX, this REXX program should never be invoked as those
REXXes have their own built-in function (BIF) named "DELAY".
*/
/*┌────────────────────────────────────────────────────────────────────┐
The DELAY function is used to delay (wait) a specific amount of
(wall-clock) time specified in seconds. Any fraction part is ignored.
If the REXX program invoking DELAY function is running under PC/REXX
or Personal REXX, this REXX program should never be invoked as those
REXXes have their own built-in function (BIF) named "DELAY".
*/
@cpsleep = 'CP SLEEP' /*point to (CP) SLEEP cmd*/
@ping = 'PING' /*point to the DOS PING cmd*/
@cpsleep = 'CP SLEEP' /*point to the (CP) SLEEP command*/
@ping = 'PING' /* " " " DOS PING " */
parse var ! n _ /*parse argument from parms*/
if _\=='' | arg()>1 then call er 59 /*are there too many args? */
if n=='' then n=1 /*no arg? Then assume 1 sec*/
if \isNum(n) then call er 53,n 'delay-seconds' /*is n numeric? */
n=n%1 /*elide any fractional part*/
parse var ! n _ /*parse argument from the parms. */
if _\=='' | arg()>1 then call er 59 /*are there too many arguments ? */
if n=='' then n=1 /*No args? Then assume 1 second*/
if \isNum(n) then call er 53,n 'delay-seconds' /*is n not numeric? Error. */
n=n%1 /*elide any fractional second. */
if n<=0 then return 0
/* ┌────────────────────┐ */
/* │ delay n seconds. │ */
/* └────────────────────┘ */
select
when !cms then @cpsleep n%1 "SEC" /*CMS? Use CP SLEEP*/
when !tso then call sleep n%1 /*TSO? Use SLEEP*/
when !regina then call sleep n%1 /*Regina? Use SLEEP*/
when !dos then @ping '-n' n "127.0.0.1 > NUL" /*DOS? use PING */
when !cms then @cpsleep n%1 "SEC" /*is this CMS? Then use CP SLEEP*/
when !tso then call sleep n%1 /* " " TSO? " " SLEEP */
when !regina then call sleep n%1 /* " " Regina? " " " */
when !dos then @ping '-n' n "127.0.0.1 > NUL" /* " " DOS? " " PING */
otherwise nop
end /*select*/
return 0 /*return a zero value. */
/*═════════════════════════════general 1-line subroutines═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/
!all: !!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1
!cal: if symbol('!CALL')\=="VAR" then !call=; return !call
!env: !env='ENVIRONMENT'; if !sys=='MSDOS' | !brexx | !r4 | !roo then !env='SYSTEM'; if !os2 then !env='OS2'!env; !ebcdic=1=='f0'x; if !crx then !env='DOS'; return
!fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .; call !sys; if !dos then do; _=lastpos('\',!fn); !fm=left(!fn,_); !fn=substr(!fn,_+1); parse var !fn !fn '.' !ft; end; return word(0 !fn !ft !fm, 1+('0'arg(1)))
!rex: parse upper version !ver !vernum !verdate .; !brexx='BY'==!vernum; !kexx='KEXX'==!ver; !pcrexx='REXX/PERSONAL'==!ver | 'REXX/PC'==!ver; !r4='REXX-R4'==!ver; !regina='REXX-REGINA'==left(!ver,11); !roo='REXX-ROO'==!ver; call !env; return
!sys: !cms=!sys=='CMS'; !os2=!sys=='OS2'; !tso=!sys=='TSO' | !sys=='MVS'; !vse=!sys=='VSE'; !dos=pos('DOS',!sys)\==0 | pos('WIN',!sys)\==0 | !sys=='CMD'; !crx=left(!sys,6)=='DOSCRX'; call !rex; return
!var: call !fid; if !kexx then return space(dosenv(arg(1))); return space(value(arg(1),,!env))
er: parse arg _1,_2; call '$ERR' "14"p(_1) p(word(_1,2) !fid(1)) _2; if _1<0 then return _1; exit result
p: return word(arg(1),1)
return 0 /*return a zero value to invoker.*/
/*─────────────────────────────general 1─line subroutines───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
!all: !!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=="NT";!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,"? ?SAMPLES ?AUTHOR ?FLOW")==0 then return 0;!call=']$H';call "$H" !fn !;!call=;return 1
!cal: if symbol('!CALL')\=="VAR" then !call=; return !call
!env: !env='ENVIRONMENT'; if !sys=="MSDOS" | !brexx | !r4 | !roo then !env='SYSTEM'; if !os2 then !env="OS2"!env; !ebcdic=3=='f3'x; if !crx then !env="DOS"; return
!fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .; call !sys; if !dos then do; _=lastpos('\',!fn); !fm=left(!fn,_); !fn=substr(!fn,_+1); parse var !fn !fn "." !ft; end; return word(0 !fn !ft !fm, 1+('0'arg(1)))
!rex: parse upper version !ver !vernum !verdate .; !brexx='BY'==!vernum; !kexx="KEXX"==!ver; !pcrexx='REXX/PERSONAL'==!ver | "REXX/PC"==!ver; !r4='REXX-R4'==!ver; !regina="REXX-REGINA"==left(!ver,11); !roo='REXX-ROO'==!ver; call !env; return
!sys: !cms=!sys=='CMS'; !os2=!sys=="OS2"; !tso=!sys=='TSO' | !sys=="MVS"; !vse=!sys=='VSE'; !dos=pos("DOS",!sys)\==0 | pos('WIN',!sys)\==0 | !sys=="CMD"; !crx=left(!sys,6)=='DOSCRX'; call !rex; return
!var: call !fid; if !kexx then return space(dosenv(arg(1))); return space(value(arg(1), , !env))
er: parse arg _1,_2; call '$ERR' "14"p(_1) p(word(_1,2) !fid(1)) _2; if _1<0 then return _1; exit result
p: return word(arg(1), 1)
halt: call er .1
isNum: return datatype(arg(1),'N')
noValue: !sigl=sigl; call er 17,!fid(2) !fid(3) !sigl condition('D') sourceline(!sigl)
syntax: !sigl=sigl; call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)
isNum: return datatype(arg(1), 'N')
noValue: !sigl=sigl; call er 17, !fid(2) !fid(3) !sigl condition('D') sourceline(!sigl)
syntax: !sigl=sigl; call er 13, !fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)

6
Task/Sleep/TXR/sleep.txr Normal file
View file

@ -0,0 +1,6 @@
(let ((usec (progn (put-string "enter sleep usecs: ")
(tointz (get-line)))))
(put-string "Sleeping ... ")
(flush-stream)
(usleep usec)
(put-line "Awake!"))