-
Notifications
You must be signed in to change notification settings - Fork 1
/
Singkong.txt
5685 lines (5022 loc) · 193 KB
/
Singkong.txt
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Singkong Programming Language Interpreter
(c) Noprianto <nop@noprianto.com>, 2019-2024
Website: nopri.github.io
License: Free to use or redistribute, no warranty
Version: 10.4 (2024-November-24 +07:00)
Singkong is based on Monkey.java: an open source, simple implementation of
Monkey programming language interpreter in Java.
Monkey.java is based on monkey.py: an open source, simple implementation of
Monkey programming language interpreter in Python.
Monkey.java and monkey.py, (c) Noprianto <nop@noprianto.com>, 2019.
monkey.py is based on code (in Go) in book: Writing an interpreter in Go
Singkong is developed on Java 8 with -source 1.5 -target 1.5, using only
Java 5.0-compatible application programming interface.
Thank you for using Singkong Programming Language.
-----------------------------------------------------------------------------
Bundled JDBC Drivers (compatible with Java 5.0 or later):
Apache Derby (Apache License 2.0): Network Server, Driver (Embedded, Client)
PostgreSQL (BSD-2-Clause License)
=============================================================================
1. What is Singkong Programming Language
2. System requirements
3. Getting started
4. Identifier, keywords, data types, and operators
5. Built-in functions and modules
6. If condition
7. Repeat loop
8. GUI application development
9. Database application development
10. Web application development
11. Simple HTTP client
12. Working with threads
13. Calling Java method
14. Embedding Singkong into another applications
15. Deployment
16. Differences with Monkey Programming Language
17. Example: GUI: components
18. Example: GUI: layout
19. Example: GUI: Singkong information
20. Example: GUI: event handlers
21. Example: GUI: printing
22. Example: GUI: simple text file editor
23. Example: GUI: timer
24. Example: Database: create table, insert, update, select, GUI
25. Example: Web: variables, GET, POST, JSON
26. Example: Java: custom dialog
27. Example: Monkey programming language interpreter in Singkong
28. Example: Working with Comma-Separated Values file
29. Example: Drawing: simple painting program
30. Changelog
-----------------------------------------------------------------------------
1. What is Singkong Programming Language
Singkong is case-insensitive, dynamically typed, procedural, and interpreted
programming language that runs on Java Virtual Machine (Java 5.0 or later).
It has numbers, booleans, strings, arrays, hash maps, dates, first-class
functions, built-in functions, GUI components, database connections, and
other features. Singkong program can call Java methods and Singkong interpreter
can be embedded and integrated into another applications.
Singkong interpreter is distributed as single jar file. It comes with simple GUI
editor/interactive evaluator/database tool and can be run on graphical or
text user interfaces.
Singkong is based on Monkey.java and inspired by Monkey Programming Language.
-----------------------------------------------------------------------------
2. System requirements
Java Runtime Environment version 5.0 or later.
If only text-based environment is available, Singkong interactive evaluator
will fallback to text only version and built-in functions will adapt
appropriately.
-----------------------------------------------------------------------------
3. Getting started
Please download Singkong.jar from its website. The jar file can be saved into
any directory - no system wide installation is required. Using portable Java
installation, Singkong can be run from external/portable storage device.
If GUI is available, Singkong.jar features interactive evaluator, variable
inspector, simple text editor, database tool, and documentation viewer.
To run Singkong in text mode when GUI is available, please set property
SINGKONG=0 (-DSINGKONG=0). This setting has no effect when GUI is not
available.
To disable some (or all) built-in functions, please set property DISABLE
(-DDISABLE) to comma-separated list of functions. If the first item in the list
is -, then only built-in functions in the list are enabled. To disable all
built-in functions, please set -DDISABLE=-.
- Standalone
- No command line argument: interactive
java -jar Singkong.jar
Singkong 10.4
Press ENTER to quit
> var hello = "Hello World"
> hello
"Hello World"
>
- No command line argument: interactive (GUI available)
java -jar Singkong.jar
(double-clicking Singkong.jar may also work)
- No command line argument: interactive (run in text mode, GUI available)
java -DSINGKONG=0 -jar Singkong.jar
- No command line argument: interactive (disable built-in: system)
java -DDISABLE=system -jar Singkong.jar
- No command line argument: interactive (disable built-in: system and info)
java -DDISABLE=system,info -jar Singkong.jar
- No command line argument: interactive (enable only built-in: len and print)
java -DDISABLE=-,len,print -jar Singkong.jar
- Command line argument: try to interpret as file
java -jar Singkong.jar test.singkong
If exception occurred: interpret the argument as Singkong code
java -jar Singkong.jar "println(1,2,3)"
1
2
3
- Run directly the main class (and setting the class path):
java -cp Singkong.jar com.noprianto.singkong.Singkong
java -cp Singkong.jar com.noprianto.singkong.Singkong test.singkong
java -cp Singkong.jar com.noprianto.singkong.Singkong "println(1,2,3)"
java -DSINGKONG=0 -cp Singkong.jar com.noprianto.singkong.Singkong "println(1,2,3)"
- Library
Please read: Embedding Singkong into another applications
Note: please use built-in function: interactive, to get information whether
Singkong program is run in Singkong interactive evaluator/editor.
Singkong or runtime version requirement: please use built-in function require
or require_runtime.
-----------------------------------------------------------------------------
4. Identifier, keywords, data types, and operators
Identifier starts with letter or underscore and optionally followed by letters,
numbers, or underscores. Built-in function names and keywords cannot be used as
identifier.
Assignment is done using var statement:
var name = "singkong"
var f = fn(name) { println(name) }
Note:
- Statement optionally ends with ;
- Block statement starts with { and ends with }
- Comment starts with # and ends with ;
- Multi-line comment is supported
Comment:
#
this
is
a
multi-line
comment
;
println("Singkong")
# this is another comment;
println("Programming")
# this is also a comment
;
println("Language")
Keywords:
#
ELSE
FALSE
FN
IF
LET
NULL
REPEAT
RETURN
TRUE
VAR
Note: to get list of keywords, please use built-in function keywords.
Data types:
Related functions: builtins, eval, ifnull, is, is_array_and_of, is_array_of,
is_array_of_component_of, hash, print, println, puts, string, type, types, variables
- NULL
- null
- null literal
- null may also returned from built-in functions
- null is not printed. To print null, please use
print, println, puts, or message.
- related functions: ifnull
- NUMBER
- any integer and decimal
- precision: 10240, default scale: 4
- to change the number scale, please use built-in function number_scale
- operators: + - * / == != %(remainder) ^(power) < <= > >=
- related functions: abs, array_number, chr, integer, integer_gcd, number, number_boolean,
number_group, number_to_byte, random, round, sort_number, words_en, words_id
- system related functions: delay
- Singkong related functions: require, require_runtime
- thread related functions: thread, thread_alive, thread_join
- trigonometric functions (degrees): sin, cos, tan, asin, acos, atan
- degrees radians conversion functions: to_degrees, to_radians
- hyperbolic functions: sinh, cosh, tanh
- natural exponential, logarithm, square/cube root functions: exp, log, log10, sqrt, cbrt
- base conversion: from_bin, from_hex, from_oct, to_bin, to_hex, to_oct
- bitwise operation: number_xor, number_or, number_and, number_not
- bit shift operation: left_shift, right_shift, unsigned_right_shift
- sorting: by value
- constant values: _e, _pi
> number_scale(15)
true
> _e()
2.718281828459045
> _pi()
3.141592653589793
- number scale setting example:
> _pi()
3.1416
> number_scale(8)
true
> _pi()
3.14159265
> number_scale(16)
true
> _pi()
3.1415926535897930
- From STRING to NUMBER: number:
> number("1.23")
1.2300
> number("a")
0
> number("a", -1)
-1
> number("a", 0, false)
0
> type(number("a", 0, true))
"NULL"
- mean, median, mode, range (using util module):
> load_module("util")
> var a = [0, 1, 2, 3, 4, 3, 2, 1, 0, 0]
> mean(a)
1.6000
> median(a)
1.5000
> mode(a)
[0, 3]
> range_(a)
4
- number grouping: built-in function: number_group
using util module:
number_group_c_p
number_group_p_c
number_group_s_c
number_group_s_p
- more functions in util module:
binomial_coefficient
binomial_distribution
factorial
geometric_distribution_failure
geometric_distribution_success
poisson_distribution
- BOOLEAN
- true or false
- operators: == != & | !
- related functions: number_boolean, boolean_xor, sort_boolean
- sorting: by value
- STRING
- double-quoted
- arbitrary length string
- operators: +(concatenation) -(remove) ==(equals,case-sensitive) != *(repeat)
- equals (case-insensitive): please use built-in function equals
- Using ==(equals,case-sensitive) operator:
> "Singkong" == "singkong"
false
> "Singkong" == "Singkong"
true
- index operator
- modify STRING: please use built-in function set
- related functions: array_string, base64_decode, base64_encode, call, center,
count, cr, crlf, dir, empty, endswith, equals, eval, in, index, isalnum, isalpha,
isdigit, islower, isupper, join, left, len,
lf, lower, matches, md5, md5_file, newline, ord, parse_string, quote, random_string, replace, right,
set, sha1, sha1_file, sha256, sha256_file, sha384, sha384_file, sha512, sha512_file,
slice, sort_string, split, startswith,
stat, tab, trim, upper, uuid
- special characters: cr, crlf, lf, newline, quote, tab
- file related functions: abs, append, copy, copy_resource, delete, mkdir, read,
rename, temp_file, write
- HTTP client related functions: http_delete, http_get, http_get_file,
http_head, http_post, http_post_override, http_put, url_decode, url_encode
- system related functions: cwd, inet_address_local, separator, user, userhome
- Singkong related functions: load, load_file_or_resource, load_module, load_resource
- extended: x_base64_decode_file, x_base64_encode_file
- sorting: lexicographically
- UUID: please use built-in function uuid
- If no argument is passed, generates a pseudo randomly generated UUID
- If optional name is passed, generates named based UUID
- simple string or file encryption/decryption:
please use functions from util module:
- string:
load_module("util")
var a = "Hello World"
var b = "Singkong"
var c = simple_string_encrypt(a, b)
var d = simple_string_decrypt(c, b)
println(a, b, a == d)
- file:
load_module("util")
var a = "input.txt"
var b = "Singkong"
var c = "input.data"
var d = "output.txt"
write(a, "Hello World")
var e = simple_file_encrypt(a, b, c)
var f = simple_file_decrypt(c, b, d)
println(e, f, md5_file(a) == md5_file(d))
- string replacement: replace (built-in), replace_array (util), or replace_hash (util)
> replace("$name", "$name", "Singkong")
"Singkong"
> load_module("util")
> replace_array("$name $type", [["$name", "Singkong"], ["$type", "programming language"]])
"Singkong programming language"
> replace_hash("$name $type", {"$name": "Singkong", "$type": "programming language"})
"Singkong programming language"
- ARRAY
- []
- array of mixed data types
- operators: +(add), -(remove) == !=
- add and extend:
> [1,2] + 3
[1, 2, 3]
> [1,2] + [3]
[1, 2, [3]]
> array_extend([1,2], [3])
[1, 2, 3]
> array_extend_all([[1,2], [3,4], 5])
[1, 2, 3, 4, 5]
- Using == operator:
> [] == []
true
> [1,2] == [1,2]
true
> [1,2] == [2,1]
false
> [[1,2]] == [[2,1]]
false
> [1,2] == [1,2,3]
false
- equals (the same elements, not necessarily in the same order):
please use built-in function array_equals
> [1,2] == [2,1]
false
> array_equals([1,2], [2,1])
true
> array_equals([1,2], [1,2])
true
- index operator
- modify ARRAY: please use built-in function set
- related functions: array, array_equals, array_extend, array_extend_all, array_number,
array_string, average, call, count, each, empty, first, in, index, join,
last, len, max, min, parse_array, pop, push, random, range, rest, reverse, shuffle, slice,
sort_array, sort_boolean, sort_date, sort_hash, sort_number, sort_string, sum
- array check functions: is_array_and_of, is_array_of, is_array_of_component_of
- file related functions: dir, read_byte, write_byte
- CGI related functions: cgi_contents
- HTTP client related functions: http_response_ok
- system related functions: arguments, inet_address, runtime_version, system
- Singkong related functions: builtins, modules, singkong_interpreter
- byte array: number_to_byte_array, string_from_byte_array, string_to_byte_array
> number_to_byte_array(123)
[123]
> number_to_byte_array(1234)
[4, -46]
> string_to_byte_array("Singkong")
[83, 105, 110, 103, 107, 111, 110, 103]
> string_from_byte_array([83, 105, 110, 103, 107, 111, 110, 103])
"Singkong"
- sorting: by length
- rectangular array: array whose each element is an array, and all elements have the same length
- rectangular array functions: is_rect_array, is_rect_array_of, rect_array_size,
rect_array_size_of
- sort rectangular array of number based on index:
please use function from util module: sort_rect_array_of_number_by_index
- rectangular array example:
> var a = []
> var b = [[], []]
> var c = [[1, 2, 3], ["Singkong", "Programming", "Language"]]
> var d = [[1, 2, 3], [4, 5, 6]]
> is_rect_array(a)
false
> is_rect_array(b)
true
> is_rect_array(c)
true
> is_rect_array_of(c, "NUMBER")
false
> is_rect_array_of(d, "NUMBER")
true
> rect_array_size(c)
[2, 3]
> rect_array_size_of(c, "NUMBER")
> rect_array_size_of(c, "NUMBER") == null
true
> rect_array_size_of(d, "NUMBER")
[2, 3]
> load_module("util")
> sort_rect_array_of_number_by_index([[1,3], [3,2], [2,1]], 1)
[[2, 1], [3, 2], [1, 3]]
> sort_rect_array_of_number_by_index([[1,3], [3,2], [2,1]], 0)
[[1, 3], [2, 1], [3, 2]]
- rectangular array and matrix: please use functions from rect_array_util module:
add_rect_array_of
add_rect_array_of_number
cross_product_3d_rect_array_column_of
cross_product_3d_rect_array_column_of_number
cross_product_3d_rect_array_row_of
cross_product_3d_rect_array_row_of_number
determinant_rect_array_of
determinant_rect_array_of_number
inverse_rect_array_of
inverse_rect_array_of_number
is_constant_rect_array_of
is_constant_rect_array_of_number
is_diagonal_rect_array_of
is_diagonal_rect_array_of_number
is_identity_rect_array_of_number
is_lower_triangular_rect_array_of
is_lower_triangular_rect_array_of_number
is_rect_array_column_of
is_rect_array_column_of_number
is_rect_array_row_of
is_rect_array_row_of_number
is_square_rect_array_of
is_square_rect_array_of_number
is_symmetric_rect_array_of
is_symmetric_rect_array_of_number
is_upper_triangular_rect_array_of
is_upper_triangular_rect_array_of_number
is_zero_rect_array_of
is_zero_rect_array_of_number
minor_rect_array_of
minor_rect_array_of_number
mul_rect_array_of
mul_rect_array_of_number
mul_scalar_rect_array_of
mul_scalar_rect_array_of_number
rect_array_not_row_col
sub_rect_array_of
sub_rect_array_of_number
trace_rect_array_of
trace_rect_array_of_number
transpose_rect_array_of
transpose_rect_array_of_number
- copy:
var a = ["hello", "world"]
var b = []
each(a, fn(e,i) {
var b = b + e
})
set(a, 1, "hello world")
println(a, b)
- copy (using array_copy function from util module):
load_module("util")
var a = ["hello", "world"]
var b = array_copy(a)
set(a, 1, "hello world")
println(a, b)
- diff (using array_diff function from util module):
> array_diff([1,2,3,4,5], [1,3,5])
[2, 4]
- From STRING to ARRAY: parse_array
using default mode (eval expression):
> parse_array("[1+2]", true)
[3]
> parse_array("[1+2]", true, 0)
[3]
> parse_array("[1+2, fn(){true}()]", true)
[3, true]
alternative 1: parse only ARRAY, BOOLEAN, HASH (uses strings for keys),
NULL, NUMBER, STRING, other types: STRING representation
(pass 1 as third argument):
> parse_array("[1+2]", true, 1)
["(1 + 2)"]
> parse_array("[1+2, fn(){true}()]", true, 1)
["(1 + 2)", "fn()
{
true;
}
()"]
alternative 2: parse only ARRAY, BOOLEAN, HASH (keys must be strings),
NULL, NUMBER, STRING, other types: returns NULL (or empty ARRAY)
(pass 2 as third argument):
> type(parse_array("[1+2]", true, 2))
"NULL"
> parse_array("[1+2]", false, 2)
[]
> parse_array("[1, 2]", true, 2)
[1, 2]
- set related functions: please use functions from set_util module:
create_relation_from_array
create_set_from_array
get_relation_part
inverse_bijective_function_set
is_antisymmetric_relation_set
is_bijective_function_set
is_function_set
is_injective_function_set
is_reflexive_relation_set
is_relation
is_relation_set
is_same_set
is_sub_set
is_surjective_function_set
is_symmetric_relation_set
is_transitive_relation_set
set_diff
set_intersection
set_power
set_product
set_union
- more functions in util module:
standard_deviation
standard_deviation_
standard_deviation_sample
variance
variance_
variance_sample
- HASH
- {}
- hash table/dictionary
- any data type can be used as key
- hash maintains insertion-order
- operators: +(add dictionary), -(remove) == !=
- Using == operator:
> {} == {}
true
> {1:2} == {1:2}
true
> {1:2} == {2:1}
false
> {1.0:2} == {1:2}
true
> {1:2, 3:4} == {3:4, 1:2}
true
> {1:1+1, 3:2+2} == {3:4.0, 1.0:2.0}
true
> {1:2, 3:4} == {1.0001:2, 3:4}
false
- modify HASH: please use built-in function set
- using string function: if optional second argument (BOOLEAN) is true (default: false),
use strings for keys.
- related functions: empty, keys, len, parse_hash, random, sort_hash, values
- file related functions: properties_read, properties_write, stat
- CGI related functions: cgi_header, cgi_get, cgi_post, cgi_post_hash
- system related functions: env, info
- Singkong related functions: singkong
- sorting: by length
- copy:
var a = {"hello": "world"}
var b = {} + a
set(a, "hello", "hello world")
println(a, b)
- copy (using hash_copy function from util module):
load_module("util")
var a = {"hello": "world"}
var b = hash_copy(a)
set(a, "hello", "hello world")
println(a, b)
- From STRING to HASH: parse_hash
using default mode (eval expression):
> parse_hash("{1: 2+3}", true)
{1: 5}
> parse_hash("{1: 2+3}", true, 0)
{1: 5}
> parse_hash("{1: 2+3, true: fn(){true}()}", true)
{1: 5, true: true}
alternative 1: uses strings for keys,
parse only ARRAY, BOOLEAN, HASH, NULL, NUMBER, STRING,
other types: STRING representation
(pass 1 as third argument):
> parse_hash("{1: 2+3}", true, 1)
{"1": "(2 + 3)"}
> parse_hash("{1: 2+3, true: fn(){true}()}", true, 1)
{"1": "(2 + 3)", "true": "fn()
{
true;
}
()"}
> parse_hash("{1: 2}", true, 1)
{"1": 2}
> parse_hash("{true: true}", true, 1)
{"true": true}
> parse_hash(string({"1": 2}, true), true, 1)
{"1": 2}
> parse_hash(string({1: 2}), true, 1)
{"1": 2}
alternative 2: parse only ARRAY, BOOLEAN, HASH (keys must be strings),
NULL, NUMBER, STRING,
other types: NULL (or empty HASH)
(pass 2 as third argument):
> type(parse_hash("{1: 2+3}", true, 2))
"NULL"
> parse_hash("{1: 2+3}", false, 2)
{}
> type(parse_hash("{1: 2}", true, 2))
"NULL"
> type(parse_hash("{true: true}", true, 2))
"NULL"
> parse_hash(string({"1": 2}, true), true, 2)
{"1": 2}
> type(parse_hash(string({1: 2}), true, 2))
"NULL"
- DATE
- @ @Y @YY @YYY @YYYY @YYYYM @YYYYMM @YYYYMMD @YYYYMMDD @YYYYMMDDh
@YYYYMMDDhh @YYYYMMDDhhm @YYYYMMDDhhmm @YYYYMMDDhhmms @YYYYMMDDhhmmss
- related functions: date, datetime, day, days_of_month, diff, format_date,
format_datetime, format_diff, format_time, hour, is_leap_year, minute,
month, part, second, sort_date, year
- file related functions: stat
- From DATE to NUMBER: number:
> number(@2023)
1672506000180
- From STRING to DATE: date or datetime:
> date("2023-10-30")
2023-10-30 00:00:00
> datetime("2023-10-30")
2023-10-30 09:14:11
> date("")
2023-10-30 09:14:38
> date("", @2023)
2023-01-01 00:00:00
> date("", @2023, false)
2023-01-01 00:00:00
> type(date("", @2023, true))
"NULL"
- From ARRAY to DATE: date or datetime:
> date([2023, 10, 30])
2023-10-30 00:00:00
> date([2023, 10, 30, 9, 15, 20])
2023-10-30 00:00:00
> datetime([2023, 10, 30, 9, 15, 20])
2023-10-30 09:15:20
> date([])
2023-10-30 09:18:27
> date([], @2023)
2023-01-01 00:00:00
> date([], @2023, false)
2023-01-01 00:00:00
> type(date([], @2023, true))
"NULL"
- sorting: before/after
- FUNCTION
- fn()
- fn(arg)
- fn(arg, arg,...)
- function definition: var statement
- function call: function name followed by (, optional comma-separated
arguments, and )
- documentation string:
without documentation string:
> var f = fn(x) {x}
> f
fn(x)
{
x;
}
> help(f)
""
with documentation string:
> var f = fn(x) "test" {x}
> f
[documentation string] test
> help(f)
"[documentation string] test"
- related functions: do, each, help, param
- Singkong related functions: load, load_file_or_resource, load_module, load_resource
- thread related functions: thread
- nested function is supported:
code:
var a = fn() {
println("a")
var b = fn() {
println("b")
var c = fn() {
println("c")
var d = fn() {
println("d")
}
d()
}
c()
}
b()
}
a()
output:
a
b
c
d
- variable scope in nested function:
code:
var x = "Hello"
println("X: " + x)
var a = fn() {
println("Function A (X): " + x)
var b = fn() {
println("Function B in A (X): " + x)
var c = fn() {
# x defined in c;
var x = "World"
println("Function C in B (local variable X): " + x)
var d = fn() {
println("Function D in C (using variable X in C): " + x)
}
d()
}
c()
# original x;
println("B (original X): " + x)
}
b()
# not found;
println(y)
}
a()
output:
X: Hello
Function A (X): Hello
Function B in A (X): Hello
Function C in B (local variable X): World
Function D in C (using variable X in C): World
B (original X): Hello
ERROR: [line: 22] identifier not found: y
ERROR: [line: 22] identifier not found: y
- BUILTIN
- built-in function
- related functions: builtins, disabled, help, param
- extended: built-in functions that require minimum Java version > 5.0.
function name prefix: x_
these functions are always available
if the requirement is not met: returns NULL
- COMPONENT
- Please read: GUI application development
- related functions: add, add_e, add_n, add_s, add_w, button_image, clear, closing,
component, component_info, component_type, components, config,
custom_dialog_close, event, event_focus,
event_frame, event_keyboard_frame, event_mouse, event_mouse_frame, fonts, frame,
frame_close, frame_image, frame_location, frame_top, get, grid_add, grid_clear,
grid_remove, gui, hide, menubar, panel_add, panel_clear, panel_remove,
popup_component, popup_hide, popup_show, printer, radio_group,
remove, remove_e, remove_n, remove_s, remove_w, reset, resizable,
screen, show, size, start, start_timer, statusbar, stop, stop_timer,
tab_add, tab_clear, tab_remove, table_add,
table_bottom, table_center, table_column, table_column_count, table_column_info,
table_column_name, table_get_value, table_left, table_middle, table_print,
table_remove, table_right, table_row_count, table_scroll, table_set_color,
table_set_renderer, table_set_row_height, table_set_value, table_top, timer,
timer_running, title, wait
- GUI input/output functions: confirm, directory, input, open, message,
password, save
(if GUI is not available: simpler text-based version)
- GUI dialogs: color_chooser, custom_dialog, login_dialog, panel_dialog
- Drawing: draw_width, draw_rect, fill_rect, draw_arc, fill_arc, draw_oval,
fill_oval, draw_round_rect, fill_round_rect, draw_string, draw_line,
draw_polygon, fill_polygon, draw_polyline, draw_read, draw_write_png,
draw_write_jpg, draw_write_bmp, draw_get_pixel, draw_set_pixel
- Clipboard: clipboard_get, clipboard_set
- Sound: beep, play_sound
- array of component check: is_array_of_component_of
- extended: x_edit_print
- user interface related functions: please use functions from ui_util module:
table_add_fill
table_add_row_fill
table_fill
table_get_array_
table_get_array_number
table_get_array_string
table_to_html
table_to_text
- user interface, calendar related functions: please use functions from ui_calendar module:
create_calendar
create_calendar_basic
create_calendar_basic_compact
create_calendar_simple
create_calendar_simple_compact
- DATABASE
- Please read: Database application development
- related functions: database, database_connected, database_metadata, query
- To work with relational database without using SQL command directly:
built-in module db_util:
create_field_from_array
db_connect
db_connect_embed
db_connect_embed_
db_connect_embed_user
db_create_table
db_create_table_
db_create_table_derby
db_create_table_derby_
db_create_table_embed
db_create_table_embed_
db_create_table_postgresql
db_create_table_postgresql_
db_delete
db_delete_
db_driver
db_insert
db_insert_
db_last
db_last_derby
db_last_embed
db_last_postgresql
db_query_simple
db_query_single
db_run_query
db_select
db_select_
db_select_all
db_select_all_
db_select_derby
db_select_derby_
db_select_embed
db_select_embed_
db_select_postgresql
db_select_postgresql_
db_update
db_update_
query_result
-----------------------------------------------------------------------------
5. Built-in functions and modules
To get a list of built-in functions, please call builtins()
["_E", "_PI", "ABS", "ACOS", "ADD", "ADD_E", "ADD_N", "ADD_S", "ADD_W",
"APPEND", "ARGUMENTS", "ARRAY", "ARRAY_EQUALS", "ARRAY_EXTEND",
"ARRAY_EXTEND_ALL", "ARRAY_NUMBER", "ARRAY_STRING", "ASIN", "ATAN", "AVERAGE",
"BASE64_DECODE", "BASE64_ENCODE", "BEEP", "BOOLEAN_XOR", "BUILTINS",
"BUTTON_IMAGE", "CALL", "CALL_INFO", "CBRT", "CENTER", "CGI_CONTENTS",
"CGI_GET", "CGI_HEADER", "CGI_POST", "CGI_POST_HASH", "CHR", "CLEAR",
"CLIPBOARD_GET", "CLIPBOARD_SET", "CLOSING", "COLOR_CHOOSER", "COMPONENT",
"COMPONENT_INFO", "COMPONENT_TYPE", "COMPONENTS", "CONFIG", "CONFIRM", "COPY",
"COPY_RESOURCE", "COS", "COSH", "COUNT", "CR", "CRLF", "CUSTOM_DIALOG",
"CUSTOM_DIALOG_CLOSE", "CWD", "DATABASE", "DATABASE_CONNECTED",
"DATABASE_METADATA", "DATE", "DATETIME", "DAY", "DAYS_OF_MONTH", "DELAY",
"DELETE", "DIFF", "DIR", "DIRECTORY", "DISABLED", "DO", "DRAW_ARC",
"DRAW_GET_PIXEL", "DRAW_LINE", "DRAW_OVAL", "DRAW_POLYGON", "DRAW_POLYLINE",
"DRAW_READ", "DRAW_RECT", "DRAW_ROUND_RECT", "DRAW_SET_PIXEL", "DRAW_STRING",
"DRAW_WIDTH", "DRAW_WRITE_BMP", "DRAW_WRITE_JPG", "DRAW_WRITE_PNG", "EACH",
"EMPTY", "ENDSWITH", "ENV", "EQUALS", "EVAL", "EVENT", "EVENT_FOCUS",
"EVENT_FRAME", "EVENT_KEYBOARD_FRAME", "EVENT_MOUSE", "EVENT_MOUSE_FRAME",
"EXIT", "EXP", "FILL_ARC", "FILL_OVAL", "FILL_POLYGON", "FILL_RECT",
"FILL_ROUND_RECT", "FIRST", "FONTS", "FORMAT_DATE", "FORMAT_DATETIME",
"FORMAT_DIFF", "FORMAT_TIME", "FRAME", "FRAME_CLOSE", "FRAME_IMAGE",
"FRAME_LOCATION", "FRAME_TOP", "FROM_BIN", "FROM_HEX", "FROM_OCT", "GET",
"GRID_ADD", "GRID_CLEAR", "GRID_REMOVE", "GUI", "HASH", "HELP", "HIDE", "HOUR",
"HTTP_DELETE", "HTTP_GET", "HTTP_GET_FILE", "HTTP_HEAD", "HTTP_POST",
"HTTP_POST_OVERRIDE", "HTTP_PUT", "HTTP_RESPONSE_OK", "IFNULL", "IN", "INDEX",
"INET_ADDRESS", "INET_ADDRESS_LOCAL", "INFO", "INPUT", "INTEGER", "INTEGER_GCD",
"INTERACTIVE", "IS", "IS_ARRAY_AND_OF", "IS_ARRAY_OF",
"IS_ARRAY_OF_COMPONENT_OF", "IS_LEAP_YEAR", "IS_RECT_ARRAY", "IS_RECT_ARRAY_OF",
"IS_UPDATE_AVAILABLE", "ISALNUM", "ISALPHA", "ISDIGIT", "ISLOWER", "ISUPPER",
"JOIN", "KEYS", "KEYWORDS", "LAST", "LEFT", "LEFT_SHIFT", "LEN", "LF", "LOAD",
"LOAD_FILE_OR_RESOURCE", "LOAD_MODULE", "LOAD_RESOURCE", "LOG", "LOG10",
"LOGIN_DIALOG", "LOWER", "MAIN_RESOURCE", "MATCHES", "MAX", "MD5", "MD5_FILE",
"MENUBAR", "MESSAGE", "MIN", "MINUTE", "MKDIR", "MODULES", "MONTH", "NEWLINE",
"NUMBER", "NUMBER_AND", "NUMBER_BOOLEAN", "NUMBER_GROUP", "NUMBER_NOT",
"NUMBER_OR", "NUMBER_SCALE", "NUMBER_TO_BYTE", "NUMBER_TO_BYTE_ARRAY",
"NUMBER_XOR", "OPEN", "ORD", "PANEL_ADD", "PANEL_CLEAR", "PANEL_DIALOG",
"PANEL_REMOVE", "PARAM", "PARSE_ARRAY", "PARSE_HASH", "PARSE_STRING", "PART",
"PARTS", "PASSWORD", "PLAY_SOUND", "POP", "POPUP_COMPONENT", "POPUP_HIDE",
"POPUP_SHOW", "PRINT", "PRINTER", "PRINTLN", "PROPERTIES_READ",
"PROPERTIES_WRITE", "PUSH", "PUTS", "QUERY", "QUOTE", "RADIO_GROUP", "RANDOM",
"RANDOM_STRING", "RANGE", "READ", "READ_BYTE", "RECT_ARRAY_SIZE",
"RECT_ARRAY_SIZE_OF", "REMOVE", "REMOVE_E", "REMOVE_N", "REMOVE_S", "REMOVE_W",
"RENAME", "REPLACE", "REQUIRE", "REQUIRE_RUNTIME", "RESET", "RESIZABLE", "REST",
"REVERSE", "RIGHT", "RIGHT_SHIFT", "ROUND", "RUNTIME_VERSION", "SAVE", "SCREEN",
"SECOND", "SEPARATOR", "SET", "SHA1", "SHA1_FILE", "SHA256", "SHA256_FILE",
"SHA384", "SHA384_FILE", "SHA512", "SHA512_FILE", "SHOW", "SHUFFLE", "SIN",
"SINGKONG", "SINGKONG_INTERPRETER", "SINH", "SIZE", "SLICE", "SORT_ARRAY",
"SORT_BOOLEAN", "SORT_DATE", "SORT_HASH", "SORT_NUMBER", "SORT_STRING", "SPLIT",
"SQRT", "START", "START_TIMER", "STARTSWITH", "STAT", "STATUSBAR", "STDIN",
"STOP", "STOP_TIMER", "STRING", "STRING_FROM_BYTE_ARRAY", "STRING_TO_BYTE_ARRAY",
"SUM", "SYSTEM", "TAB", "TAB_ADD", "TAB_CLEAR", "TAB_REMOVE", "TABLE_ADD",
"TABLE_BOTTOM", "TABLE_CENTER", "TABLE_COLUMN", "TABLE_COLUMN_COUNT",
"TABLE_COLUMN_INFO", "TABLE_COLUMN_NAME", "TABLE_GET_VALUE", "TABLE_LEFT",
"TABLE_MIDDLE", "TABLE_PRINT", "TABLE_REMOVE", "TABLE_RIGHT", "TABLE_ROW_COUNT",
"TABLE_SCROLL", "TABLE_SET_COLOR", "TABLE_SET_RENDERER", "TABLE_SET_ROW_HEIGHT",
"TABLE_SET_VALUE", "TABLE_TOP", "TAN", "TANH", "TEMP_FILE", "THREAD",
"THREAD_ALIVE", "THREAD_JOIN", "TIMER", "TIMER_RUNNING", "TITLE", "TO_BIN",
"TO_DEGREES", "TO_HEX", "TO_OCT", "TO_RADIANS", "TRIM", "TYPE", "TYPES",
"UNSIGNED_RIGHT_SHIFT", "UPPER", "URL_DECODE", "URL_ENCODE", "USER", "USERHOME",
"UUID", "VALUES", "VARIABLES", "WAIT", "WORDS_EN", "WORDS_ID", "WRITE",
"WRITE_BYTE", "X_BASE64_DECODE_FILE", "X_BASE64_ENCODE_FILE", "X_EDIT_PRINT",
"YEAR"]
> len(builtins())
351
Note: a built-in function may be disabled when the interpreter is run. In such
case, an error will be returned when the function is called.
To get basic information of a built-in function, please enter its name in
interactive evaluator, without ( and ). For example:
> random
built-in function: random: returns random number (between 0 inclusive and 1
exclusive), random number between min and max (both inclusive), random element
in ARRAY, random key in HASH
arguments: 0, 1 (ARRAY or HASH), 2: (NUMBER and NUMBER)
return value: <any type>
To get a list of built-in modules, please call modules()
> modules()
["csv", "db_util", "json", "rect_array_util", "set_util", "ui_calendar", "ui_util", "util", "web"]
To load a built-in module, please use built-in function load_module,
for example:
> load_module("csv")
> load_module("db_util")
> load_module("json")
> load_module("rect_array_util")
> load_module("set_util")
> load_module("ui_calendar")
> load_module("ui_util")
> load_module("util")
> load_module("web")
Note: reusing function name from built-in modules as identifier is allowed:
> var len = "hello, world"
ERROR: [line: 1] len is a built-in function
> load_module("csv")
> csv_from_string
[documentation string] [csv] function: csv_from_string: returns ARRAY from CSV STRING (with separator).
arguments: 2: STRING (separator) and STRING (CSV)
return value: ARRAY or NULL (error)
> var csv_from_string = "hello, world"
> csv_from_string
"hello, world"
Functions in module: csv:
["CSV_FROM_STRING", "CSV_FROM_STRING_DEFAULT", "CSV_FUNCTIONS", "CSV_TO_STRING",
"CSV_TO_STRING_DEFAULT"]
Functions in module: db_util:
["CREATE_FIELD_FROM_ARRAY", "DB_CONNECT", "DB_CONNECT_EMBED",
"DB_CONNECT_EMBED_", "DB_CONNECT_EMBED_USER", "DB_CREATE_TABLE",
"DB_CREATE_TABLE_", "DB_CREATE_TABLE_DERBY", "DB_CREATE_TABLE_DERBY_",
"DB_CREATE_TABLE_EMBED", "DB_CREATE_TABLE_EMBED_", "DB_CREATE_TABLE_POSTGRESQL",
"DB_CREATE_TABLE_POSTGRESQL_", "DB_DELETE", "DB_DELETE_", "DB_DRIVER",
"DB_INSERT", "DB_INSERT_", "DB_LAST", "DB_LAST_DERBY", "DB_LAST_EMBED",
"DB_LAST_POSTGRESQL", "DB_QUERY_SIMPLE", "DB_QUERY_SINGLE", "DB_RUN_QUERY",
"DB_SELECT", "DB_SELECT_", "DB_SELECT_ALL", "DB_SELECT_ALL_", "DB_SELECT_DERBY",
"DB_SELECT_DERBY_", "DB_SELECT_EMBED", "DB_SELECT_EMBED_",
"DB_SELECT_POSTGRESQL", "DB_SELECT_POSTGRESQL_", "DB_UPDATE", "DB_UPDATE_",
"QUERY_RESULT"]
Functions in module: json:
["JSON_PARSE", "JSON_PARSE_", "JSON_STRING"]