-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtype.html
129 lines (129 loc) · 3.88 KB
/
type.html
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
<html dir="ltr">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Arc: Type handling</title>
<link rel="shortcut icon" href="/assets/favicon.png">
<link rel="stylesheet" type="text/css" href="code.css">
<link href="/assets/bootstrap.css" rel="stylesheet">
</head>
<body style='margin:12px 50px 0'>
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<ul class="nav navbar-nav">
<li><a href="/ref/">Arc 3.1</a>
<li><a href="http://tryarc.org">Try it</a></li>
<li><a href="http://github.com/arclanguage/anarki">Get it</a></li>
<li><a href="http://ycombinator.com/arc/tut.txt">Tutorial</a></li>
<li><a href="http://arclanguage.org/forum">Forum</a></li>
</ul>
</div>
</div> <!-- end of navbar -->
<div class="links">Previous: <a href="table.html">Table operations</a>
Up: <a href="index.html">Contents</a>
Next: <a href="variables.html">Variable operations</a>
</div>
<h1 class="links">Type handling</h1>
Arc has functions to convert types and to determine the type of an object.
<h2>Type handling</h2>
<p><table class='arc'>
<tr>
<td class='arc'><a name='annotate'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>annotate</span> <span class='args'>type obj</span>
<div class='desc'>Tags the object with the given type.</div>
</td>
<td class='arc'><pre>
>(type (annotate 'mac car))
<span class="return">mac
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='rep'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>rep</span> <span class='args'>obj</span>
<div class='desc'>Returns the underlying object for an annotated object</div>
</td>
<td class='arc'><pre>
>(rep whilet)
<span class="return">#<procedure: whilet>
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='sym'></a>
<img src='proc.gif' title='Procedure'/>
<span class='op'>sym</span> <span class='args'>x</span>
<div class='desc'>Coerces x to a 'sym.</div>
</td>
<td class='arc'><pre>
>(sym "a")
<span class="return">a
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='coerce'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>coerce</span> <span class='args'>obj type [args]</span>
<div class='desc'>Coerces object to a new type. A char can be
coerced to int, string, or sym. A number can be coerced to int, char, or string
(of specified base). A string can be coerced to sym, cons (char list), or int (of
specified base). A list of characters can be coerced to a string. A symbol
can be coerced to a string.</div>
</td>
<td class='arc'><pre>
>(coerce "a" 'sym)
<span class="return">a
</span></pre>
<pre>
>(coerce 65 'char)
<span class="return">#\A
</span></pre>
<pre>
>(coerce 65 'int 2)
<span class="return">65
</span></pre>
<pre>
>(coerce "abc" 'cons)
<span class="return">(#\a #\b #\c)
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='int'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>int</span> <span class='args'>x [base]</span>
<div class='desc'>Coerces x to an integer. New in arc3.</div>
</td>
<td class='arc'><pre>
>(int "3.14")
<span class="return">3
</span></pre>
<pre>
>(int "1111" 2)
<span class="return">15
</span></pre>
<pre>
>(int #\a)
<span class="return">97
</span></pre>
</td></tr>
<tr>
<td class='arc'><a name='type'></a>
<img src='foundation.gif' title='Foundation'/>
<span class='op'>type</span> <span class='args'>object</span>
<div class='desc'>Returns the type of an object (as a symbol).
Possibilities are cons, sym, fn, char, string, int, num, table, output,
input, socket, exception, or mac.</div>
</td>
<td class='arc'><pre>
>(type 1)
<span class="return">int
</span></pre>
<pre>
>(type car)
<span class="return">fn
</span></pre>
</td></tr>
</table>
<p>
Copyright 2008 Ken Shirriff.
</body>
</html>