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
// Copyright (c) 2019 Timo Savola. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

use std::any::Any;
use std::rc::Rc;

/// Obj can be any object.
pub type Obj = Rc<dyn Any>;

/// Pair may be a node in a singly linked list.
pub struct Pair(pub Obj, pub Obj);

/// () object.
pub fn nil() -> Obj {
    Rc::new(())
}

/// bool object.
pub fn boolean(b: bool) -> Obj {
    Rc::new(b)
}

/// i64 object.
pub fn int(n: i64) -> Obj {
    Rc::new(n)
}

/// String object.
pub fn string(s: String) -> Obj {
    Rc::new(s)
}

/// Construct a Pair object.
pub fn pair(car: Obj, cdr: Obj) -> Obj {
    Rc::new(Pair(car, cdr))
}