-
Notifications
You must be signed in to change notification settings - Fork 0
/
inilib.joy
122 lines (102 loc) · 2.72 KB
/
inilib.joy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(* FILE: inilib.joy *)
LIBRA
_inilib == true;
(* - - - - - I N P U T O U T P U T - - - - *)
newline == '\n putch;
putln == put newline;
space == '\032 putch;
bell == '\007 putch;
(* this is now a primitive in raw Joy:
putchars == [putch] step;
*)
putstrings == [putchars] step;
ask == "Please " putchars putchars newline get;
(* - - - - - O P E R A T O R S - - - - - *)
dup2 == dupd dup swapd;
pop2 == pop pop;
newstack == [] unstack;
truth == true;
falsity == false;
to-upper == ['a >=] [32 -] [] ifte;
to-lower == ['a < ] [32 +] [] ifte;
boolean == [logical] [set] sequor;
numerical == [integer] [float] sequor;
swoncat == swap concat;
(* date and time *)
weekdays ==
[ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday"
"Saturday" "Sunday" ];
months ==
[ "JAN" "FEB" "MAR" "APR" "MAY" "JUN"
"JUL" "AUG" "SEP" "OCT" "NOV" "DEC" ];
localtime-strings ==
time localtime
[ [ 0 at 'd 4 4 format ]
[ 1 at pred months of ]
[ 2 at 'd 2 2 format ]
[ 3 at 'd 2 2 format ]
[ 4 at 'd 2 2 format ]
[ 5 at 'd 2 2 format ]
[ 6 at [] ["true"] ["false"] ifte ]
[ 7 at 'd 5 5 format ]
[ 8 at pred weekdays of ] ]
[i] map
popd;
today ==
localtime-strings
[ [8 at] [" "] [2 at] ["-"] [1 at] ["-"] [0 at rest rest] ]
[i] map
popd
"" [concat] fold;
now ==
localtime-strings
3 drop
[ [0 at] [":"] [1 at] [":"] [2 at] ]
[i] map
popd
"" [concat] fold;
show-todaynow ==
today putchars space now putchars newline;
(* program operators *)
conjoin == [[false] ifte] cons cons;
disjoin == [ifte] cons [true] swons cons;
negate == [[false] [true] ifte] cons;
(* - - - - - C O M B I N A T O R S - - - - - *)
sequor == [pop true] swap ifte;
sequand == [pop false] ifte;
dipd == [dip] cons dip;
dip2 == [dip] cons dip;
dip3 == [dip2] cons dip;
call == [] cons i;
i2 == [dip] dip i;
nullary2 == [nullary] cons dup i2 swapd;
(* this is now a primitive in raw Joy:
unary2 == [unary ] cons dup i2;
*)
repeat == dupd swap [i] dip2 while;
forever == maxint swap times;
(* library inclusion *)
verbose == false;
libload ==
[ '_ swons intern body null ]
[ ".joy" concat include ]
[ [ verbose ]
[ putchars " is already loaded\n" putchars ]
[ pop ]
ifte ]
ifte;
basic-libload ==
"agglib" libload
"seqlib" libload
"numlib" libload;
special-libload ==
"mtrlib" libload
"tutlib" libload
"lazlib" libload
"lsplib" libload
"symlib" libload;
all-libload == basic-libload special-libload;
INILIB == "inilib.joy - the initial library, assumed everywhere\n".
(* end LIBRA *)
"inilib is loaded\n" putchars.
(* END inilib.joy *)