-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
95 lines (92 loc) · 2.52 KB
/
test.pl
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
:- ['jurassic.pl'].
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Basics
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- := println("Hello World!").
:-
a := sqrt(2.0),
:= println(a).
:- jl_isdefined(a).
:- a := 1.
:- jl_isdefined(a).
:- := f(x) = x*transpose(x).
:- := @show(f([1,2,3,4,5])).
:- a := f([1,2,3,4,5]).
:- X = 2, := @show(a[1,X]).
:- X = 100, := @show(a[1,X]).
:- := cmd("fib(n) = n <= 1 ? 1 : fib(n-1) + fib(n-2)").
:- := @time(@show(fib(46))).
:-
:= cmd("function fib2(n)
n <= 1 && return 1
sum = 0
while n > 1
sum += fib2(n-1)
n -= 2
end
return sum + 1
end").
:- := @time(@show(fib2(46))).
:- jl_using("Pkg").
:- := 'Pkg'.status().
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*
:- := "struct point
x
y
end".
:- a := cmd("[point([1,2,3],[1,2,3]), point([2,3,4],[2,3,4])]").
:- := @show(a[2].x[1]).
*/
:- := @show(ccall(tuple([:clock, "libc.so.6"]), 'Int32', tuple([]))).
:- := cmd("function getenv(var::AbstractString)
val = ccall((:getenv, \"libc.so.6\"),
Cstring, (Cstring,), var)
if val == C_NULL
error(\"getenv: undefined variable: \", var)
end
unsafe_string(val)
end").
:- X := getenv("SHELL").
:- := f(x) = sqrt(x) + x^2 + log(x) + 1.0.
:- X := f(2.0).
:- between(1,10,X),
Y := f(X).
:- a := 1,
X := a,
b := X + 1,
Y := b,
Z := c.
:- a := array('Int64', undef, 2, 2).
:- X = a, := @show(X).
:- X = :a, := @show(X).
:- := f(x) = pi.*x.
:- X := f([1,2,3,4,5]).
:- := f(x) = x*transpose(x).
:- := @show(typeof(f([1,2,3]))),
X := f([1,2,3]).
:- X := 1/0.
:- X := -1/0.
:- a := tuple([1,"I'm string!", tuple([2.0, :'I\'m a quoted symbol'])]), := @show(a).
:- := cmd("f(x) = (x, x^2, x^3)").
:- A = a, tuple([A, B, C]) := f(-2).
:- := @show(a).
:- a := 1.
:- X := [a, :a].
:- X := tuple([1+1, :a]).
:- jl_using("Plots").
:- := gr().
:- plt := plot(rand(10), kw(title, "10 Random numbers"), kw(fmt, :png), kw(show, false)).
:- := savefig(plt, "rand10.png").
:- := foo(x,y,z) = sum([x,y,z]).
:- := foo([1,2,3]).
:- := foo([1,2,3]...).
:- X := map(x ->> pi*x, [1,2,3,4,5]).
:- a := array('Float64', undef, 2, 2, 2).
:- := @show(a[1,:,:]).
:- jl_new_array(a, 'Int', undef, [2, 2, 2]).
:- := @show(a[1,:,:]).
:- a := array(union('Int64', 'Missing'), missing, 2, 2).
:- a[1, :] := [1,2].
:- := @show(a).